Skip to content

Commit

Permalink
[1767][tests] move test_tag_list_vocab to test_action.py.
Browse files Browse the repository at this point in the history
Update it to use action API.
  • Loading branch information
johnglover committed Feb 13, 2012
1 parent 053cb27 commit bf88c4c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
36 changes: 35 additions & 1 deletion ckan/tests/logic/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_05b_user_show_datasets(self):
dataset = result['datasets'][0]
assert_equal(dataset['name'], u'annakarenina')

def test_06_tag_list(self):
def test_06a_tag_list(self):
postparams = '%s=1' % json.dumps({})
res = self.app.post('/api/action/tag_list', params=postparams)
assert_dicts_equal_ignoring_ordering(
Expand Down Expand Up @@ -308,6 +308,40 @@ def test_06_tag_list(self):
assert 'id' in res_obj['result'][1]
assert 'id' in res_obj['result'][2]

def test_06b_tag_list_vocab(self):
vocab_name = 'test-vocab'
tag_name = 'test-vocab-tag'

# create vocab
params = json.dumps({'name': vocab_name})
extra_environ = {'Authorization' : str(self.sysadmin_user.apikey)}
response = self.app.post('/api/action/vocabulary_create', params=params,
extra_environ=extra_environ)
assert response.json['success']
vocab_id = response.json['result']['id']

# create new tag with vocab
params = json.dumps({'name': tag_name, 'vocabulary_id': vocab_id})
extra_environ = {'Authorization' : str(self.sysadmin_user.apikey)}
response = self.app.post('/api/action/tag_create', params=params,
extra_environ=extra_environ)
assert response.json['success'] == True

# check that tag shows up in list
params = '%s=1' % json.dumps({'vocabulary_name': vocab_name})
res = self.app.post('/api/action/tag_list', params=params)
body = json.loads(res.body)
assert_dicts_equal_ignoring_ordering(
json.loads(res.body),
{'help': 'Returns a list of tags',
'success': True,
'result': [tag_name]}
)

# check that invalid vocab name results in a 404
params = '%s=1' % json.dumps({'vocabulary_name': 'invalid-vocab-name'})
res = self.app.post('/api/action/tag_list', params=params, status=404)

def test_07_tag_show(self):
postparams = '%s=1' % json.dumps({'id':'russian'})
res = self.app.post('/api/action/tag_show', params=postparams)
Expand Down
31 changes: 0 additions & 31 deletions ckan/tests/logic/test_tag_vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,3 @@ def test_free_tags_only(self):
assert len(data) == 2
assert ('tags', 1, 'vocabulary_id') in data.keys()
assert ('tags', 1, '__extras') in data.keys()

class TestAPI(WsgiAppCase):
@classmethod
def setup_class(cls):
CreateTestData.create()
cls.vocab = model.Vocabulary('test-vocab')
model.Session.add(cls.vocab)
cls.vocab_tag = model.Tag('vocab-tag', cls.vocab.id)
model.Session.add(cls.vocab_tag)
model.Session.commit()
model.Session.remove()

@classmethod
def teardown_class(cls):
model.repo.rebuild_db()

def test_tag_list(self):
postparams = '%s=1' % json.dumps({'vocabulary_name': self.vocab.name})
res = self.app.post('/api/action/tag_list', params=postparams)
body = json.loads(res.body)
assert_dicts_equal_ignoring_ordering(
json.loads(res.body),
{'help': 'Returns a list of tags',
'success': True,
'result': [self.vocab_tag.name]}
)

def test_tag_list_invalid_vocab_name_404(self):
postparams = '%s=1' % json.dumps({'vocabulary_name': 'invalid-vocab-name'})
res = self.app.post('/api/action/tag_list', params=postparams, status=404)

0 comments on commit bf88c4c

Please sign in to comment.