Commits

Anonymous committed 06c9492

Added support for packages to be specified by IDs in REST interface (fixes #313).

  • Participants
  • Parent commits 170cac0

Comments (0)

Files changed (2)

File ckan/controllers/rest.py

             _dict = changeset.as_dict()
             return self._finish_ok(_dict)
         elif register == u'package' and not subregister:
-            pkg = model.Package.by_name(id)
-            if pkg is None:
+            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?
+            if pkg == None:
                 response.status_int = 404
                 return ''
-
             if not self._check_access(pkg, model.Action.READ):
                 return ''
             _dict = pkg.as_dict()

File ckan/tests/functional/test_rest.py

         assert '"download_url": "http://www.annakarenina.com/download/x=1&y=2"' in res, res
         assert '"id": "%s"' % anna.id in res, res
 
+        # Get package by ID.
+        offset = '/api/rest/package/%s' % anna.id
+        res = self.app.get(offset, status=[200])
+        assert 'annakarenina' in res, res
+        assert '"license_id": "other-open"' in res, str(res)
+        assert 'russian' in res, res
+        assert 'tolstoy' in res, res
+        assert '"extras": {' in res, res
+        assert '"genre": "romantic novel"' in res, res
+        assert '"original media": "book"' in res, res
+        assert 'annakarenina.com/download' in res, res
+        assert '"plain text"' in res, res
+        assert '"Index of the novel"' in res, res
+        assert '"id": "%s"' % anna.id in res, res
+
+
 
     def _test_04_ckan_url(self):
         # NB This only works if run on its own