misc tweaks

This commit is contained in:
dave 2023-01-18 20:05:08 -08:00
parent cff6e32667
commit ff8592c89d
4 changed files with 17 additions and 32 deletions

View File

@ -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),

View File

@ -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

View File

@ -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)))])

View File

@ -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')
# ]
# )