diff --git a/photoapp/api.py b/photoapp/api.py index adad605..56c7b92 100644 --- a/photoapp/api.py +++ b/photoapp/api.py @@ -69,7 +69,7 @@ class PhotosApiV1Upload(object): if type(files) != list: files = [files] if set([file.filename for file in files]) != set(meta["files"].keys()): - raise cherrypy.HTTPError(400, f"file metadata missing") + raise cherrypy.HTTPError(400, "file metadata missing") dupes = db.query(Photo).filter(Photo.hash.in_([f["hash"] for f in meta["files"].values()])).first() if dupes: @@ -270,14 +270,14 @@ class PhotosApiV1PhotoTags(object): def DELETE(self, uuid): # deleting tag tag = db.query(Tag).filter(Tag.uuid == uuid).first() - db.query(TagItem).fitler(TagItem.tag_id == tag.id).delete() + db.query(TagItem).filter(TagItem.tag_id == tag.id).delete() db.delete(tag) db.commit() return {} def POST(self): # creating tag tagdata = json.loads(cherrypy.request.body.read()) - tagname = tagdata.get("name") + tagname = tagdata["name"] db.add(Tag(name=tagname, title=tagdata.get("title", None) or tagname.capitalize(), description=tagdata.get("description", None), diff --git a/photoapp/cli.py b/photoapp/cli.py index 0ec9417..d31975b 100644 --- a/photoapp/cli.py +++ b/photoapp/cli.py @@ -124,7 +124,7 @@ class PhotoApiClient(object): def create_tag(self, name, title, description): return self.post("tags", json={"name": name, "title": title, "description": description}) - def list_tags(self, name): + def list_tags(self, name=None): params = {} if name: params["name"] = name diff --git a/tests/lib.py b/tests/lib.py index dfc8262..d9ade8b 100644 --- a/tests/lib.py +++ b/tests/lib.py @@ -1,4 +1,5 @@ import os +import json import tempfile import cherrypy @@ -46,6 +47,9 @@ class PhotolibTest(helper.CPWebCase): 'tools.auth_basic.on': False, }) + def setUp(self): + self.do_gc_test = False + def getHeader(self, name): for key, value in self.headers: if name == key: @@ -55,3 +59,9 @@ class PhotolibTest(helper.CPWebCase): header = self.getHeader(name) assert header is not None, "Header '{}' not present".format(name) assert header.endswith(value), "Needed to end with '{}' but got '{}'".format(value, header) + + def postJSON(self, path, body): + body = json.dumps(body) + return self.getPage(path, method="POST", body=body, + headers=[('Content-Type', 'application/json'), + ('Content-Length', str(len(body)))]) diff --git a/tests/test_misc.py b/tests/test_misc.py index 6017a43..fc9e645 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1,9 +1,8 @@ -import pytest -import cherrypy -from tests.lib import * # NOQA - fixtures +import json +from tests.lib import PhotolibTest -class PhotolibTestExample(PhotolibTest): +class PhotolibTestMisc(PhotolibTest): def test_index(self): """ Tests that the '/' url returns a redirect to '/feed' @@ -11,27 +10,3 @@ class PhotolibTestExample(PhotolibTest): self.getPage("/") self.assertStatus('302 Found') self.assertHeaderEndsWith('Location', '/feed') - - -class PhotolibTestApi(PhotolibTest): - def test_photos(self): - self.getPage("/api/v1/photos") - self.assertStatus('200 OK') - - def test_byhash(self): - self.getPage("/api/v1/byhash?sha=lol") - self.assertStatus('404 Not Found') - - def test_user(self): - self.getPage("/api/v1/user") - self.assertStatus('200 OK') - - # self.assertBody('Hello world') - # self.assertHeader('Content-Type', 'text/html;charset=utf-8') - # self.getPage("/echo?message=A+bient%F4t", - # headers=[ - # ('Accept-Charset', 'ISO-8859-1,utf-8'), - # ('Content-Type', 'text/html;charset=ISO-8859-1') - # ] - # ) -