Skip to content

Commit 3c361ed

Browse files
committed
Axe unused tests and improve comments in datainterface.
1 parent 7c0e78e commit 3c361ed

3 files changed

Lines changed: 49 additions & 103 deletions

File tree

tests/support/wsgisupp.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
from tests.support.suppconst import MIG_BASE
4040

41+
OBJECTS_TYPE = 'objects'
42+
4143

4244
def _import_forcibly(module_name, relative_module_dir=None):
4345
"""Custom import function to allow an import of a file for testing
@@ -257,3 +259,12 @@ def called_once(fake):
257259
raise AssertionError("response did not contain valid JSON")
258260

259261
return content, headers
262+
263+
def assertWsgiJsonResponse(self, prepared_wsgi):
264+
content, _ = self.assertWsgiResponse(None, prepared_wsgi, None, content_format='json')
265+
266+
assert isinstance(content, list)
267+
268+
found_objects = [obj for obj in content if obj['object_type'] == OBJECTS_TYPE]
269+
assert len(found_objects) == 1, "object with type '%s' was not found" % (OBJECTS_TYPE,)
270+
return found_objects[0][OBJECTS_TYPE]

tests/test_mig_shared_functionality_datainterface.py

Lines changed: 38 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/test_mig_shared_functionality_tmplinterface.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -164,38 +164,6 @@ def test_list_peers_arranges_template_output(self):
164164
}
165165
})
166166

167-
class MigSharedFunctionalityTmplinterface_with_peer_request(MigTestCase):
168-
"""Wrap unit tests for the corresponding module"""
169-
170-
TEST_CLIENT_ID = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com'
171-
TEST_PEER_ID = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Peer User/emailAddress=peer@example.com'
172-
173-
def _provide_configuration(self):
174-
return 'testconfig'
175-
176-
def before_each(self):
177-
self.test_user_dir = self._provision_test_user(self, self.TEST_CLIENT_ID)
178-
#self.test_user_dir = self._provision_test_user(self, self.TEST_CLIENT_ID)
179-
180-
# fabiricate a peer
181-
peers, err = accountreq.parse_peers_userid(self.configuration, [self.TEST_PEER_ID])
182-
if err:
183-
self.assertTrue(False, "error parsing peers")
184-
185-
all_peers = {}
186-
for user in peers:
187-
fill_distinguished_name(user)
188-
peer_id = user['distinguished_name']
189-
all_peers[peer_id] = user
190-
191-
client_dir = client_id_dir(self.TEST_CLIENT_ID)
192-
peers_path = os.path.join(self.configuration.user_settings, client_dir,
193-
DEFAULT_PEERS_FILENAME)
194-
dump(all_peers, peers_path)
195-
196-
def test_test_test_test(self):
197-
pass
198-
199167

200168
class MigSharedFunctionalityTmplinterface__end_to_end(MigTestCase,
201169
WsgiAssertMixin,

0 commit comments

Comments
 (0)