Commit 583e081c authored by Nico Alt's avatar Nico Alt

Add first tests for private chat

Also move shared pytest fixtures to conftest.py
parent 5763fcb9
Pipeline #3559 passed with stage
in 3 minutes and 57 seconds
......@@ -3,12 +3,8 @@
# License-Filename: LICENSE.md
import json
from random import choice
import requests_mock
from string import ascii_letters, digits
from unittest import mock
import pytest
import requests_mock
from briar.api.models.contacts import Contacts
......@@ -22,23 +18,3 @@ def test_get_empty(api, request_headers, requests_mock):
request_headers=request_headers,
text=json.dumps(response))
assert contacts.get() == response
@pytest.fixture
def api(auth_token):
api = mock.Mock()
api.auth_token = auth_token
return api
@pytest.fixture
def request_headers(auth_token):
request_headers = {
"Authorization": 'Bearer %s' % auth_token
}
return request_headers
@pytest.fixture
def auth_token():
return ''.join(choice(ascii_letters + digits) for i in range(33))
# Copyright (c) 2019 Nico Alt
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
import json
import requests_mock
from briar.api.models.private_chat import PrivateChat
@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
response = []
requests_mock.register_uri("GET", url, request_headers=request_headers,
text=json.dumps(response))
assert private_chat.get(contact_id) == response
# Copyright (c) 2019 Nico Alt
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
from random import choice
from string import ascii_letters, digits
from unittest import mock
import pytest
# pylint: disable=redefined-outer-name
@pytest.fixture
def api(auth_token):
api = mock.Mock()
api.auth_token = auth_token
return api
@pytest.fixture
def auth_token():
return ''.join(choice(ascii_letters + digits) for i in range(33))
@pytest.fixture
def request_headers(auth_token):
request_headers = {
"Authorization": 'Bearer %s' % auth_token
}
return request_headers
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment