Permalink
Browse files

Small CL to change the way format is used for package versions.

Adds tests to confirm new behaviour and old.

R=rnystrom@google.com

Review URL: https://chromiumcodereview.appspot.com//104503011
  • Loading branch information...
1 parent 74179f8 commit 8892da8bab65c6b308892ab85b33ab1fbcd6762f @amouravski amouravski committed Dec 19, 2013
Showing with 29 additions and 3 deletions.
  1. +6 −3 app/handlers/api/package_versions.py
  2. +23 −0 test/test_handlers/api/test_package_versions.py
@@ -164,10 +164,13 @@ def upload(self, file, key, acl=None, policy=None, signature=None,
return ""
@handlers.api(2)
- def show(self, package_id, id, format):
+ def show(self, package_id, id, format=None):
"""Retrieve the document describing a package version."""
- # The mapper thinks the final version digit is the format.
- id = id + '.' + format
+ # The mapper expects anything past a period to be the format of the
+ # document, which is fine for "index.html" or "packages.json" but not
+ # for "1.2.3". It thinks "3" is the format, which is wrong, so we add it
+ # on here.
+ if format: id = id + '.' + format
return json.dumps(
handlers.request().package_version(id).as_dict(full=True))
@@ -253,6 +253,29 @@ def test_api_uploader_gets_dartdoc_form_for_nonexistent_package(self):
status=404)
self.assert_json_error(response)
+ def test_api_malformed_package_version(self):
+ version = self.package_version(self.package, '1.2.3')
+ version.put()
+
+ response = self.testapp.get(
+ '/api/packages/test-package/versions/banana', status=400)
+ self.assertEqual(response.headers['Content-Type'], 'application/json')
+ self.assertEqual(json.loads(response.body), {
+ 'error': {'message': '"banana" is not a valid semantic version.'}
+ })
+
+ def test_api_no_such_package_version(self):
+ version = self.package_version(self.package, '1.2.3')
+ version.put()
+
+ response = self.testapp.get(
+ '/api/packages/test-package/versions/2.0.0', status=404)
+ self.assertEqual(response.headers['Content-Type'], 'application/json')
+ self.assertEqual(json.loads(response.body), {
+ 'error':
+ {'message': '"test-package" version 2.0.0 doesn\'t exist.'}
+ })
+
def post_package_version(self, version, name='test-package'):
response = self.create_package(self.upload_archive(name, version))
self.assert_json_success(response)

0 comments on commit 8892da8

Please sign in to comment.