test_client.py 1.11 KB
Newer Older
Jo Sama's avatar
Jo Sama committed
1
2
import types

Jonas Braathen's avatar
Jonas Braathen committed
3
from topdesk_client.models import Operator
Jo Sama's avatar
Jo Sama committed
4
5
6


def test_get_operator(client, base_url, requests_mock, operator_data):
Jo Sama's avatar
Jo Sama committed
7
8
9
10
    identity = 'a-b-c-d'
    requests_mock.get(client.urls.get_operator(identity),
                      json=operator_data)
    expected = client.get_operator(identity)
Jo Sama's avatar
Jo Sama committed
11
    assert isinstance(expected, Operator)
Jo Sama's avatar
Jo Sama committed
12
13
14
15
16
17
18
19
20


def test_list_operators(client, base_url, requests_mock, operator_list_data):
    requests_mock.get(client.urls.get_operators(),
                      json=operator_list_data)
    expected = client.list_operators()
    assert isinstance(expected, types.GeneratorType)
    for x in expected:
        assert isinstance(x, Operator)
Jo Sama's avatar
Jo Sama committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34


def test_create_operator(client,
                         base_url,
                         requests_mock,
                         operator_data,
                         operator):
    m = requests_mock.post(client.urls.get_operators())
    client.create_operator(operator)

    object_sent = m.request_history[-1].text
    sent_operator = Operator.from_json(object_sent)
    assert(sent_operator == operator)
    assert(sent_operator.dict() == operator.dict())