Add test for API object endpoint
This commit is contained in:
parent
51ab51921e
commit
3c8bd177b2
@ -461,6 +461,17 @@ class MediaEntry(Base, MediaEntryMixin):
|
|||||||
"pump_io": {
|
"pump_io": {
|
||||||
"shared": False,
|
"shared": False,
|
||||||
},
|
},
|
||||||
|
"links": {
|
||||||
|
"self": {
|
||||||
|
"href": request.urlgen(
|
||||||
|
"mediagoblin.federation.object",
|
||||||
|
objectType=self.objectType,
|
||||||
|
slug=self.slug,
|
||||||
|
qualified=True
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.title:
|
if self.title:
|
||||||
|
@ -51,7 +51,7 @@ add_route(
|
|||||||
# object endpoints
|
# object endpoints
|
||||||
add_route(
|
add_route(
|
||||||
"mediagoblin.federation.object",
|
"mediagoblin.federation.object",
|
||||||
"/api/<string:objectType>/<string:uuid>",
|
"/api/<string:objectType>/<string:slug>",
|
||||||
"mediagoblin.federation.views:object"
|
"mediagoblin.federation.views:object"
|
||||||
)
|
)
|
||||||
add_route(
|
add_route(
|
||||||
|
@ -275,16 +275,16 @@ def feed(request):
|
|||||||
def object(request, raw_obj=False):
|
def object(request, raw_obj=False):
|
||||||
""" Lookup for a object type """
|
""" Lookup for a object type """
|
||||||
object_type = request.matchdict["objectType"]
|
object_type = request.matchdict["objectType"]
|
||||||
uuid = request.matchdict["uuid"]
|
slug = request.matchdict["slug"]
|
||||||
if object_type not in ["image"]:
|
if object_type not in ["image"]:
|
||||||
error = "Unknown type: {0}".format(object_type)
|
error = "Unknown type: {0}".format(object_type)
|
||||||
# not sure why this is 404, maybe ask evan. Maybe 400?
|
# not sure why this is 404, maybe ask evan. Maybe 400?
|
||||||
return json_response({"error": error}, status=404)
|
return json_response({"error": error}, status=404)
|
||||||
|
|
||||||
media = MediaEntry.query.filter_by(slug=uuid).first()
|
media = MediaEntry.query.filter_by(slug=slug).first()
|
||||||
if media is None:
|
if media is None:
|
||||||
# no media found with that uuid
|
# no media found with that uuid
|
||||||
error = "Can't find a {0} with ID = {1}".format(object_type, uuid)
|
error = "Can't find a {0} with ID = {1}".format(object_type, slug)
|
||||||
return json_response({"error": error}, status=404)
|
return json_response({"error": error}, status=404)
|
||||||
|
|
||||||
if raw_obj:
|
if raw_obj:
|
||||||
|
@ -178,6 +178,35 @@ class TestAPI(object):
|
|||||||
# Assert that we've got a 403
|
# Assert that we've got a 403
|
||||||
assert "403 FORBIDDEN" in excinfo.value.message
|
assert "403 FORBIDDEN" in excinfo.value.message
|
||||||
|
|
||||||
|
def test_object_endpoint(self, test_app):
|
||||||
|
""" Tests that object can be looked up at endpoint """
|
||||||
|
# Post an image
|
||||||
|
response, data = self._upload_image(test_app, GOOD_JPG)
|
||||||
|
response, data = self._post_image_to_feed(test_app, data)
|
||||||
|
|
||||||
|
# Now lookup image to check that endpoint works.
|
||||||
|
image = data["object"]
|
||||||
|
|
||||||
|
assert "links" in image
|
||||||
|
assert "self" in image["links"]
|
||||||
|
|
||||||
|
# Get URI and strip testing host off
|
||||||
|
object_uri = image["links"]["self"]["href"]
|
||||||
|
object_uri = object_uri.replace("http://localhost:80", "")
|
||||||
|
|
||||||
|
with mock.patch("mediagoblin.decorators.oauth_required", new_callable=self.mocked_oauth_required):
|
||||||
|
request = test_app.get(object_uri)
|
||||||
|
|
||||||
|
image = json.loads(request.body)
|
||||||
|
entry = MediaEntry.query.filter_by(id=image["id"]).first()
|
||||||
|
|
||||||
|
assert request.status_code == 200
|
||||||
|
assert entry.id == image["id"]
|
||||||
|
|
||||||
|
assert "image" in image
|
||||||
|
assert "fullImage" in image
|
||||||
|
assert "pump_io" in image
|
||||||
|
assert "links" in image
|
||||||
|
|
||||||
def test_post_comment(self, test_app):
|
def test_post_comment(self, test_app):
|
||||||
""" Tests that I can post an comment media """
|
""" Tests that I can post an comment media """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user