|
1 | 1 | """Tests for datagov_inventory plugin.py.""" |
2 | 2 |
|
3 | | -from nose.tools import assert_raises |
| 3 | +from builtins import object |
| 4 | +from pytest import raises as assert_raises |
| 5 | +import pytest |
4 | 6 |
|
5 | | -from ckan.lib import search |
6 | 7 | import ckan.logic as logic |
7 | 8 | import ckan.model as model |
8 | 9 |
|
|
19 | 20 | is_denied = False |
20 | 21 |
|
21 | 22 |
|
| 23 | +@pytest.mark.usefixtures(u"clean_index") |
| 24 | +@pytest.mark.usefixtures(u"clean_db") |
22 | 25 | class TestDatagovInventoryAuth(object): |
23 | 26 |
|
24 | | - @classmethod |
25 | | - def setup_class(self): |
26 | | - '''Nose runs this method once to setup our test class.''' |
27 | | - |
28 | 27 | def setup(self): |
29 | | - '''Nose runs this method before each test method in our test class.''' |
30 | | - |
31 | 28 | # Start with a clean database and index for each test |
32 | | - search.clear_all() |
33 | 29 | self.clean_datastore() |
34 | | - model.repo.rebuild_db() |
35 | | - |
36 | | - def teardown(self): |
37 | | - '''Nose runs this method after each test method in our test class.''' |
38 | 30 |
|
39 | 31 | def setup_test_orgs_users(self): |
40 | 32 |
|
@@ -97,8 +89,8 @@ def factory_dataset(self, **kwargs): |
97 | 89 | # Return id string for the package and resoruce just created |
98 | 90 | return({'package_id': dataset['id'], |
99 | 91 | 'tag_id': dataset_params['tag_string'], |
100 | | - 'resource_id': dataset['resources'][0]['id'], |
101 | | - 'revision_id': dataset['revision_id']}) |
| 92 | + 'resource_id': dataset['resources'][0]['id']}) |
| 93 | + # 'revision_id': dataset['revision_id']}) |
102 | 94 |
|
103 | 95 | def assert_user_authorization(self, |
104 | 96 | auth_function, |
@@ -127,11 +119,10 @@ def assert_user_authorization(self, |
127 | 119 | assert actual_authorization == expected_user_access_dict[user] |
128 | 120 | else: |
129 | 121 | # We expect users to be denied |
130 | | - assert_raises(logic.NotAuthorized, |
131 | | - helpers.call_auth, |
132 | | - auth_function, |
133 | | - context=context, |
134 | | - id=object_id) |
| 122 | + with assert_raises(logic.NotAuthorized): |
| 123 | + helpers.call_auth(auth_function, |
| 124 | + context=context, |
| 125 | + id=object_id) |
135 | 126 |
|
136 | 127 | def test_auth_format_autocomplete(self): |
137 | 128 | # Create test users and test group |
@@ -285,33 +276,6 @@ def test_auth_resource_show_for_public_gsa_dataset(self): |
285 | 276 | 'anonymous': is_allowed |
286 | 277 | }, object_id=dataset['resource_id']) |
287 | 278 |
|
288 | | - def test_auth_revision_list(self): |
289 | | - # Create test users and test data |
290 | | - self.setup_test_orgs_users() |
291 | | - |
292 | | - self.assert_user_authorization('revision_list', { |
293 | | - 'gsa_admin': is_allowed, |
294 | | - 'gsa_editor': is_allowed, |
295 | | - 'gsa_member': is_allowed, |
296 | | - 'doi_admin': is_allowed, |
297 | | - 'doi_member': is_allowed, |
298 | | - 'anonymous': is_denied |
299 | | - }) |
300 | | - |
301 | | - def test_auth_revision_show(self): |
302 | | - # Create test users and test data |
303 | | - self.setup_test_orgs_users() |
304 | | - dataset = self.factory_dataset(owner_org='gsa', private=True) |
305 | | - |
306 | | - self.assert_user_authorization('revision_show', { |
307 | | - 'gsa_admin': is_allowed, |
308 | | - 'gsa_editor': is_allowed, |
309 | | - 'gsa_member': is_allowed, |
310 | | - 'doi_admin': is_allowed, |
311 | | - 'doi_member': is_allowed, |
312 | | - 'anonymous': is_denied |
313 | | - }, dataset['revision_id']) |
314 | | - |
315 | 279 | def test_auth_site_read(self): |
316 | 280 | # Create test users and test data |
317 | 281 | self.setup_test_orgs_users() |
|
0 commit comments