-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_api_object.py
More file actions
80 lines (61 loc) · 2.42 KB
/
test_api_object.py
File metadata and controls
80 lines (61 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from uuid import uuid4
import pytest
from backslash import Backslash
from backslash.api_object import APIObject
from backslash import test, session
# pylint: disable=redefined-outer-name
def test_api_object_equality(client, data1):
assert APIObject(client, data1) == APIObject(client, data1)
assert not APIObject(client, data1) != APIObject(client, data1) # pylint: disable=unneeded-not
def test_api_object_equality_reflexive(client, data1):
api_object = APIObject(client, data1)
assert api_object == api_object
assert not api_object != api_object # pylint: disable=unneeded-not
def test_api_object_not_equal_when_different_clients(data1):
a = APIObject(object(), data1)
b = APIObject(object(), data1)
assert not a == b # pylint: disable=unneeded-not
assert a != b
def test_api_object_not_equal_different_data(client, data1, data2):
a = APIObject(client, data1)
b = APIObject(client, data2)
assert not a == b # pylint: disable=unneeded-not
assert a != b
def test_object_api_url(client):
data = {'api_path': '/rest/objects/1'}
obj = APIObject(client, data)
assert obj.api_url == 'http://127.0.0.1:12345/rest/objects/1'
def test_object_api_repr(client):
data = {'id': 1, 'type': 'test'}
obj = APIObject(client, data)
assert repr(obj) == '<API:test:1>'
def test_object_ui_url(client):
obj = APIObject(client, {})
with pytest.raises(NotImplementedError):
obj.ui_url # pylint: disable=pointless-statement
@pytest.mark.parametrize('object_type', [test.Test, session.Session])
@pytest.mark.parametrize('use_logical', [True, False])
def test_ui_url(client, object_type, logical_id, use_logical):
id = 1002
data = {'id': id, 'logical_id': logical_id if use_logical else None}
if object_type is test.Test:
data['session_display_id'] = str(uuid4())
obj = object_type(client, data)
url = obj.ui_url
display_id = logical_id if use_logical else id
if object_type is test.Test:
assert url == client.url + f"/#/sessions/{data['session_display_id']}/tests/{display_id}"
else:
assert url == client.url + f'/#/{object_type.__name__.lower()}s/{display_id}'
@pytest.fixture
def logical_id():
return str(uuid4())
@pytest.fixture
def client():
return Backslash('http://127.0.0.1:12345', runtoken=None)
@pytest.fixture
def data1():
return {'name': 'data1'}
@pytest.fixture
def data2():
return {'name': 'data2'}