|
4 | 4 |
|
5 | 5 |
|
6 | 6 | 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 | + |
7 | 31 | def test_parse(self): |
8 | 32 | 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 |
15 | 39 | }], |
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': [] |
21 | 45 | }], |
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'], |
38 | 62 | }, |
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' |
55 | 79 | } |
56 | 80 | }, |
57 | | - "workload-version": "1.2" |
| 81 | + 'workload-version': '1.2' |
58 | 82 | } |
59 | 83 | } |
60 | 84 | }) |
61 | 85 | if status.relations != status['relations']: |
62 | | - raise Exception("subscript not equal to attr") |
| 86 | + raise Exception('subscript not equal to attr') |
63 | 87 | if status['relations'][0]['endpoints'][0]['application'] != 'application': |
64 | | - raise Exception("failed to use complex subscript") |
| 88 | + raise Exception('failed to use complex subscript') |
65 | 89 | 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') |
67 | 91 | 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') |
69 | 93 | if not isinstance(status.relations[0].endpoints[0], client.EndpointStatus): |
70 | | - raise Exception("status relation endpoint is not a EndpointStatus") |
| 94 | + raise Exception('status relation endpoint is not a EndpointStatus') |
71 | 95 | if not isinstance(status.applications['app'], client.ApplicationStatus): |
72 | | - raise Exception("status application is not a ApplicationStatus") |
| 96 | + raise Exception('status application is not a ApplicationStatus') |
0 commit comments