Skip to content

Commit

Permalink
[1767][tests] update tag vocab WUI tests - remove vocab tags after ea…
Browse files Browse the repository at this point in the history
…ch test
  • Loading branch information
johnglover committed Feb 15, 2012
1 parent 7711876 commit 4f64b25
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ckan/tests/logic/test_tag_vocab.py
Expand Up @@ -225,15 +225,35 @@ def _add_vocab_tag_to_dataset(self, dataset_id, vocab_id, tag_name):
extra_environ={'Authorization': str(self.sysadmin_user.apikey)})
assert json.loads(response.body)['success']

def _remove_vocab_tags(self, dataset_id, vocab_id, tag_name):
params = json.dumps({'id': dataset_id})
response = self.app.post('/api/action/package_show', params=params)
dataset = json.loads(response.body)['result']
dataset['tags'] = [t for t in dataset['tags'] if not t['name'] == tag_name]
params = json.dumps(dataset)
response = self.app.post('/api/action/package_update', params=params,
extra_environ={'Authorization': str(self.sysadmin_user.apikey)})
assert json.loads(response.body)['success']

# TODO: should really be able to delete a tag with tag name and vocab ID,
# update tag_delete then change this
params = json.dumps({'tag_name': tag_name, 'vocabulary_name': TEST_VOCAB_NAME})
extra_environ = {'Authorization' : str(self.sysadmin_user.apikey)}
response = self.app.post('/api/action/tag_delete', params=params,
extra_environ=extra_environ)
assert json.loads(response.body)['success']

def test_01_dataset_view(self):
vocab_id = self._get_vocab_id(TEST_VOCAB_NAME)
self._add_vocab_tag(vocab_id, self.tag1_name)
self._add_vocab_tag_to_dataset(self.dset.id, vocab_id, self.tag1_name)
response = self.app.get(h.url_for(controller='package', action='read', id=self.dset.id))
assert self.tag1_name in response.body
self._remove_vocab_tags(self.dset.id, vocab_id, self.tag1_name)

def test_02_dataset_edit_change_vocab_tag(self):
vocab_id = self._get_vocab_id(TEST_VOCAB_NAME)
self._add_vocab_tag(vocab_id, self.tag1_name)
self._add_vocab_tag(vocab_id, self.tag2_name)
url = h.url_for(controller='package', action='edit', id=self.dset.id)
response = self.app.get(url)
Expand All @@ -243,4 +263,6 @@ def test_02_dataset_edit_change_vocab_tag(self):
response = response.follow()
assert not self.tag1_name in response.body
assert self.tag2_name in response.body
self._remove_vocab_tags(self.dset.id, vocab_id, self.tag1_name)
self._remove_vocab_tags(self.dset.id, vocab_id, self.tag2_name)

0 comments on commit 4f64b25

Please sign in to comment.