misc tweaks
This commit is contained in:
parent
cff6e32667
commit
ff8592c89d
|
@ -69,7 +69,7 @@ class PhotosApiV1Upload(object):
|
||||||
if type(files) != list:
|
if type(files) != list:
|
||||||
files = [files]
|
files = [files]
|
||||||
if set([file.filename for file in files]) != set(meta["files"].keys()):
|
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()
|
dupes = db.query(Photo).filter(Photo.hash.in_([f["hash"] for f in meta["files"].values()])).first()
|
||||||
if dupes:
|
if dupes:
|
||||||
|
@ -270,14 +270,14 @@ class PhotosApiV1PhotoTags(object):
|
||||||
|
|
||||||
def DELETE(self, uuid): # deleting tag
|
def DELETE(self, uuid): # deleting tag
|
||||||
tag = db.query(Tag).filter(Tag.uuid == uuid).first()
|
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.delete(tag)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def POST(self): # creating tag
|
def POST(self): # creating tag
|
||||||
tagdata = json.loads(cherrypy.request.body.read())
|
tagdata = json.loads(cherrypy.request.body.read())
|
||||||
tagname = tagdata.get("name")
|
tagname = tagdata["name"]
|
||||||
db.add(Tag(name=tagname,
|
db.add(Tag(name=tagname,
|
||||||
title=tagdata.get("title", None) or tagname.capitalize(),
|
title=tagdata.get("title", None) or tagname.capitalize(),
|
||||||
description=tagdata.get("description", None),
|
description=tagdata.get("description", None),
|
||||||
|
|
|
@ -124,7 +124,7 @@ class PhotoApiClient(object):
|
||||||
def create_tag(self, name, title, description):
|
def create_tag(self, name, title, description):
|
||||||
return self.post("tags", json={"name": name, "title": title, "description": description})
|
return self.post("tags", json={"name": name, "title": title, "description": description})
|
||||||
|
|
||||||
def list_tags(self, name):
|
def list_tags(self, name=None):
|
||||||
params = {}
|
params = {}
|
||||||
if name:
|
if name:
|
||||||
params["name"] = name
|
params["name"] = name
|
||||||
|
|
10
tests/lib.py
10
tests/lib.py
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import cherrypy
|
import cherrypy
|
||||||
|
@ -46,6 +47,9 @@ class PhotolibTest(helper.CPWebCase):
|
||||||
'tools.auth_basic.on': False,
|
'tools.auth_basic.on': False,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.do_gc_test = False
|
||||||
|
|
||||||
def getHeader(self, name):
|
def getHeader(self, name):
|
||||||
for key, value in self.headers:
|
for key, value in self.headers:
|
||||||
if name == key:
|
if name == key:
|
||||||
|
@ -55,3 +59,9 @@ class PhotolibTest(helper.CPWebCase):
|
||||||
header = self.getHeader(name)
|
header = self.getHeader(name)
|
||||||
assert header is not None, "Header '{}' not present".format(name)
|
assert header is not None, "Header '{}' not present".format(name)
|
||||||
assert header.endswith(value), "Needed to end with '{}' but got '{}'".format(value, header)
|
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)))])
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import pytest
|
import json
|
||||||
import cherrypy
|
from tests.lib import PhotolibTest
|
||||||
from tests.lib import * # NOQA - fixtures
|
|
||||||
|
|
||||||
|
|
||||||
class PhotolibTestExample(PhotolibTest):
|
class PhotolibTestMisc(PhotolibTest):
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
"""
|
"""
|
||||||
Tests that the '/' url returns a redirect to '/feed'
|
Tests that the '/' url returns a redirect to '/feed'
|
||||||
|
@ -11,27 +10,3 @@ class PhotolibTestExample(PhotolibTest):
|
||||||
self.getPage("/")
|
self.getPage("/")
|
||||||
self.assertStatus('302 Found')
|
self.assertStatus('302 Found')
|
||||||
self.assertHeaderEndsWith('Location', '/feed')
|
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')
|
|
||||||
# ]
|
|
||||||
# )
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue