...
 
Commits (3)
......@@ -14,7 +14,7 @@ from briar.api.model import Model
class PrivateChat(Model):
def get(self, contact_id):
url = urljoin(BASE_HTTP_URL, 'messages/%i' % contact_id)
url = urljoin(BASE_HTTP_URL, "messages/%i" % contact_id)
request = _get(url, headers=self._headers)
return request.json()
......@@ -24,5 +24,5 @@ class PrivateChat(Model):
contact_id=contact_id)
def send(self, contact_id, message):
url = urljoin(BASE_HTTP_URL, 'messages/%i' % contact_id)
_post(url, headers=self._headers, json={'text': message})
url = urljoin(BASE_HTTP_URL, "messages/%i" % contact_id)
_post(url, headers=self._headers, json={"text": message})
......@@ -8,14 +8,32 @@ import requests_mock
from briar.api.models.private_chat import PrivateChat
BASE_HTTP_URL = "http://localhost:7000/v1/messages/%s"
SEND_TEXT = "Hello World"
@requests_mock.Mocker(kw='requests_mock')
@requests_mock.Mocker(kw="requests_mock")
def test_get_empty(api, request_headers, requests_mock):
private_chat = PrivateChat(api)
contact_id = 1
url = "http://localhost:7000/v1/messages/%s" % contact_id
url = BASE_HTTP_URL % contact_id
response = []
requests_mock.register_uri("GET", url, request_headers=request_headers,
text=json.dumps(response))
assert private_chat.get(contact_id) == response
@requests_mock.Mocker(kw="requests_mock")
def test_send_message(api, request_headers, requests_mock):
private_chat = PrivateChat(api)
contact_id = 1
url = BASE_HTTP_URL % contact_id
requests_mock.register_uri("POST", url, request_headers=request_headers,
additional_matcher=match_request_text)
private_chat.send(contact_id, SEND_TEXT)
def match_request_text(request):
return {"text": SEND_TEXT} == request.json()