33import os
44import os .path
55from identify .main import get_client
6+ from identify .resources .traffic_type import TrafficType
7+ from identify .resources .environment import Environment
8+ from identify .resources .attribute import Attribute
9+ from identify .resources .identity import Identity
610
711
812class TestEndToEnd :
@@ -16,12 +20,10 @@ def setup_class(cls):
1620 cls .mock_server_subprocess = subprocess .Popen (
1721 ['python' , os .path .join (dir_path , 'server.py' )]
1822 )
19- time .sleep (5 )
23+ time .sleep (3 )
2024
21- def test_successful_command_sequence (self ):
25+ def test_traffic_type_endpoint (self ):
2226 '''
23- Test a basic command sequence using the get_client entry point function,
24- issuing calls to a mocked API running in background.
2527 '''
2628 c = get_client ({
2729 'base_url' : 'http://localhost:8888' ,
@@ -30,39 +32,112 @@ def test_successful_command_sequence(self):
3032
3133 tts = c .get_traffic_types ()
3234 assert isinstance (tts , list )
35+ assert all (isinstance (tt , TrafficType ) for tt in tts )
36+ assert all (
37+ {
38+ 'id' : tt .id ,
39+ 'name' : tt .name ,
40+ 'displayAttributeId' : tt .display_attribute_id
41+ } == tt .to_dict ()
42+ for tt in tts
43+ )
44+
45+ def test_environments_endpoint (self ):
46+ '''
47+ '''
48+ c = get_client ({
49+ 'base_url' : 'http://localhost:8888' ,
50+ 'apikey' : 'Admin'
51+ })
3352
3453 envs = c .get_environments ()
3554 assert isinstance (envs , list )
55+ assert all (isinstance (env , Environment ) for env in envs )
56+ assert all (
57+ {
58+ 'id' : env .id ,
59+ 'name' : env .name ,
60+ } == env .to_dict ()
61+ for env in envs
62+ )
3663
37- attrs = c .get_attributes_for_traffic_type (tts [0 ].id )
64+ def test_attribute_endpoints (self ):
65+ '''
66+ '''
67+ c = get_client ({
68+ 'base_url' : 'http://localhost:8888' ,
69+ 'apikey' : 'Admin'
70+ })
71+
72+ attrs = c .get_attributes_for_traffic_type ('1' )
3873 assert isinstance (attrs , list )
74+ assert all (isinstance (attr , Attribute ) for attr in attrs )
75+ assert all (
76+ {
77+ 'id' : attr .id ,
78+ 'trafficTypeId' : attr .traffic_type_id ,
79+ 'displayName' : attr .display_name ,
80+ 'description' : attr .description ,
81+ 'dataType' : attr .data_type ,
82+ } == attr .to_dict ()
83+ for attr in attrs
84+ )
3985
86+ new_attr_props = {
87+ 'id' : 'aa' ,
88+ 'trafficTypeId' : '1' ,
89+ 'displayName' : 'AA' ,
90+ 'description' : 'DESC' ,
91+ 'dataType' : 'STRING'
92+ }
4093 new_attr = c .create_attribute_for_traffic_type (
41- 1 ,
94+ '1' ,
4295 {
4396 'id' : 'aa' ,
44- 'display_name ' : 'AA' ,
97+ 'displayName ' : 'AA' ,
4598 'description' : 'DESC' ,
46- 'data_type ' : 'STRING'
99+ 'dataType ' : 'STRING'
47100 }
48101 )
49- assert isinstance ( new_attr , object )
102+ assert new_attr_props == new_attr . to_dict ( )
50103
51- attrs_2 = c .get_attributes_for_traffic_type ( tts [ 0 ]. id )
52- assert isinstance ( attrs_2 , list )
104+ res_delete = c .delete_attribute_from_schema ( 1 , 'aa' )
105+ assert res_delete is None
53106
54- c .delete_attribute_from_schema (1 , 'aa' )
55- attrs_3 = c .get_attributes_for_traffic_type (tts [0 ].id )
56- assert isinstance (attrs_3 , list )
107+ def test_identity_endpoints (self ):
108+ '''
109+ '''
110+ c = get_client ({
111+ 'base_url' : 'http://localhost:8888' ,
112+ 'apikey' : 'Admin'
113+ })
57114
58115 i1 = c .add_identity ('1' , '1' , 'keycita' , {'a1' : 'qwe' })
59- assert isinstance (i1 , object )
116+ assert isinstance (i1 , Identity )
117+ assert {
118+ 'key' : i1 .key ,
119+ 'environmentId' : i1 .environment_id ,
120+ 'trafficTypeId' : i1 .traffic_type_id ,
121+ 'values' : i1 .values
122+ } == i1 .to_dict ()
60123
61124 i2 = c .update_identity ('1' , '1' , 'keycita' , {'a1' : 'qwe2' })
62- assert isinstance (i2 , object )
125+ assert isinstance (i2 , Identity )
126+ assert {
127+ 'key' : i2 .key ,
128+ 'environmentId' : i2 .environment_id ,
129+ 'trafficTypeId' : i2 .traffic_type_id ,
130+ 'values' : i2 .values
131+ } == i2 .to_dict ()
63132
64133 i3 = c .patch_identity ('1' , '1' , 'keycita' , {'a1' : 'qwe3' })
65- assert isinstance (i3 , object )
134+ assert isinstance (i3 , Identity )
135+ assert {
136+ 'key' : i3 .key ,
137+ 'environmentId' : i3 .environment_id ,
138+ 'trafficTypeId' : i3 .traffic_type_id ,
139+ 'values' : i3 .values
140+ } == i3 .to_dict ()
66141
67142 res_add_identities = c .add_identities (
68143 '1' ,
@@ -73,6 +148,8 @@ def test_successful_command_sequence(self):
73148 }
74149 )
75150 assert res_add_identities is None
151+ assert isinstance (res_add_identities , list )
152+ assert all (isinstance (i , Identity ) for i in res_add_identities )
76153
77154 res_delete_attr = c .delete_attributes_from_key ('1' , '1' , 'keycita' )
78155 assert res_delete_attr is None
0 commit comments