[ckan-changes] commit/ckan: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Wed Jul 6 20:17:21 UTC 2011


2 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/a2f704c1b273/
changeset:   a2f704c1b273
branch:      defect-1214-api-improvements
user:        dread
date:        2011-07-06 20:46:36
summary:     [tests]: Added tests for json responses to errors. Removed unneeded group tests and consolidated remaining ones in ckan/tests/api/model/test_group.py.
affected #:  7 files (7.1 KB)

--- a/ckan/controllers/api.py	Tue Jul 05 17:16:08 2011 +0100
+++ b/ckan/controllers/api.py	Wed Jul 06 19:46:36 2011 +0100
@@ -30,10 +30,6 @@
     }
 class ApiController(BaseController):
 
-    content_type_text = 'text/;charset=utf-8'
-    content_type_html = 'text/html;charset=utf-8'
-    content_type_json = 'application/json;charset=utf-8'
-
     def __call__(self, environ, start_response):
         self._identify_user()
         if not self.authorizer.am_authorized(c, model.Action.SITE_READ, model.System):


--- a/ckan/tests/functional/api/base.py	Tue Jul 05 17:16:08 2011 +0100
+++ b/ckan/tests/functional/api/base.py	Wed Jul 06 19:46:36 2011 +0100
@@ -218,6 +218,16 @@
         except ValueError, inst:
             raise Exception, "Couldn't loads string '%s': %s" % (chars, inst)
 
+    def assert_json_response(self, res, expected_in_body=None):
+        content_type = res.header_dict['Content-Type']
+        assert 'application/json' in content_type, content_type
+        res_json = self.loads(res.body)
+        if expected_in_body:
+            assert expected_in_body in res_json or \
+                   expected_in_body in str(res_json), \
+                   'Expected to find %r in JSON response %r' % \
+                   (expected_in_body, res_json)
+
 # Todo: Rename to Version1TestCase.
 class Api1TestCase(ApiTestCase):
 


--- a/ckan/tests/functional/api/model/test_group.py	Tue Jul 05 17:16:08 2011 +0100
+++ b/ckan/tests/functional/api/model/test_group.py	Wed Jul 06 19:46:36 2011 +0100
@@ -1,5 +1,7 @@
 import copy
 
+from ckan import model
+
 from nose.tools import assert_equal 
 
 from ckan.tests.functional.api.base import BaseModelApiTestCase
@@ -29,6 +31,10 @@
         # check group object
         group = self.get_group_by_name(self.testgroupvalues['name'])
         assert group
+        assert group.title == self.testgroupvalues['title'], group
+        assert group.description == self.testgroupvalues['description'], group
+        pkg_names = [pkg.name for pkg in group.packages]
+        assert set(pkg_names) == set(('annakarenina', 'warandpeace')), pkg_names
 
         # check register updated
         res = self.app.get(offset, status=self.STATUS_200_OK)
@@ -53,11 +59,15 @@
         res = self.app.post(offset, params=postparams,
                             status=self.STATUS_409_CONFLICT,
                             extra_environ=self.extra_environ)
+        self.assert_json_response(res, 'Group name already exists')
     
     def test_entity_get_ok(self):
         offset = self.group_offset(self.roger.name)
         res = self.app.get(offset, status=self.STATUS_200_OK)
         self.assert_msg_represents_roger(msg=res.body)
+        assert self.package_ref_from_name('annakarenina') in res, res
+        assert self.group_ref_from_name('roger') in res, res
+        assert not self.package_ref_from_name('warandpeace') in res, res
 
     def test_entity_get_then_post(self):
         # (ticket 662) Ensure an entity you 'get' from a register can be
@@ -70,6 +80,123 @@
                             status=self.STATUS_200_OK,
                             extra_environ=self.extra_environ)
 
