Skip to content

Commit

Permalink
[#2939] Fix tests in tests/logic/test_action.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Oct 12, 2012
1 parent 2b19fcf commit ba4f348
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ckan/tests/logic/test_action.py
Expand Up @@ -150,13 +150,13 @@ def test_03_create_update_package(self):
wee = json.dumps(package)
postparams = '%s=1' % json.dumps(package)
res = self.app.post('/api/action/package_create', params=postparams,
extra_environ={'Authorization': 'tester'})
extra_environ={'Authorization': str(self.sysadmin_user.apikey)})
package_created = json.loads(res.body)['result']
print package_created
package_created['name'] = 'moo'
postparams = '%s=1' % json.dumps(package_created)
res = self.app.post('/api/action/package_update', params=postparams,
extra_environ={'Authorization': 'tester'})
extra_environ={'Authorization': str(self.sysadmin_user.apikey)})

package_updated = json.loads(res.body)['result']
package_updated.pop('revision_id')
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_41_create_resource(self):

anna_id = model.Package.by_name(u'annakarenina').id
resource = {'package_id': anna_id, 'url': 'http://new_url'}
api_key = model.User.get('annafan').apikey.encode('utf8')
api_key = model.User.get('testsysadmin').apikey.encode('utf8')
postparams = '%s=1' % json.dumps(resource)
res = self.app.post('/api/action/resource_create', params=postparams,
extra_environ={'Authorization': api_key })
Expand All @@ -209,7 +209,7 @@ def test_42_create_resource_with_error(self):

anna_id = model.Package.by_name(u'annakarenina').id
resource = {'package_id': anna_id, 'url': 'new_url', 'created': 'bad_date'}
api_key = model.User.get('annafan').apikey.encode('utf8')
api_key = model.User.get('testsysadmin').apikey.encode('utf8')

postparams = '%s=1' % json.dumps(resource)
res = self.app.post('/api/action/resource_create', params=postparams,
Expand Down Expand Up @@ -557,15 +557,15 @@ def test_19_update_resource(self):

postparams = '%s=1' % json.dumps(package)
res = self.app.post('/api/action/package_create', params=postparams,
extra_environ={'Authorization': 'tester'})
extra_environ={'Authorization': str(self.sysadmin_user.apikey)})
package_created = json.loads(res.body)['result']

resource_created = package_created['resources'][0]
new_resource_url = u'http://www.annakareinanew.com/download/'
resource_created['url'] = new_resource_url
postparams = '%s=1' % json.dumps(resource_created)
res = self.app.post('/api/action/resource_update', params=postparams,
extra_environ={'Authorization': 'tester'})
extra_environ={'Authorization': str(self.sysadmin_user.apikey)})

resource_updated = json.loads(res.body)['result']
assert resource_updated['url'] == new_resource_url, resource_updated
Expand Down Expand Up @@ -1164,9 +1164,10 @@ def test_2_update_many(self):
class TestActionPackageSearch(WsgiAppCase):

@classmethod
def setup_class(self):
def setup_class(cls):
setup_test_search_index()
CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')

@classmethod
def teardown_class(self):
Expand Down Expand Up @@ -1244,7 +1245,7 @@ def test_4_sort_by_metadata_modified(self):
pkg_dict['tags'].append({'name': 'new-tag'})
pkg_params = '%s=1' % json.dumps(pkg_dict)
res = self.app.post('/api/action/package_update', params=pkg_params,
extra_environ={'Authorization': 'tester'})
extra_environ={'Authorization': str(self.sysadmin_user.apikey)})

res = self.app.post('/api/action/package_search', params=search_params)
result = json.loads(res.body)['result']
Expand Down Expand Up @@ -1303,6 +1304,7 @@ def setup_class(cls):
setup_test_search_index()
CreateTestData.create()
MockPackageSearchPlugin().disable()
cls.sysadmin_user = model.User.get('testsysadmin')

@classmethod
def teardown_class(cls):
Expand Down

0 comments on commit ba4f348

Please sign in to comment.