@@ -53,52 +53,45 @@ def _only_output_objects(output_objects, with_object_type=None):
5353 return [o for o in output_objects if o ['object_type' ] == with_object_type ]
5454
5555
56- class MigSharedFunctionalityDatainterface_internals :
57- """Wrap unit tests for the corresponding module"""
56+ class MigSharedFunctionalityDatainterface__generic (MigTestCase ,
57+ WsgiAssertMixin ):
58+ """Tests of end to end generic behaviour of datainterface"""
5859
5960 TEST_CLIENT_ID = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com'
6061
6162 def _provide_configuration (self ):
6263 return 'testconfig'
6364
6465 def before_each (self ):
65- self .test_user_dir = self ._provision_test_user (self , self .TEST_CLIENT_ID )
66-
67- def assertSingleOutputObject (self , output_objects , with_object_type = None ):
68- assert with_object_type is not None
69- found_objects = _only_output_objects (output_objects ,
70- with_object_type = with_object_type )
71- self .assertEqual (len (found_objects ), 1 )
72- return found_objects [0 ]
73-
74- def test_xxx (self ):
75- wsgi_environ = create_wsgi_environ (self .configuration , 'http://localhost/foobar' ,
76- method = 'POST' )
77-
78- user_arguments_dict = {
79- 'type' : ['migux_apps_peers__new' ],
80- 'operation' : ['create' ],
81- 'output_format' : ['json' ],
66+ user_paths_dict = self ._provision_test_user_return_dict (self , self .TEST_CLIENT_ID , )
67+ self .test_user_settings_dir = user_paths_dict ['user_settings_dir' ]
68+
69+ def test_wsgi_nonexistent_route (self ):
70+ request_body = {
71+ 'type' : '__nonexistent' ,
72+ 'operation' : 'create' ,
73+ 'content' : 'insert me' ,
8274 }
83- (output_objects , status ) = submain (self .configuration , self .logger ,
84- client_id = self .TEST_CLIENT_ID ,
85- environ = wsgi_environ ,
86- user_arguments_dict = user_arguments_dict )
75+ prepared_wsgi = self .prepareWsgiAssert (self .configuration ,
76+ 'http://localhost/datainterface.py' ,
77+ form = request_body ,
78+ mig_user_dn = self .TEST_CLIENT_ID )
79+
80+ json_response = self .assertWsgiJsonResponse (prepared_wsgi )
81+
82+ status = json_response ['status' ]
83+ self .assertEqual (status , 404 )
8784
88- # NOTE: start entry with headers and actual content
89- self .assertEqual (len (output_objects ), 2 )
90- relevant_obj = self .assertSingleOutputObject (output_objects ,
91- with_object_type = 'error_text' )
92- self .assertEqual (relevant_obj ['text' ],
93- 'Workflows are not enabled on this system' )
85+ self .assertIn ('error' , json_response )
86+ self .assertEqual (json_response ['error' ], 'invalid route' )
9487
9588
96- class MigSharedFunctionalityDatainterface__content_type_form_data (MigTestCase ,
89+ class MigSharedFunctionalityDatainterface__peers (MigTestCase ,
9790 WsgiAssertMixin ,
9891 FixtureAssertMixin ,
9992 PickleAssertMixin ,
10093 UserAssertMixin ):
101- """Tests of the end to end usage of jsoninterface """
94+ """Tests of the end to end peers behaviours of datainterface """
10295
10396 TEST_CLIENT_ID = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com'
10497 TEST_PEER_DN = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=peer@example.com'
@@ -111,35 +104,6 @@ def before_each(self):
111104 user_paths_dict = self ._provision_test_user_return_dict (self , self .TEST_CLIENT_ID , )
112105 self .test_user_settings_dir = user_paths_dict ['user_settings_dir' ]
113106
114- # def _pending_peer_from_fixture(self):
115- # pending_peers_fixure = self.prepareFixtureAssert('pending_peers--single', fixture_format='json')
116- # pending_peers_by_dn = dict(pending_peers_fixure.fixture_data)
117- # return pending_peers_by_dn[self.TEST_PENDING_PEER_DN]
118-
119- def assertJsonResponse (self , content ):
120- with_object_type = 'objects'
121- assert isinstance (content , list )
122- found_objects = [obj for obj in content if obj ['object_type' ] == with_object_type ]
123- assert len (found_objects ) == 1 , "object with type '%s' was not found" % (with_object_type ,)
124- return found_objects [0 ]['objects' ]
125-
126- def test_wsgi_nonexistent_route (self ):
127- request_body = {
128- 'type' : '__nonexistent' ,
129- 'operation' : 'create' ,
130- 'content' : 'insert me' ,
131- }
132- prepared_wsgi = self .prepareWsgiAssert (self .configuration ,
133- 'http://localhost/datainterface.py' ,
134- form = request_body ,
135- mig_user_dn = self .TEST_CLIENT_ID )
136-
137- content , _ = self .assertWsgiResponse (None , prepared_wsgi , None , content_format = 'json' )
138-
139- json_response = self .assertJsonResponse (content )
140- self .assertIn ('error' , json_response )
141- self .assertEqual (json_response ['error' ], 'invalid route' )
142-
143107 def test_wsgi_peers_new_for_content_type_form_data (self ):
144108 test_pending_peer = {
145109 "country" : "DK" ,
@@ -160,9 +124,10 @@ def test_wsgi_peers_new_for_content_type_form_data(self):
160124 form = request_body ,
161125 mig_user_dn = self .TEST_CLIENT_ID )
162126
163- content , _ = self .assertWsgiResponse (None , prepared_wsgi , content_format = 'json' )
164- json_response = self .assertJsonResponse (content )
165- self .assertEqual (json_response ['status' ], 200 )
127+ json_response = self .assertWsgiJsonResponse (prepared_wsgi )
128+
129+ status = json_response ['status' ]
130+ self .assertEqual (status , 200 )
166131
167132 user_pending_entries = os .listdir (self .configuration .user_pending )
168133 user_pending_filename = user_pending_entries [0 ]
@@ -190,8 +155,9 @@ def test_wsgi_peers_summary(self):
190155 form = request_body ,
191156 mig_user_dn = self .TEST_CLIENT_ID )
192157
193- content , _ = self .assertWsgiResponse (None , prepared_wsgi , content_format = 'json' )
194- json_response = self .assertJsonResponse (content )
158+
159+ json_response = self .assertWsgiJsonResponse (prepared_wsgi )
160+
195161 status = json_response ['status' ]
196162 self .assertEqual (status , 200 )
197163
@@ -218,8 +184,8 @@ def test_wsgi_peers_accepted_delete(self):
218184 form = request_body ,
219185 mig_user_dn = self .TEST_CLIENT_ID )
220186
221- content , _ = self .assertWsgiResponse ( None , prepared_wsgi , content_format = 'json' )
222- json_response = self . assertJsonResponse ( content )
187+ json_response = self .assertWsgiJsonResponse ( prepared_wsgi )
188+
223189 status = json_response ['status' ]
224190 self .assertEqual (status , 200 )
225191
@@ -245,8 +211,8 @@ def test_wsgi_peers_requsted_accept(self):
245211 form = request_body ,
246212 mig_user_dn = self .TEST_CLIENT_ID )
247213
248- content , _ = self .assertWsgiResponse ( None , prepared_wsgi , content_format = 'json' )
249- json_response = self . assertJsonResponse ( content )
214+ json_response = self .assertWsgiJsonResponse ( prepared_wsgi )
215+
250216 status = json_response ['status' ]
251217 self .assertEqual (status , 200 )
252218
@@ -280,8 +246,9 @@ def test_wsgi_peers_requested_delete(self):
280246 form = request_body ,
281247 mig_user_dn = self .TEST_CLIENT_ID )
282248
283- content , _ = self .assertWsgiResponse (None , prepared_wsgi , content_format = 'json' )
284- json_response = self .assertJsonResponse (content )
249+
250+ json_response = self .assertWsgiJsonResponse (prepared_wsgi )
251+
285252 status = json_response ['status' ]
286253 self .assertEqual (status , 200 )
287254
0 commit comments