Skip to content

Commit

Permalink
Move test_search_by_modified into test_search
Browse files Browse the repository at this point in the history
  • Loading branch information
johnglover committed Aug 29, 2013
1 parent 4a9888a commit bdf7a1b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 49 deletions.
40 changes: 0 additions & 40 deletions tests/test_api.py
Expand Up @@ -208,46 +208,6 @@ def test_contact_name_required(self):
extra_environ={'Authorization': 'ectest'},
status=409)

def test_search_by_modified(self):
# create a new dataset
dataset = {'name': u'new-test-dataset',
'title': u'title',
'description': u'description',
'url': u'http://datahub.io',
'published_by': u'david',
'status': u'http://purl.org/adms/status/Completed'}
self.app.post('/api/action/package_create',
params=json.dumps(dataset),
extra_environ={'Authorization': 'ectest'})

# check that new dataset is first result when sorting by
# modified_date (should default to same value as CKAN's
# metadata_modified field)
search_query = {'sort': 'modified_date desc'}
response = self.app.post('/api/action/package_search',
params=json.dumps(search_query),
extra_environ={'Authorization': 'ectest'})
result = json.loads(response.body)['result']
assert result['count'] > 1
assert result['results'][0]['name'] == dataset['name']

# set the modified_date field to a time before the rest
# of the datasets were created
dataset['modified_date'] = u'2013-01-01'
self.app.post('/api/action/package_update',
params=json.dumps(dataset),
extra_environ={'Authorization': 'ectest'})

# check that dataset is now the first result when sorting
# by modified_date (ascending)
search_query = {'sort': 'modified_date asc'}
response = self.app.post('/api/action/package_search',
params=json.dumps(search_query),
extra_environ={'Authorization': 'ectest'})
result = json.loads(response.body)['result']
assert result['count'] > 1
assert result['results'][0]['name'] == dataset['name']

def test_blank_license_allowed(self):
dataset_json = json.dumps({
'name': u'test-blank-license-string',
Expand Down
60 changes: 51 additions & 9 deletions tests/test_search.py
Expand Up @@ -3,10 +3,7 @@
**Notice**: Vim users please check the tests README file before
editing this file.
'''
try:
import json
except ImportError:
import simplejson as json
import json

import ckan.model as model
import ckan.lib.create_test_data
Expand All @@ -30,14 +27,19 @@ def setup_class(cls):
_create_test_data.create('publisher')

cls.sysadmin_user = model.User.get('testsysadmin')
cls.extra_environ = {'Authorization': str(cls.sysadmin_user.apikey)}
cls.sysadmin_env = {'Authorization': str(cls.sysadmin_user.apikey)}

model.repo.new_revision()

usr = model.User(name="ectest", apikey="ectest", password=u'ectest')
model.Session.add(usr)
model.Session.commit()

g = model.Group.get('david')
g.type = 'organization'
model.Session.add(g)
mu = model.Member(table_id=cls.sysadmin_user.id,
table_name='user', group=g)

mu = model.Member(table_id=usr.id, table_name='user', group=g)
model.Session.add(mu)
model.Session.commit()

Expand All @@ -62,7 +64,7 @@ def setup_class(cls):
})
response = cls.app.post('/api/action/term_translation_update',
params=params,
extra_environ=cls.extra_environ)
extra_environ=cls.sysadmin_env)
assert json.loads(response.body)['success']

@classmethod
Expand Down Expand Up @@ -140,7 +142,7 @@ def test_facets(self):

params = json.dumps(dataset)
response = self.app.post('/api/action/package_update', params=params,
extra_environ=self.extra_environ)
extra_environ={'Authorization': 'ectest'})

params = json.dumps({
'q': u'warandpeace',
Expand All @@ -152,3 +154,43 @@ def test_facets(self):

assert geo_facets[0]['count'] == 1
assert geo_facets[0]['name'] == 'uk'

def test_search_by_modified(self):
# create a new dataset
dataset = {'name': u'new-test-dataset',
'title': u'title',
'description': u'description',
'url': u'http://datahub.io',
'published_by': u'david',
'status': u'http://purl.org/adms/status/Completed'}
self.app.post('/api/action/package_create',
params=json.dumps(dataset),
extra_environ={'Authorization': 'ectest'})

# check that new dataset is first result when sorting by
# modified_date (should default to same value as CKAN's
# metadata_modified field)
search_query = {'sort': 'modified_date desc'}
response = self.app.post('/api/action/package_search',
params=json.dumps(search_query),
extra_environ={'Authorization': 'ectest'})
result = json.loads(response.body)['result']
assert result['count'] > 1
assert result['results'][0]['name'] == dataset['name']

# set the modified_date field to a time before the rest
# of the datasets were created
dataset['modified_date'] = u'2013-01-01'
self.app.post('/api/action/package_update',
params=json.dumps(dataset),
extra_environ={'Authorization': 'ectest'})

# check that dataset is now the first result when sorting
# by modified_date (ascending)
search_query = {'sort': 'modified_date asc'}
response = self.app.post('/api/action/package_search',
params=json.dumps(search_query),
extra_environ={'Authorization': 'ectest'})
result = json.loads(response.body)['result']
assert result['count'] > 1
assert result['results'][0]['name'] == dataset['name']

0 comments on commit bdf7a1b

Please sign in to comment.