Commit 3ce5d485 authored by Jo Sama's avatar Jo Sama 😱
Browse files

MAKE TESTS GRAET AGAIN!

parent 72b6d1b2
......@@ -38,6 +38,11 @@ def operator_data():
return load_json_file('operator.json')
@pytest.fixture
def single_operator_list_data():
return load_json_file('single_operator_list.json')
@pytest.fixture
def operator():
d = load_json_file('operator.json')
......@@ -60,6 +65,11 @@ def person_data():
return load_json_file('person.json')
@pytest.fixture
def single_person_list_data():
return load_json_file('single_person_list.json')
@pytest.fixture
def person():
d = load_json_file('person.json')
......
......@@ -18,6 +18,6 @@
"phoneNumber": "+47 800 00 000",
"mobileNumber": "900 00 000",
"email": "f.j@example.org",
"networkLoginName": "fj",
"tasLoginName": "fj",
"employeeNumber": "123456"
}
......@@ -20,7 +20,7 @@
"phoneNumber": "+47 800 00 000",
"mobileNumber": "900 00 000",
"email": "f.j@example.org",
"networkLoginName": "fj",
"tasLoginName": "fj",
"employeeNumber": "234567"
},
{
......@@ -44,7 +44,7 @@
"phoneNumber": "+47 800 00 001",
"mobileNumber": "900 00 001",
"email": "j.f@example.org",
"networkLoginName": "jf",
"tasLoginName": "jf",
"employeeNumber": "123456"
}
]
[
{
"id": "a-b-c-d",
"surName": "Josefsen",
"firstName": "Franz",
"branch": {
"id": "b-c-d-e",
"name": "USIT",
"clientReferenceNumber": "x-y-z",
"timeZone": "GMT+1",
"extraA": {
"id": "id_extra_a",
"name": "name_extra_a"
},
"extraB": {
"id": "id_extra_b",
"name": "name_extra_b"}
},
"telephone": "+47 800 00 000",
"mobileNumber": "900 00 000",
"email": "f.j@example.org",
"loginName": "fj"
}
]
[
{
"id": "a-b-c-d",
"surName": "Josefsen",
"firstName": "Franz",
"branch": {
"id": "b-c-d-e",
"name": "USIT",
"clientReferenceNumber": "x-y-z",
"timeZone": "GMT+1",
"extraA": {
"id": "id_extra_a",
"name": "name_extra_a"
},
"extraB": {
"id": "id_extra_b",
"name": "name_extra_b"}
},
"phoneNumber": "+47 800 00 000",
"mobileNumber": "900 00 000",
"email": "f.j@example.org",
"tasLoginName": "fj",
"employeeNumber": "123456"
}
]
......@@ -17,6 +17,6 @@
"phoneNumber": "+47 800 00 000",
"mobileNumber": "900 00 000",
"email": "f.j@example.org",
"networkLoginName": "fj",
"tasLoginName": "fj",
"employeeNumber": "123456"
}
import types
import json
from topdesk_client.models import Operator, Person
def test_get_operator(client, base_url, requests_mock, operator_data):
identity = 'a-b-c-d'
requests_mock.get(client.urls.get_operator(identity),
json=operator_data)
def test_get_operator_by_login_name(client,
base_url,
requests_mock,
single_operator_list_data):
identity = 'fj'
requests_mock.get((client.urls.get_operators() +
'?topdesk_login_name=' + identity),
json=single_operator_list_data)
expected = client.get_operator(identity)
assert isinstance(expected, Operator)
def test_get_operator(client,
base_url,
requests_mock,
operator,
operator_data):
requests_mock.get(client.urls.get_operator(operator.id),
json=operator_data)
expected = client.get_operator(operator)
assert isinstance(expected, Operator)
def test_list_operators(client, base_url, requests_mock, operator_list_data):
requests_mock.get(client.urls.get_operators(),
json=operator_list_data)
......@@ -20,6 +36,17 @@ def test_list_operators(client, base_url, requests_mock, operator_list_data):
assert isinstance(x, Operator)
def _patch_operator_for_comparison(obj, operator):
sent_operator = json.loads(obj)
del sent_operator['password']
try:
sent_operator['id'] = operator.inclusive_dict()['id']
except KeyError:
pass
sent_operator['branch'] = operator.branch.inclusive_dict()
return Operator.from_dict(sent_operator)
def test_create_operator(client,
base_url,
requests_mock,
......@@ -28,9 +55,9 @@ def test_create_operator(client,
client.create_operator(uncreated_operator)
object_sent = m.request_history[-1].text
sent_operator = Operator.from_json(object_sent)
assert(sent_operator == uncreated_operator)
assert(_patch_operator_for_comparison(
object_sent, uncreated_operator) == uncreated_operator)
def test_update_operator(client,
......@@ -41,19 +68,30 @@ def test_update_operator(client,
client.update_operator(operator)
object_sent = m.request_history[-1].text
updated_operator = Operator.from_json(object_sent)
assert(updated_operator == operator)
assert _patch_operator_for_comparison(object_sent, operator) == operator
def test_get_person(client, base_url, requests_mock, person_data):
identity = 'a-b-c-d'
requests_mock.get(client.urls.get_person(identity),
json=person_data)
def test_get_person_by_login_name(client,
base_url,
requests_mock,
single_person_list_data):
identity = 'fj'
requests_mock.get((client.urls.get_persons() +
'?ssp_login_name=' + identity),
complete_qs=True,
json=single_person_list_data)
expected = client.get_person(identity)
assert isinstance(expected, Person)
def test_get_person(client, base_url, requests_mock, person, person_data):
requests_mock.get(client.urls.get_person(person.id),
json=person_data)
expected = client.get_person(person)
assert isinstance(expected, Person)
def test_list_persons(client, base_url, requests_mock, person_list_data):
requests_mock.get(client.urls.get_persons(),
json=person_list_data)
......@@ -63,6 +101,17 @@ def test_list_persons(client, base_url, requests_mock, person_list_data):
assert isinstance(x, Person)
def _patch_person_for_comparison(obj, person):
sent_person = json.loads(obj)
del sent_person['password']
try:
sent_person['id'] = person.inclusive_dict()['id']
except KeyError:
pass
sent_person['branch'] = person.branch.inclusive_dict()
return Person.from_dict(sent_person)
def test_create_person(client,
base_url,
requests_mock,
......@@ -71,9 +120,9 @@ def test_create_person(client,
client.create_person(uncreated_person)
object_sent = m.request_history[-1].text
sent_person = Person.from_json(object_sent)
assert(sent_person == uncreated_person)
assert(_patch_person_for_comparison(object_sent,
uncreated_person) == uncreated_person)
def test_update_person(client,
......@@ -84,6 +133,5 @@ def test_update_person(client,
client.update_person(person)
object_sent = m.request_history[-1].text
updated_person = Person.from_json(object_sent)
assert(updated_person == person)
assert(_patch_person_for_comparison(object_sent, person) == person)
......@@ -157,6 +157,9 @@ class BranchReference(BaseModel):
kwargs['include'] = {'id'}
return super(BranchReference, self).dict(*args, **kwargs)
def inclusive_dict(self, *args, **kwargs):
return super(BranchReference, self).dict(*args, **kwargs)
class Operator(BaseModel):
id: Optional[str]
......@@ -183,6 +186,9 @@ class Operator(BaseModel):
kwargs['exclude'] = {'id'}
return super(Operator, self).dict(*args, **kwargs)
def inclusive_dict(self, *args, **kwargs):
return super(Operator, self).dict(*args, **kwargs)
class Person(BaseModel):
id: Optional[str]
......@@ -210,3 +216,6 @@ class Person(BaseModel):
def dict(self, *args, **kwargs):
kwargs['exclude'] = {'id'}
return super(Person, self).dict(*args, **kwargs)
def inclusive_dict(self, *args, **kwargs):
return super(Person, self).dict(*args, **kwargs)
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