+    def test_05_get_group_entity_not_found(self):
+        offset = self.offset('/rest/group/22222')
+        res = self.app.get(offset, status=404)
+        self.assert_json_response(res, 'not found')
+
+    def test_10_edit_group(self):
+        # create a group with testgroupvalues
+        group = model.Group.by_name(self.testgroupvalues['name'])
+        if not group:
+            offset = self.offset('/rest/group')
+            postparams = '%s=1' % self.dumps(self.testgroupvalues)
+            res = self.app.post(offset, params=postparams, status=[201],
+                    extra_environ=self.extra_environ)
+            model.Session.remove()
+            group = model.Group.by_name(self.testgroupvalues['name'])
+        assert group
+        assert len(group.packages) == 2, group.packages
+        user = model.User.by_name(self.user_name)
+        model.setup_default_user_roles(group, [user])
+
+        # edit it
+        group_vals = {'name':u'somethingnew', 'title':u'newtesttitle',
+                      'packages':[u'annakarenina']}
+        offset = self.group_offset(self.testgroupvalues['name'])
+        postparams = '%s=1' % self.dumps(group_vals)
+        res = self.app.post(offset, params=postparams, status=[200],
+                            extra_environ=self.extra_environ)
+        model.Session.remove()
+        group = model.Session.query(model.Group).filter_by(name=group_vals['name']).one()
+        assert group.name == group_vals['name']
+        assert group.title == group_vals['title']
+        assert len(group.packages) == 1, group.packages
+        assert group.packages[0].name == group_vals['packages'][0]
+
+    def test_10_edit_group_name_duplicate(self):
+        # create a group with testgroupvalues
+        if not model.Group.by_name(self.testgroupvalues['name']):
+            rev = model.repo.new_revision()
+            group = model.Group()
+            model.Session.add(group)
+            group.name = self.testgroupvalues['name']
+            model.Session.commit()
+
+            group = model.Group.by_name(self.testgroupvalues['name'])
+            model.setup_default_user_roles(group, [self.user])
+            rev = model.repo.new_revision()
+            model.repo.commit_and_remove()
+        assert model.Group.by_name(self.testgroupvalues['name'])
+        
+        # create a group with name 'dupname'
+        dupname = u'dupname'
+        if not model.Group.by_name(dupname):
+            rev = model.repo.new_revision()
+            group = model.Group()
+            model.Session.add(group)
+            group.name = dupname
+            model.Session.commit()
+        assert model.Group.by_name(dupname)
+
+        # edit first group to have dupname
+        group_vals = {'name':dupname}
+        offset = self.group_offset(self.testgroupvalues['name'])
+        postparams = '%s=1' % self.dumps(group_vals)
+        res = self.app.post(offset, params=postparams, status=[409],
+                            extra_environ=self.extra_environ)
+        self.assert_json_response(res, 'Group name already exists')
+        
+    def test_11_delete_group(self):
+        # Test Groups Entity Delete 200.
+
+        # create a group with testgroupvalues
+        group = model.Group.by_name(self.testgroupvalues['name'])
+        if not group:
+            rev = model.repo.new_revision()
+            group = model.Group()
+            model.Session.add(group)
+            group.name = self.testgroupvalues['name']
+            model.repo.commit_and_remove()
+
+            rev = model.repo.new_revision()
+            group = model.Group.by_name(self.testgroupvalues['name'])
+            model.setup_default_user_roles(group, [self.user])
+            model.repo.commit_and_remove()
+        assert group
+        user = model.User.by_name(self.user_name)
+        model.setup_default_user_roles(group, [user])
+
+        # delete it
+        offset = self.group_offset(self.testgroupvalues['name'])
+        res = self.app.delete(offset, status=[200],
+                extra_environ=self.extra_environ)
+
+        group = model.Group.by_name(self.testgroupvalues['name'])
+        assert group
+        assert group.state == 'deleted', group.state
+
+        res = self.app.get(offset, status=[403])
+        self.assert_json_response(res, 'Access denied')
+        res = self.app.get(offset, status=[200],
+                           extra_environ=self.extra_environ)
+
+    def test_12_get_group_404(self):
+        # Test Package Entity Get 404.
+        assert not model.Session.query(model.Group).filter_by(name=self.testgroupvalues['name']).count()
+        offset = self.group_offset(self.testgroupvalues['name'])
+        res = self.app.get(offset, status=404)
+        self.assert_json_response(res, 'not found')
+
+    def test_13_delete_group_404(self):
+        # Test Packages Entity Delete 404.
+        assert not model.Session.query(model.Group).filter_by(name=self.testgroupvalues['name']).count()
+        offset = self.group_offset(self.testgroupvalues['name'])
+        res = self.app.delete(offset, status=[404],
+                              extra_environ=self.extra_environ)
+        self.assert_json_response(res, 'not found')
+
+
 class TestGroupsVersion1(Version1TestCase, GroupsTestCase): pass
 class TestGroupsVersion2(Version2TestCase, GroupsTestCase): pass
 class TestGroupsUnversioned(UnversionedTestCase, GroupsTestCase): pass


