Fix #1025 - Make API IDs IRIs
This commit is contained in:
@@ -26,6 +26,7 @@ from webtest import AppError
|
||||
from .resources import GOOD_JPG
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin.db.models import User, MediaEntry, MediaComment
|
||||
from mediagoblin.tools.routing import extract_url_arguments
|
||||
from mediagoblin.tests.tools import fixture_add_user
|
||||
from mediagoblin.moderation.tools import take_away_privileges
|
||||
|
||||
@@ -187,7 +188,8 @@ class TestAPI(object):
|
||||
# Lets change the image uploader to be self.other_user, this is easier
|
||||
# than uploading the image as someone else as the way self.mocked_oauth_required
|
||||
# and self._upload_image.
|
||||
media = MediaEntry.query.filter_by(id=data["object"]["id"]).first()
|
||||
id = int(data["object"]["id"].split("/")[-1])
|
||||
media = MediaEntry.query.filter_by(id=id).first()
|
||||
media.uploader = self.other_user.id
|
||||
media.save()
|
||||
|
||||
@@ -230,13 +232,14 @@ class TestAPI(object):
|
||||
image = json.loads(response.body.decode())["object"]
|
||||
|
||||
# Check everything has been set on the media correctly
|
||||
media = MediaEntry.query.filter_by(id=image["id"]).first()
|
||||
id = int(image["id"].split("/")[-1])
|
||||
media = MediaEntry.query.filter_by(id=id).first()
|
||||
assert media.title == title
|
||||
assert media.description == description
|
||||
assert media.license == license
|
||||
|
||||
# Check we're being given back everything we should on an update
|
||||
assert image["id"] == media.id
|
||||
assert int(image["id"].split("/")[-1]) == media.id
|
||||
assert image["displayName"] == title
|
||||
assert image["content"] == description
|
||||
assert image["license"] == license
|
||||
@@ -285,10 +288,10 @@ class TestAPI(object):
|
||||
request = test_app.get(object_uri)
|
||||
|
||||
image = json.loads(request.body.decode())
|
||||
entry = MediaEntry.query.filter_by(id=image["id"]).first()
|
||||
entry_id = int(image["id"].split("/")[-1])
|
||||
entry = MediaEntry.query.filter_by(id=entry_id).first()
|
||||
|
||||
assert request.status_code == 200
|
||||
assert entry.id == image["id"]
|
||||
|
||||
assert "image" in image
|
||||
assert "fullImage" in image
|
||||
@@ -316,7 +319,8 @@ class TestAPI(object):
|
||||
assert response.status_code == 200
|
||||
|
||||
# Find the objects in the database
|
||||
media = MediaEntry.query.filter_by(id=data["object"]["id"]).first()
|
||||
media_id = int(data["object"]["id"].split("/")[-1])
|
||||
media = MediaEntry.query.filter_by(id=media_id).first()
|
||||
comment = media.get_comments()[0]
|
||||
|
||||
# Tests that it matches in the database
|
||||
@@ -324,7 +328,6 @@ class TestAPI(object):
|
||||
assert comment.content == content
|
||||
|
||||
# Test that the response is what we should be given
|
||||
assert comment.id == comment_data["object"]["id"]
|
||||
assert comment.content == comment_data["object"]["content"]
|
||||
|
||||
def test_unable_to_post_comment_as_someone_else(self, test_app):
|
||||
@@ -379,7 +382,7 @@ class TestAPI(object):
|
||||
response, comment_data = self._activity_to_feed(test_app, activity)
|
||||
|
||||
# change who uploaded the comment as it's easier than changing
|
||||
comment_id = comment_data["object"]["id"]
|
||||
comment_id = int(comment_data["object"]["id"].split("/")[-1])
|
||||
comment = MediaComment.query.filter_by(id=comment_id).first()
|
||||
comment.author = self.other_user.id
|
||||
comment.save()
|
||||
|
||||
Reference in New Issue
Block a user