From 53d9e6ecb9774258883a4248738dde482fb30304 Mon Sep 17 00:00:00 2001
From: Nico Alt <nicoalt@posteo.org>
Date: Sun, 7 Mar 2021 12:00:18 +0100
Subject: [PATCH] Add unit tests

---
 tests/briar_wrapper/models/test_contacts.py | 27 +++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/tests/briar_wrapper/models/test_contacts.py b/tests/briar_wrapper/models/test_contacts.py
index 2017565..cc39bf0 100644
--- a/tests/briar_wrapper/models/test_contacts.py
+++ b/tests/briar_wrapper/models/test_contacts.py
@@ -6,6 +6,8 @@ import json
 
 import pytest
 import requests_mock
+from briar_wrapper.exceptions.pending_invalid_public_key import \
+    PendingContactInvalidPublicKeyException
 
 from briar_wrapper.models.contacts import Contacts
 from briar_wrapper.models.socket_listener import SocketListener
@@ -14,6 +16,7 @@ BASE_HTTP_URL = "http://localhost:7000/v1/contacts/"
 
 TEST_ALIAS = "Alice"
 TEST_CONTACT_ID = 42
+TEST_PENDING_CONTACT_ID = "jsTgWcsEQ2g9rnomeK1g/hmO8M1Ix6ZIGWAjgBtlS9U="
 
 TEST_CONTACT_FIRST = {
     "lastChatActivity": 1
@@ -50,6 +53,30 @@ def match_request_add_pending(request):
     return {"alias": TEST_ALIAS, "link": TEST_LINK} == request.json()
 
 
+@requests_mock.Mocker(kw="requests_mock")
+def test_add_pending_error(api, request_headers, requests_mock):
+    contacts = Contacts(api)
+    requests_mock.post(BASE_HTTP_URL + "add/pending/",
+                       status_code=400,
+                       json={"error": "INVALID_PUBLIC_KEY"})
+    with pytest.raises(PendingContactInvalidPublicKeyException):
+        contacts.add_pending(TEST_LINK, TEST_ALIAS)
+
+
+@requests_mock.Mocker(kw="requests_mock")
+def test_delete_pending(api, request_headers, requests_mock):
+    contacts = Contacts(api)
+    requests_mock.register_uri("DELETE",
+                               BASE_HTTP_URL + "add/pending/",
+                               request_headers=request_headers,
+                               additional_matcher=match_request_delete_pending)
+    contacts.delete_pending(TEST_PENDING_CONTACT_ID)
+
+
+def match_request_delete_pending(request):
+    return {"pendingContactId": TEST_PENDING_CONTACT_ID} == request.json()
+
+
 @requests_mock.Mocker(kw="requests_mock")
 def test_set_alias(api, request_headers, requests_mock):
     contacts = Contacts(api)
-- 
GitLab