From 3235ec0bbdc12ae0f75a7ca860cdaf2fce1e7995 Mon Sep 17 00:00:00 2001
From: Nico Alt <nicoalt@posteo.org>
Date: Fri, 4 Sep 2020 14:00:00 +0000
Subject: [PATCH] Support deleting contacts

Fixes #16
---
 briar_wrapper/models/contacts.py            | 14 ++++++++++++++
 tests/briar_wrapper/models/test_contacts.py | 10 ++++++++++
 2 files changed, 24 insertions(+)

diff --git a/briar_wrapper/models/contacts.py b/briar_wrapper/models/contacts.py
index dc88afb..4820f7b 100644
--- a/briar_wrapper/models/contacts.py
+++ b/briar_wrapper/models/contacts.py
@@ -8,6 +8,7 @@ Wrapper around Briar API's _/contacts/_ resource
 from operator import itemgetter
 from urllib.parse import urljoin
 
+from requests import delete as _delete
 from requests import get as _get
 from requests import post as _post
 
@@ -35,6 +36,19 @@ class Contacts(Model):
         url = urljoin(BASE_HTTP_URL, self._API_ENDPOINT + "add/pending/")
         _post(url, headers=self._headers, json={"link": link, "alias": alias})
 
+    def delete(self, contact_id):
+        # pylint: disable=line-too-long
+        """
+
+        Deletes the contact with `contact_id`
+
+        [Upstream documentation](https://code.briarproject.org/briar/briar/blob/master/briar-headless/README.md#removing-a-contact)
+
+        .. versionadded:: 0.0.4
+        """
+        url = urljoin(BASE_HTTP_URL, self.API_ENDPOINT + str(contact_id))
+        _delete(url, headers=self._headers)
+
     def get(self):
         # pylint: disable=line-too-long
         """
diff --git a/tests/briar_wrapper/models/test_contacts.py b/tests/briar_wrapper/models/test_contacts.py
index 68029ab..3bd6c6d 100644
--- a/tests/briar_wrapper/models/test_contacts.py
+++ b/tests/briar_wrapper/models/test_contacts.py
@@ -48,6 +48,16 @@ def match_request_add_pending(request):
     return {"alias": TEST_ALIAS, "link": TEST_LINK} == request.json()
 
 
+@requests_mock.Mocker(kw="requests_mock")
+def test_delete(api, request_headers, requests_mock):
+    contacts = Contacts(api)
+    contact_id = 137
+    requests_mock.register_uri("DELETE",
+                               BASE_HTTP_URL + str(contact_id),
+                               request_headers=request_headers)
+    contacts.delete(contact_id)
+
+
 @requests_mock.Mocker(kw='requests_mock')
 def test_get(api, request_headers, requests_mock):
     contacts = Contacts(api)
-- 
GitLab