diff --git a/tests/briar_wrapper/models/test_contacts.py b/tests/briar_wrapper/models/test_contacts.py index 20175657a8610c97aa175d4ad4e8c818461c3f1e..cc39bf0c2113863a1cce976630cdd5d7f3acbc6d 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)