Skip to content

Commit

Permalink
test whether it works as an alias for resource_id as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Dec 21, 2012
1 parent a5433d2 commit 65a02a3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions ckanext/datastore/tests/test_create.py
Expand Up @@ -453,6 +453,20 @@ def test_create_basic(self):

assert res_dict['success'] is True, res_dict

####### insert with paramter id rather than resource_id which is a shortcut
data8 = {
'id': resource.id,
'records': [{'boo%k': 'warandpeace'}]
}

postparams = '%s=1' % json.dumps(data8)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
res = self.app.post('/api/action/datastore_create', params=postparams,
extra_environ=auth, expect_errors=True)
res_dict = json.loads(res.body)

assert res_dict['success'] is True, res_dict

def test_guess_types(self):
resource = model.Package.get('annakarenina').resources[1]

Expand Down
4 changes: 2 additions & 2 deletions ckanext/datastore/tests/test_delete.py
Expand Up @@ -134,8 +134,8 @@ def test_delete_filters(self):
assert results[0].book == 'annakarenina'
self.Session.remove()

# delete the 'annakarenina' row
data = {'resource_id': resource_id,
# delete the 'annakarenina' row and also only use id
data = {'id': resource_id,
'filters': {'book': 'annakarenina', 'author': 'tolstoy'}}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
Expand Down
12 changes: 12 additions & 0 deletions ckanext/datastore/tests/test_search.py
Expand Up @@ -80,6 +80,18 @@ def test_search_basic(self):
assert result['total'] == len(self.data['records'])
assert result['records'] == self.expected_records, result['records']

# search with parameter id should yield the same results
data = {'id': self.data['resource_id']}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
res = self.app.post('/api/action/datastore_search', params=postparams,
extra_environ=auth)
res_dict = json.loads(res.body)
assert res_dict['success'] is True
result = res_dict['result']
assert result['total'] == len(self.data['records'])
assert result['records'] == self.expected_records, result['records']

def test_search_alias(self):
data = {'resource_id': self.data['aliases']}
postparams = '%s=1' % json.dumps(data)
Expand Down

0 comments on commit 65a02a3

Please sign in to comment.