--- a/ckan/tests/functional/api/test_model.py	Tue Jul 05 17:16:08 2011 +0100
+++ b/ckan/tests/functional/api/test_model.py	Wed Jul 06 19:46:36 2011 +0100
@@ -50,12 +50,12 @@
     def test_05_get_group_entity_not_found(self):
         offset = self.offset('/rest/group/22222')
         res = self.app.get(offset, status=404)
-        model.Session.remove()
+        self.assert_json_response(res, 'not found')
 
     def test_05_get_tag_entity_not_found(self):
         offset = self.offset('/rest/tag/doesntexist')
         res = self.app.get(offset, status=404)
-        model.Session.remove()
+        self.assert_json_response(res, 'not found')
 
     def test_06_create_group_entity_ok(self):
         offset = self.offset('/rest/group')
@@ -94,7 +94,7 @@
         postparams = '%s=1' % self.dumps(self.testgroupvalues)
         res = self.app.post(offset, params=postparams, status=[409],
                 extra_environ=self.extra_environ)
-        model.Session.remove()
+        self.assert_json_response(res, 'Group name already exists')
 
     def test_06_rate_package(self):
         # Test Rating Register Post 200.
@@ -139,6 +139,7 @@
         postparams = '%s=1' % self.dumps(rating_opts)
         res = self.app.post(offset, params=postparams, status=[409],
                 extra_environ=self.extra_environ)
+        self.assert_json_response(res, 'rating')
         model.Session.remove()
         pkg = self.get_package_by_name(rating_opts['package'])
         assert pkg
@@ -204,6 +205,7 @@
         postparams = '%s=1' % self.dumps(group_vals)
         res = self.app.post(offset, params=postparams, status=[409],
                             extra_environ=self.extra_environ)
+        self.assert_json_response(res, 'Group name already exists')
         model.Session.remove()
         
     def test_11_delete_group(self):
@@ -236,6 +238,7 @@
         assert group.state == 'deleted', group.state
 
         res = self.app.get(offset, status=[403])
+        self.assert_json_response(res, 'Access denied')
         res = self.app.get(offset, status=[200],
                            extra_environ=self.extra_environ)
 
@@ -246,6 +249,7 @@
         assert not model.Session.query(model.Group).filter_by(name=self.testgroupvalues['name']).count()
         offset = self.offset('/rest/group/%s' % self.testgroupvalues['name'])
         res = self.app.get(offset, status=404)
+        self.assert_json_response(res, 'not found')
         model.Session.remove()
 
     def test_13_delete_group_404(self):
@@ -254,6 +258,7 @@
         offset = self.offset('/rest/group/%s' % self.testgroupvalues['name'])
         res = self.app.delete(offset, status=[404],
                               extra_environ=self.extra_environ)
+        self.assert_json_response(res, 'not found')
 
     def test_14_list_revisions(self):
         # Check mock register behaviour.
@@ -285,6 +290,7 @@
         revision_id = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
         offset = self.offset('/rest/revision/%s' % revision_id)
         res = self.app.get(offset, status=404)
+        self.assert_json_response(res, 'not found')
         model.Session.remove()
 
     def test_16_list_licenses(self):


--- a/ckan/tests/functional/api/test_package_search.py	Tue Jul 05 17:16:08 2011 +0100
+++ b/ckan/tests/functional/api/test_package_search.py	Wed Jul 06 19:46:36 2011 +0100
@@ -179,6 +179,7 @@
     def test_08_uri_qjson_malformed(self):
         offset = self.base_url + '?qjson="q":""' # user forgot the curly braces
         res = self.app.get(offset, status=400)
