Anonymous avatar Anonymous committed 16b227a

Changed API v2 to reference packages of a revision with package ids (was package names).

Comments (0)

Files changed (4)

ckan/controllers/rest.py

     def _list_package_refs(self, packages):
         raise Exception, "Method not implemented."
 
+    def _get_pkg(self, id):
+        pkg = model.Session.query(model.Package).get(id)
+        if pkg == None:
+            pkg = model.Package.by_name(id)
+            # Todo: Make sure package names can't be changed to look like package IDs?
+        return pkg
+
     def list(self, register, subregister=None, id=None):
         if register == 'revision':
             revs = model.Session.query(model.Revision).all()
             response.status_int = 400
             return ''
 
-    def _get_pkg(self, id):
-        pkg = model.Session.query(model.Package).get(id)
-        if pkg == None:
-            pkg = model.Package.by_name(id)
-            # Todo: Make sure package names can't be changed to look like package IDs?
-        return pkg
-
     def show(self, register, id, subregister=None, id2=None):
         if register == u'revision':
             # Todo: Implement access control for revisions.
                 'timestamp': model.strftimestamp(rev.timestamp),
                 'author': rev.author,
                 'message': rev.message,
-                'packages': [p.name for p in rev.packages],
+                'packages': self._list_package_refs(rev.packages),
             }
             return self._finish_ok(response_data)
         elif register == u'changeset':

ckan/tests/functional/test_rest.py

 class RestTestCase(TestController):
 
     api_version = ''
+    fixture_package_name = u'--'
 
 #    @classmethod
 #    def setup_class(self):
             pass
         model.Session.remove()
         CreateTestData.create()
-        model.Session.add(model.Package(name=u'--'))
+        model.Session.add(model.Package(name=self.fixture_package_name))
         rev = model.repo.new_revision()
         model.repo.commit_and_remove()
         from ckan.model.changeset import ChangesetRegister
 
     def test_01_entity_put_noauth(self):
         # Test Packages Entity Put 401.
-        offset = '/api/rest/package/%s' % u'--'
+        offset = '/api/rest/package/%s' % self.fixture_package_name
         postparams = '%s=1' % json.dumps(self.testpackagevalues)
         res = self.app.post(offset, params=postparams, status=ACCESS_DENIED)
 
 
     def test_14_get_revision(self):
         rev = model.Revision.youngest(model.Session)
-        offset = '/api/rest/revision/%s' % rev.id
+        offset = self.offset('/rest/revision/%s' % rev.id)
         res = self.app.get(offset, status=[200])
         res_dict = json.loads(res.body)
         assert rev.id == res_dict['id']
         assert rev.timestamp.isoformat() == res_dict['timestamp'], (rev.timestamp.isoformat(), res_dict['timestamp'])
         assert 'packages' in res_dict
-        assert isinstance(res_dict['packages'], list)
-        assert len(res_dict['packages']) != 0, "List of package names is empty: %s" % res_dict['packages']
+        self.assert_revision_packages(res_dict['packages'])
+
+    def assert_revision_packages(self, packages):
+        raise Exception, "Method not implemented."
 
     def test_14_get_revision_404(self):
         revision_id = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
         assert self.anna.name in res, res
         assert self.war.name in res, res
 
-        
+    def assert_revision_packages(self, packages):
+        assert isinstance(packages, list)
+        assert len(packages) != 0, "Revision packages is empty: %s" % packages
+        assert self.fixture_package_name in packages, packages
+
 
 class TestRelationships(TestController):
     @classmethod

ckan/tests/functional/test_rest2.py

         assert self.anna.id in res, res
         assert self.war.id in res, res
 
+    def assert_revision_packages(self, packages):
+        assert isinstance(packages, list)
+        assert len(packages) != 0, "Revision packages is empty: %s" % packages
+        package = self.get_package_by_name(self.fixture_package_name)
+        assert package.id in packages, (package.id, packages)
+
 | Key                   |    Value      | Example                                             |  Notes                           |
 +=======================+===============+=====================================================+==================================+ 
 | since_time            | Date-Time     | since_time=2010-05-05T19:42:45.854533               | The time can be less precisely   |
-|                       |               |                                                     | stated (e.g. 2010, or 2010-05, or|
-|                       |               |                                                     | 2010-05-05, and so on).          |
+|                       |               |                                                     | stated (e.g 2010-05-05).          |
 +-----------------------+---------------+-----------------------------------------------------+----------------------------------+
 | since_id              | Uuid          | since_id=6c9f32ef-1f93-4b2f-891b-fd01924ebe08       | The stated id will not be        |
 |                       |               |                                                     | included in the results.         |
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.