From be4386af978e466fc68d1c3ec8d5ff26236ffb20 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            |  5 +++++
 tests/briar_wrapper/models/test_contacts.py | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/briar_wrapper/models/contacts.py b/briar_wrapper/models/contacts.py
index 81d6304..5ae6a6d 100644
--- a/briar_wrapper/models/contacts.py
+++ b/briar_wrapper/models/contacts.py
@@ -5,6 +5,7 @@
 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
 
@@ -23,6 +24,10 @@ 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):
+        url = urljoin(BASE_HTTP_URL, self.API_ENDPOINT + str(contact_id))
+        _delete(url, headers=self._headers)
+
     def get(self):
         url = urljoin(BASE_HTTP_URL, self.API_ENDPOINT)
         request = _get(url, headers=self._headers)
diff --git a/tests/briar_wrapper/models/test_contacts.py b/tests/briar_wrapper/models/test_contacts.py
index 3af6d2e..caaa247 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