+        self.assert_json_response(res, 'bum')
         
     def test_08_all_fields(self):
         rating = model.Rating(user_ip_address=u'123.1.2.3',
@@ -211,6 +212,7 @@
         res = self.app.get(offset, status=400)
         assert('boolean' in res.body)
         assert('all_fields' in res.body)
+        self.assert_json_response(res, 'boolean')
 
     def test_09_just_tags(self):
         offset = self.base_url + '?tags=russian&all_fields=1'
@@ -257,6 +259,7 @@
         res = self.app.get(offset, status=400)
         assert('integer' in res.body)
         assert('offset' in res.body)
+        self.assert_json_response(res, 'integer')
 
     def test_12_all_packages_qjson(self):
         query = {'q': ''}


--- a/ckan/tests/functional/api/test_resource_search.py	Tue Jul 05 17:16:08 2011 +0100
+++ b/ckan/tests/functional/api/test_resource_search.py	Wed Jul 06 19:46:36 2011 +0100
@@ -70,6 +70,7 @@
     def test_04_bad_option(self):
         offset = self.base_url + '?random=option'
         result = self.app.get(offset, status=400)
+        self.assert_json_response(result, 'bad request')
 
     def test_05_options(self):
         offset = self.base_url + '?url=site&all_fields=1&callback=mycallback'


--- a/ckan/tests/functional/api/test_revision_search.py	Tue Jul 05 17:16:08 2011 +0100
+++ b/ckan/tests/functional/api/test_revision_search.py	Wed Jul 06 19:46:36 2011 +0100
@@ -14,10 +14,14 @@
     def test_12_search_revision_basic(self):
         offset = self.offset('/search/revision')
         # Check bad request.
-        self.app.get(offset, status=400)
-        self.app.get(offset+'?since_rev=2010-01-01T00:00:00', status=400)
-        self.app.get(offset+'?since_revision=2010-01-01T00:00:00', status=400)
-        self.app.get(offset+'?since_id=', status=400)
+        res = self.app.get(offset, status=400)
+        self.assert_json_response(res, 'bad request')
+        res = self.app.get(offset+'?since_rev=2010-01-01T00:00:00', status=400)
+        self.assert_json_response(res, 'bad request')
+        res = self.app.get(offset+'?since_revision=2010-01-01T00:00:00', status=400)
+        self.assert_json_response(res, 'bad request')
+        res = self.app.get(offset+'?since_id=', status=400)
+        self.assert_json_response(res, 'bad request')
 
     def test_12_search_revision_since_rev(self):
         offset = self.offset('/search/revision')
@@ -54,8 +58,9 @@
         assert res_list == [], res_list
         # Check bad format.
         params = "?since_time=2010-04-31T23:45"
-        self.app.get(offset+params, status=400)
+        res = self.app.get(offset+params, status=400)
+        self.assert_json_response(res, 'bad request')
 
 
-class TestPackageSearchApi1(Api1TestCase, RevisionSearchApiTestCase): pass
-class TestPackageSearchApi2(Api2TestCase, RevisionSearchApiTestCase): pass
+class TestRevisionSearchApi1(Api1TestCase, RevisionSearchApiTestCase): pass
+class TestRevisionSearchApi2(Api2TestCase, RevisionSearchApiTestCase): pass


http://bitbucket.org/okfn/ckan/changeset/0a533a8da3df/
changeset:   0a533a8da3df
branch:      defect-1214-api-improvements
user:        dread
date:        2011-07-06 21:58:59
summary:     [controllers]: Complete work to return Content-Type application/json for all API errors.
affected #:  6 files (8.5 KB)

--- a/ckan/controllers/api.py	Wed Jul 06 19:46:36 2011 +0100
+++ b/ckan/controllers/api.py	Wed Jul 06 20:58:59 2011 +0100
@@ -41,6 +41,8 @@
             start_response(body, response.headers.items())
             return [response_msg]
         else:
+            # avoid status_code_redirect intercepting error responses
+            environ['pylons.status_code_redirect'] = True
             return BaseController.__call__(self, environ, start_response)
 
     def _finish(self, status_int, response_data=None,
@@ -102,6 +104,14 @@
                             response_data=response_data,
                             content_type='json')
 
+    def _finish_bad_request(self, extra_msg=None):
+        response_data = _('Bad request')
+        if extra_msg:
+            response_data = '%s - %s' % (response_data, extra_msg)
+        return self._finish(status_int=400,
+                            response_data=response_data,
+                            content_type='json')
+
     def _wrap_jsonp(self, callback, response_msg):
         return '%s(%s);' % (callback, response_msg)
 
@@ -136,8 +146,8 @@
         if not action:
             action = action_map.get(register)
         if not action:
-            response.status_int = 400
-            return gettext('Cannot list entity of this type: %s') % register
+            return self._finish_bad_request(
+                gettext('Cannot list entity of this type: %s') % register)
         try:
             return self._finish_ok(action(context))
         except NotFound, e:
@@ -147,7 +157,6 @@
             return self._finish_not_authz()
 
     def show(self, ver=None, register=None, subregister=None, id=None, id2=None):
-
         action_map = {
             'revision': get.revision_show,
             'group': get.group_show_rest,
@@ -167,8 +176,8 @@
         if not action:
             action = action_map.get(register)
         if not action:
-            response.status_int = 400
-            return gettext('Cannot read entity of this type: %s') % register
+            return self._finish_bad_request(
+                gettext('Cannot read entity of this type: %s') % register)
         try:
             
             return self._finish_ok(action(context))
@@ -201,15 +210,16 @@
         try:
             request_data = self._get_request_data()
         except ValueError, inst:
-            response.status_int = 400
-            return gettext('JSON Error: %s') % str(inst)
+            return self._finish_bad_request(
+                gettext('JSON Error: %s') % str(inst))
 
         action = action_map.get((register, subregister)) 
         if not action:
             action = action_map.get(register)
         if not action:
-            response.status_int = 400
-            return gettext('Cannot create new entity of this type: %s %s') % (register, subregister)
+            return self._finish_bad_request(
+                gettext('Cannot create new entity of this type: %s %s') % \
+                (register, subregister))
         try:
             response_data = action(request_data, context)
             location = None
@@ -247,15 +257,15 @@
         try:
             request_data = self._get_request_data()
         except ValueError, inst:
-            response.status_int = 400
-            return gettext('JSON Error: %s') % str(inst)
+            return self._finish_bad_request(
+                gettext('JSON Error: %s') % str(inst))
         action = action_map.get((register, subregister)) 
         if not action:
             action = action_map.get(register)
         if not action:
-            response.status_int = 400
-            return gettext('Cannot update entity of this type: %s') % \
-                    register.encode('utf-8')
+            return self._finish_bad_request(
+                gettext('Cannot update entity of this type: %s') % \
+                    register.encode('utf-8'))
         try:
             response_data = action(request_data, context)
             return self._finish_ok(response_data)
@@ -290,8 +300,9 @@
         if not action:
             action = action_map.get(register)
         if not action:
-            response.status_int = 400
-            return gettext('Cannot delete entity of this type: %s %s') % (register, subregister or '')
+            return self._finish_bad_request(
+                gettext('Cannot delete entity of this type: %s %s') %\
+                (register, subregister or ''))
         try:
             response_data = action(context)
             return self._finish_ok(response_data)
@@ -311,29 +322,31 @@
             since_time = None
             if request.params.has_key('since_id'):
                 id = request.params['since_id']
+                if not id:
+                    return self._finish_bad_request(
+                        gettext(u'No revision specified'))
                 rev = model.Session.query(model.Revision).get(id)
                 if rev is None:
-                    response.status_int = 400
-                    return gettext(u'There is no revision with id: %s') % id
+                    return self._finish_not_found(
+                        gettext(u'There is no revision with id: %s') % id)
                 since_time = rev.timestamp
             elif request.params.has_key('since_time'):
                 since_time_str = request.params['since_time']
                 try:
                     since_time = model.strptimestamp(since_time_str)
                 except ValueError, inst:
-                    response.status_int = 400
-                    return 'ValueError: %s' % inst
+                    return self._finish_bad_request('ValueError: %s' % inst)
             else:
-                response.status_int = 400
-                return gettext("Missing search term ('since_id=UUID' or 'since_time=TIMESTAMP')")
+                return self._finish_bad_request(
+                    gettext("Missing search term ('since_id=UUID' or 'since_time=TIMESTAMP')"))
             revs = model.Session.query(model.Revision).filter(model.Revision.timestamp>since_time)
             return self._finish_ok([rev.id for rev in revs])
         elif register == 'package' or register == 'resource':
             try:
                 params = self._get_search_params(request.params)
             except ValueError, e:
-                response.status_int = 400
-                return gettext('Could not read parameters: %r' % e)
+                return self._finish_bad_request(
+                    gettext('Could not read parameters: %r' % e))
             options = QueryOptions()
             for k, v in params.items():
                 if (k in DEFAULT_OPTIONS.keys()):
@@ -369,11 +382,11 @@
                 return self._finish_ok(results)
             except SearchError, e:
                 log.exception(e)
-                response.status_int = 400
-                return gettext('Bad search option: %s') % e
+                return self._finish_bad_request(
+                    gettext('Bad search option: %s') % e)
         else:
-            response.status_int = 404
-            return gettext('Unknown register: %s') % register
+            return self._finish_not_found(
+                gettext('Unknown register: %s') % register)
 
     @classmethod
     def _get_search_params(cls, request_params):


--- a/ckan/tests/functional/api/model/test_group.py	Wed Jul 06 19:46:36 2011 +0100
+++ b/ckan/tests/functional/api/model/test_group.py	Wed Jul 06 20:58:59 2011 +0100
@@ -83,7 +83,7 @@
     def test_05_get_group_entity_not_found(self):
         offset = self.offset('/rest/group/22222')
         res = self.app.get(offset, status=404)
-        self.assert_json_response(res, 'not found')
+        self.assert_json_response(res, 'Not found')
 
     def test_10_edit_group(self):
         # create a group with testgroupvalues
@@ -186,7 +186,7 @@
         assert not model.Session.query(model.Group).filter_by(name=self.testgroupvalues['name']).count()
         offset = self.group_offset(self.testgroupvalues['name'])
         res = self.app.get(offset, status=404)
-        self.assert_json_response(res, 'not found')
+        self.assert_json_response(res, 'Not found')
 
     def test_13_delete_group_404(self):
         # Test Packages Entity Delete 404.


--- a/ckan/tests/functional/api/test_model.py	Wed Jul 06 19:46:36 2011 +0100
+++ b/ckan/tests/functional/api/test_model.py	Wed Jul 06 20:58:59 2011 +0100
@@ -28,73 +28,16 @@
         assert 'russian' in res, res
         assert 'tolstoy' in res, res
 
-    def test_02_get_group_register_ok(self):
-        offset = self.offset('/rest/group')
-        res = self.app.get(offset, status=[200])
-        assert self.group_ref_from_name('david') in res, res
-        assert self.group_ref_from_name('roger') in res, res
-
     def test_04_get_tag(self):
         offset = self.offset('/rest/tag/tolstoy')
         res = self.app.get(offset, status=[200])
         assert 'annakarenina' in res, res
         assert not 'warandpeace' in res, res
-
-    def test_04_get_group(self):
-        offset = self.offset('/rest/group/roger')
-        res = self.app.get(offset, status=[200])
-        assert self.package_ref_from_name('annakarenina') in res, res
-        assert self.group_ref_from_name('roger') in res, res
-        assert not self.package_ref_from_name('warandpeace') in res, res
         
-    def test_05_get_group_entity_not_found(self):
-        offset = self.offset('/rest/group/22222')
-        res = self.app.get(offset, status=404)
-        self.assert_json_response(res, 'not found')
-
     def test_05_get_tag_entity_not_found(self):
         offset = self.offset('/rest/tag/doesntexist')
         res = self.app.get(offset, status=404)
-        self.assert_json_response(res, 'not found')
-
-    def test_06_create_group_entity_ok(self):
-        offset = self.offset('/rest/group')
-        postparams = '%s=1' % self.dumps(self.testgroupvalues)
-        res = self.app.post(offset, params=postparams, status=201,
-                extra_environ=self.extra_environ)
-        model.Session.remove()
-        rev = model.repo.new_revision()
-        group = model.Group.by_name(self.testgroupvalues['name'])
-        assert group
-        model.setup_default_user_roles(group, [self.user])
-        model.repo.commit_and_remove()
-        group = model.Group.by_name(self.testgroupvalues['name'])
-        assert group
-        assert group.title == self.testgroupvalues['title'], group
-        assert group.description == self.testgroupvalues['description'], group
-        assert len(group.packages) == 2, len(group.packages)
-        anna = self.anna
-        warandpeace = self.war
-        assert anna in group.packages
-        assert warandpeace in group.packages
-
-        # Check group packages.
-        offset = self.offset('/rest/group/%s' % self.testgroupvalues['name'])
-        res = self.app.get(offset, status=[200])
-        assert self.testgroupvalues['name'] in res, res
-        assert self.package_ref_from_name(self.testgroupvalues['packages'][0]) in res, res
-        ref = self.package_ref_from_name(self.testgroupvalues['packages'][0])
-        assert ref in res, res
-        ref = self.package_ref_from_name(self.testgroupvalues['packages'][1])
-        assert ref in res, res
-        model.Session.remove()
-        
-        # Check create group entity conflict.
-        offset = self.offset('/rest/group')
-        postparams = '%s=1' % self.dumps(self.testgroupvalues)
-        res = self.app.post(offset, params=postparams, status=[409],
-                extra_environ=self.extra_environ)
-        self.assert_json_response(res, 'Group name already exists')
+        self.assert_json_response(res, 'Not found')
 
     def test_06_rate_package(self):
         # Test Rating Register Post 200.
@@ -145,121 +88,6 @@
         assert pkg
         assert len(pkg.ratings) == 0
 
-    def test_10_edit_group(self):
-        # create a group with testgroupvalues
-        group = model.Group.by_name(self.testgroupvalues['name'])
-        if not group:
-            offset = self.offset('/rest/group')
-            postparams = '%s=1' % self.dumps(self.testgroupvalues)
-            res = self.app.post(offset, params=postparams, status=[201],
-                    extra_environ=self.extra_environ)
-            model.Session.remove()
-            group = model.Group.by_name(self.testgroupvalues['name'])
-        assert group
-        assert len(group.packages) == 2, group.packages
-        user = model.User.by_name(self.user_name)
-        model.setup_default_user_roles(group, [user])
-
-        # edit it
-        group_vals = {'name':u'somethingnew', 'title':u'newtesttitle',
-                      'packages':[u'annakarenina']}
-        offset = self.offset('/rest/group/%s' % self.testgroupvalues['name'])
-        postparams = '%s=1' % self.dumps(group_vals)
-        res = self.app.post(offset, params=postparams, status=[200],
-                            extra_environ=self.extra_environ)
-        model.Session.remove()
-        group = model.Session.query(model.Group).filter_by(name=group_vals['name']).one()
-        assert group.name == group_vals['name']
-        assert group.title == group_vals['title']
-        assert len(group.packages) == 1, group.packages
-        assert group.packages[0].name == group_vals['packages'][0]
-
-    def test_10_edit_group_name_duplicate(self):
-        # create a group with testgroupvalues
-        if not model.Group.by_name(self.testgroupvalues['name']):
-            rev = model.repo.new_revision()
-            group = model.Group()
-            model.Session.add(group)
-            group.name = self.testgroupvalues['name']
-            model.Session.commit()
-
-            group = model.Group.by_name(self.testgroupvalues['name'])
-            model.setup_default_user_roles(group, [self.user])
-            rev = model.repo.new_revision()
-            model.repo.commit_and_remove()
-        assert model.Group.by_name(self.testgroupvalues['name'])
-        
-        # create a group with name 'dupname'
-        dupname = u'dupname'
-        if not model.Group.by_name(dupname):
-            rev = model.repo.new_revision()
-            group = model.Group()
-            model.Session.add(group)
-            group.name = dupname
-            model.Session.commit()
-        assert model.Group.by_name(dupname)
-
-        # edit first group to have dupname
-        group_vals = {'name':dupname}
-        offset = self.offset('/rest/group/%s' % self.testgroupvalues['name'])
-        postparams = '%s=1' % self.dumps(group_vals)
-        res = self.app.post(offset, params=postparams, status=[409],
-                            extra_environ=self.extra_environ)
-        self.assert_json_response(res, 'Group name already exists')
-        model.Session.remove()
-        
-    def test_11_delete_group(self):
-        # Test Groups Entity Delete 200.
-
-        # create a group with testgroupvalues
-        group = model.Group.by_name(self.testgroupvalues['name'])
-        if not group:
-            rev = model.repo.new_revision()
-            group = model.Group()
-            model.Session.add(group)
-            group.name = self.testgroupvalues['name']
-            model.repo.commit_and_remove()
-
-            rev = model.repo.new_revision()
-            group = model.Group.by_name(self.testgroupvalues['name'])
-            model.setup_default_user_roles(group, [self.user])
-            model.repo.commit_and_remove()
-        assert group
-        user = model.User.by_name(self.user_name)
-        model.setup_default_user_roles(group, [user])
-
-        # delete it
-        offset = self.offset('/rest/group/%s' % self.testgroupvalues['name'])
-        res = self.app.delete(offset, status=[200],
-                extra_environ=self.extra_environ)
-
-        group = model.Group.by_name(self.testgroupvalues['name'])
-        assert group
-        assert group.state == 'deleted', group.state
-
-        res = self.app.get(offset, status=[403])
-        self.assert_json_response(res, 'Access denied')
-        res = self.app.get(offset, status=[200],
-                           extra_environ=self.extra_environ)
-
-        model.Session.remove()
-
-    def test_12_get_group_404(self):
-        # Test Package Entity Get 404.
-        assert not model.Session.query(model.Group).filter_by(name=self.testgroupvalues['name']).count()
-        offset = self.offset('/rest/group/%s' % self.testgroupvalues['name'])
-        res = self.app.get(offset, status=404)
-        self.assert_json_response(res, 'not found')
-        model.Session.remove()
-
-    def test_13_delete_group_404(self):
-        # Test Packages Entity Delete 404.
-        assert not model.Session.query(model.Group).filter_by(name=self.testgroupvalues['name']).count()
-        offset = self.offset('/rest/group/%s' % self.testgroupvalues['name'])
-        res = self.app.delete(offset, status=[404],
-                              extra_environ=self.extra_environ)
-        self.assert_json_response(res, 'not found')
-
     def test_14_list_revisions(self):
         # Check mock register behaviour.
         offset = self.offset('/rest/revision')
@@ -290,7 +118,7 @@
         revision_id = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
         offset = self.offset('/rest/revision/%s' % revision_id)
         res = self.app.get(offset, status=404)
-        self.assert_json_response(res, 'not found')
+        self.assert_json_response(res, 'Not found')
         model.Session.remove()
 
     def test_16_list_licenses(self):


--- a/ckan/tests/functional/api/test_package_search.py	Wed Jul 06 19:46:36 2011 +0100
+++ b/ckan/tests/functional/api/test_package_search.py	Wed Jul 06 20:58:59 2011 +0100
@@ -179,7 +179,7 @@
     def test_08_uri_qjson_malformed(self):
         offset = self.base_url + '?qjson="q":""' # user forgot the curly braces
         res = self.app.get(offset, status=400)
-        self.assert_json_response(res, 'bum')
+        self.assert_json_response(res, 'Bad request - Could not read parameters')
         
     def test_08_all_fields(self):
         rating = model.Rating(user_ip_address=u'123.1.2.3',


--- a/ckan/tests/functional/api/test_resource_search.py	Wed Jul 06 19:46:36 2011 +0100
+++ b/ckan/tests/functional/api/test_resource_search.py	Wed Jul 06 20:58:59 2011 +0100
@@ -70,7 +70,7 @@
     def test_04_bad_option(self):
         offset = self.base_url + '?random=option'
         result = self.app.get(offset, status=400)
-        self.assert_json_response(result, 'bad request')
+        self.assert_json_response(result, 'Bad request - Bad search option')
 
     def test_05_options(self):
         offset = self.base_url + '?url=site&all_fields=1&callback=mycallback'


--- a/ckan/tests/functional/api/test_revision_search.py	Wed Jul 06 19:46:36 2011 +0100
+++ b/ckan/tests/functional/api/test_revision_search.py	Wed Jul 06 20:58:59 2011 +0100
@@ -11,17 +11,19 @@
     def teardown_class(self):
         model.repo.rebuild_db()
 
-    def test_12_search_revision_basic(self):
+    def test_12_search_revision_bad_requests(self):
         offset = self.offset('/search/revision')
         # Check bad request.
         res = self.app.get(offset, status=400)
-        self.assert_json_response(res, 'bad request')
+        self.assert_json_response(res, 'Bad request - Missing search term')
         res = self.app.get(offset+'?since_rev=2010-01-01T00:00:00', status=400)
-        self.assert_json_response(res, 'bad request')
+        self.assert_json_response(res, 'Bad request - Missing search term')
         res = self.app.get(offset+'?since_revision=2010-01-01T00:00:00', status=400)
-        self.assert_json_response(res, 'bad request')
+        self.assert_json_response(res, 'Bad request - Missing search term')
         res = self.app.get(offset+'?since_id=', status=400)
-        self.assert_json_response(res, 'bad request')
+        self.assert_json_response(res, 'Bad request - No revision specified')
+        res = self.app.get(offset+'?since_id=1234', status=404)
+        self.assert_json_response(res, 'Not found - There is no revision')
 
     def test_12_search_revision_since_rev(self):
         offset = self.offset('/search/revision')
@@ -59,7 +61,7 @@
         # Check bad format.
         params = "?since_time=2010-04-31T23:45"
         res = self.app.get(offset+params, status=400)
-        self.assert_json_response(res, 'bad request')
+        self.assert_json_response(res, 'Bad request - ValueError: day is out of range for month')
 
 
 class TestRevisionSearchApi1(Api1TestCase, RevisionSearchApiTestCase): pass

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list