Skip to content

Commit 74f2b04

Browse files
committed
Extend definition tests
1 parent 866e5f2 commit 74f2b04

1 file changed

Lines changed: 75 additions & 51 deletions

File tree

tests/unit/test_definitions.py

Lines changed: 75 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,93 @@
44

55

66
class TestDefinitions(unittest.TestCase):
7+
8+
def test_dict_legacy(self):
9+
status = client.FullStatus.from_json({
10+
'relations': [{
11+
'endpoints': [{
12+
'application': 'application',
13+
'name': 'name',
14+
'role': 'role',
15+
'subordinate': True
16+
}],
17+
'id': 1,
18+
'interface': 'interface',
19+
'key': 'key',
20+
'scope': 'scope',
21+
'status': []
22+
}]
23+
})
24+
if status.relations != status['relations']:
25+
raise Exception('subscript not equal to attr')
26+
if status.relations != status.get('relations'):
27+
raise Exception('get() not equal to attr')
28+
if status.get('non-existing', 'foo') != 'foo':
29+
raise Exception('get defaulting missing attr')
30+
731
def test_parse(self):
832
status = client.FullStatus.from_json({
9-
"relations": [{
10-
"endpoints": [{
11-
"application": "application",
12-
"name": "name",
13-
"role": "role",
14-
"subordinate": True
33+
'relations': [{
34+
'endpoints': [{
35+
'application': 'application',
36+
'name': 'name',
37+
'role': 'role',
38+
'subordinate': True
1539
}],
16-
"id": 1,
17-
"interface": "interface",
18-
"key": "key",
19-
"scope": "scope",
20-
"status": []
40+
'id': 1,
41+
'interface': 'interface',
42+
'key': 'key',
43+
'scope': 'scope',
44+
'status': []
2145
}],
22-
"applications": {
23-
"app": {
24-
"can-upgrade-to": "something",
25-
"charm": "charm",
26-
"charm-profile": "profile",
27-
"charm-version": "2",
28-
"endpoint-bindings": None,
29-
"err": None,
30-
"exposed": True,
31-
"int": 0,
32-
"life": "life",
33-
"meter-statuses": {},
34-
"provider-id": "provider-id",
35-
"public-address": "1.1.1.1",
36-
"relations": {
37-
"a": ["b", "c"],
46+
'applications': {
47+
'app': {
48+
'can-upgrade-to': 'something',
49+
'charm': 'charm',
50+
'charm-profile': 'profile',
51+
'charm-version': '2',
52+
'endpoint-bindings': None,
53+
'err': None,
54+
'exposed': True,
55+
'int': 0,
56+
'life': 'life',
57+
'meter-statuses': {},
58+
'provider-id': 'provider-id',
59+
'public-address': '1.1.1.1',
60+
'relations': {
61+
'a': ['b', 'c'],
3862
},
39-
"series": "focal",
40-
"status": {},
41-
"subordinate-to": ["other"],
42-
"units": {
43-
"unit-id": {
44-
"address": "1.1.1.1",
45-
"agent-status": {},
46-
"charm": "charm",
47-
"leader": True,
48-
"machine": "machine-0",
49-
"opened-ports": ["1234"],
50-
"provider-id": "provider",
51-
"public-address": "1.1.1.2",
52-
"subordinates": {},
53-
"workload-status": {},
54-
"workload-version": "1.2"
63+
'series': 'focal',
64+
'status': {},
65+
'subordinate-to': ['other'],
66+
'units': {
67+
'unit-id': {
68+
'address': '1.1.1.1',
69+
'agent-status': {},
70+
'charm': 'charm',
71+
'leader': True,
72+
'machine': 'machine-0',
73+
'opened-ports': ['1234'],
74+
'provider-id': 'provider',
75+
'public-address': '1.1.1.2',
76+
'subordinates': {},
77+
'workload-status': {},
78+
'workload-version': '1.2'
5579
}
5680
},
57-
"workload-version": "1.2"
81+
'workload-version': '1.2'
5882
}
5983
}
6084
})
6185
if status.relations != status['relations']:
62-
raise Exception("subscript not equal to attr")
86+
raise Exception('subscript not equal to attr')
6387
if status['relations'][0]['endpoints'][0]['application'] != 'application':
64-
raise Exception("failed to use complex subscript")
88+
raise Exception('failed to use complex subscript')
6589
if status.applications['app'].relations['a'][0] != 'b':
66-
raise Exception("object with array type is invalid")
90+
raise Exception('object with array type is invalid')
6791
if not isinstance(status.relations[0], client.RelationStatus):
68-
raise Exception("status relation is not a RelationStatus")
92+
raise Exception('status relation is not a RelationStatus')
6993
if not isinstance(status.relations[0].endpoints[0], client.EndpointStatus):
70-
raise Exception("status relation endpoint is not a EndpointStatus")
71-
if not isinstance(status.get('applications')['app'], client.ApplicationStatus):
72-
raise Exception("status application is not a ApplicationStatus")
94+
raise Exception('status relation endpoint is not a EndpointStatus')
95+
if not isinstance(status.applications['app'], client.ApplicationStatus):
96+
raise Exception('status application is not a ApplicationStatus')

0 commit comments

Comments
 (0)