aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r--mediagoblin/tests/__init__.py4
-rw-r--r--mediagoblin/tests/test_api.py71
-rw-r--r--mediagoblin/tests/test_auth.py17
-rw-r--r--mediagoblin/tests/test_basic_auth.py6
-rw-r--r--mediagoblin/tests/test_csrf_middleware.py4
-rw-r--r--mediagoblin/tests/test_edit.py23
-rw-r--r--mediagoblin/tests/test_exif.py6
-rw-r--r--mediagoblin/tests/test_ldap.py6
-rw-r--r--mediagoblin/tests/test_misc.py24
-rw-r--r--mediagoblin/tests/test_modelmethods.py66
-rw-r--r--mediagoblin/tests/test_moderation.py53
-rw-r--r--mediagoblin/tests/test_notifications.py32
-rw-r--r--mediagoblin/tests/test_openid.py7
-rw-r--r--mediagoblin/tests/test_persona.py12
-rw-r--r--mediagoblin/tests/test_privileges.py8
-rw-r--r--mediagoblin/tests/test_reporting.py37
-rw-r--r--mediagoblin/tests/test_response.py65
-rw-r--r--mediagoblin/tests/test_submission.py24
-rw-r--r--mediagoblin/tests/tools.py83
19 files changed, 326 insertions, 222 deletions
diff --git a/mediagoblin/tests/__init__.py b/mediagoblin/tests/__init__.py
index fbf3fc6c..651dac24 100644
--- a/mediagoblin/tests/__init__.py
+++ b/mediagoblin/tests/__init__.py
@@ -16,7 +16,7 @@
import pytest
-from mediagoblin.db.models import User
+from mediagoblin.db.models import User, LocalUser
from mediagoblin.tests.tools import fixture_add_user
from mediagoblin.tools import template
@@ -44,7 +44,7 @@ class MGClientTestCase:
fixture_add_user(username, **options)
def user(self, username):
- return User.query.filter(User.username == username).first()
+ return LocalUser.query.filter(LocalUser.username==username).first()
def _do_request(self, url, *context_keys, **kwargs):
template.clear_test_template_context()
diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py
index 83003875..10bf08fe 100644
--- a/mediagoblin/tests/test_api.py
+++ b/mediagoblin/tests/test_api.py
@@ -25,7 +25,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.db.models import User, Activity, MediaEntry, TextComment
from mediagoblin.tools.routing import extract_url_arguments
from mediagoblin.tests.tools import fixture_add_user
from mediagoblin.moderation.tools import take_away_privileges
@@ -188,9 +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.
- id = int(data["object"]["id"].split("/")[-2])
- media = MediaEntry.query.filter_by(id=id).first()
- media.uploader = self.other_user.id
+ media = MediaEntry.query.filter_by(public_id=data["object"]["id"]).first()
+ media.actor = self.other_user.id
media.save()
# Now lets try and edit the image as self.user, this should produce a 403 error.
@@ -232,14 +231,13 @@ class TestAPI(object):
image = json.loads(response.body.decode())["object"]
# Check everything has been set on the media correctly
- id = int(image["id"].split("/")[-2])
- media = MediaEntry.query.filter_by(id=id).first()
+ media = MediaEntry.query.filter_by(public_id=image["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 int(image["id"].split("/")[-2]) == media.id
+ assert image["id"] == media.public_id
assert image["displayName"] == title
assert image["content"] == description
assert image["license"] == license
@@ -288,8 +286,7 @@ class TestAPI(object):
request = test_app.get(object_uri)
image = json.loads(request.body.decode())
- entry_id = int(image["id"].split("/")[-2])
- entry = MediaEntry.query.filter_by(id=entry_id).first()
+ entry = MediaEntry.query.filter_by(public_id=image["id"]).first()
assert request.status_code == 200
@@ -319,12 +316,11 @@ class TestAPI(object):
assert response.status_code == 200
# Find the objects in the database
- media_id = int(data["object"]["id"].split("/")[-2])
- media = MediaEntry.query.filter_by(id=media_id).first()
+ media = MediaEntry.query.filter_by(public_id=data["object"]["id"]).first()
comment = media.get_comments()[0]
# Tests that it matches in the database
- assert comment.author == self.user.id
+ assert comment.actor == self.user.id
assert comment.content == content
# Test that the response is what we should be given
@@ -382,9 +378,8 @@ 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 = int(comment_data["object"]["id"].split("/")[-2])
- comment = MediaComment.query.filter_by(id=comment_id).first()
- comment.author = self.other_user.id
+ comment = TextComment.query.filter_by(public_id=comment_data["object"]["id"]).first()
+ comment.actor = self.other_user.id
comment.save()
# Update the comment as someone else.
@@ -463,7 +458,40 @@ class TestAPI(object):
# Check that image i uploaded is there
assert feed["items"][0]["verb"] == "post"
- assert feed["items"][0]["actor"]
+ assert feed["items"][0]["id"] == data["id"]
+ assert feed["items"][0]["object"]["objectType"] == "image"
+ assert feed["items"][0]["object"]["id"] == data["object"]["id"]
+
+
+ def test_read_another_feed(self, test_app):
+ """ Test able to read objects from someone else's feed """
+ response, data = self._upload_image(test_app, GOOD_JPG)
+ response, data = self._post_image_to_feed(test_app, data)
+
+ # Change the active user to someone else.
+ self.active_user = self.other_user
+
+ # Fetch the feed
+ url = "/api/user/{0}/feed".format(self.user.username)
+ with self.mock_oauth():
+ response = test_app.get(url)
+ feed = json.loads(response.body.decode())
+
+ assert response.status_code == 200
+
+ # Check it has the attributes it ought to.
+ assert "displayName" in feed
+ assert "objectTypes" in feed
+ assert "url" in feed
+ assert "links" in feed
+ assert "author" in feed
+ assert "items" in feed
+
+ # Assert the uploaded image is there
+ assert feed["items"][0]["verb"] == "post"
+ assert feed["items"][0]["id"] == data["id"]
+ assert feed["items"][0]["object"]["objectType"] == "image"
+ assert feed["items"][0]["object"]["id"] == data["object"]["id"]
def test_cant_post_to_someone_elses_feed(self, test_app):
""" Test that can't post to someone elses feed """
@@ -510,8 +538,7 @@ class TestAPI(object):
response = self._activity_to_feed(test_app, activity)[1]
# Check the media is no longer in the database
- media_id = int(object_id.split("/")[-2])
- media = MediaEntry.query.filter_by(id=media_id).first()
+ media = MediaEntry.query.filter_by(public_id=object_id).first()
assert media is None
@@ -552,8 +579,8 @@ class TestAPI(object):
delete = self._activity_to_feed(test_app, activity)[1]
# Verify the comment no longer exists
- comment_id = int(comment["object"]["id"].split("/")[-2])
- assert MediaComment.query.filter_by(id=comment_id).first() is None
+ assert TextComment.query.filter_by(public_id=comment["object"]["id"]).first() is None
+ comment_id = comment["object"]["id"]
# Check we've got a delete activity back
assert "id" in delete
@@ -593,8 +620,6 @@ class TestAPI(object):
comment = self._activity_to_feed(test_app, activity)[1]
# Verify the comment reflects the changes
- comment_id = int(comment["object"]["id"].split("/")[-2])
- model = MediaComment.query.filter_by(id=comment_id).first()
+ model = TextComment.query.filter_by(public_id=comment["object"]["id"]).first()
assert model.content == activity["object"]["content"]
-
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py
index 5ce67688..62f77f74 100644
--- a/mediagoblin/tests/test_auth.py
+++ b/mediagoblin/tests/test_auth.py
@@ -23,7 +23,7 @@ import six
import six.moves.urllib.parse as urlparse
from mediagoblin import mg_globals
-from mediagoblin.db.models import User
+from mediagoblin.db.models import User, LocalUser
from mediagoblin.tests.tools import get_app, fixture_add_user
from mediagoblin.tools import template, mail
from mediagoblin.auth import tools as auth_tools
@@ -98,8 +98,9 @@ def test_register_views(test_app):
assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT
## Make sure user is in place
- new_user = mg_globals.database.User.query.filter_by(
- username=u'angrygirl').first()
+ new_user = mg_globals.database.LocalUser.query.filter(
+ LocalUser.username==u'angrygirl'
+ ).first()
assert new_user
## Make sure that the proper privileges are granted on registration
@@ -137,8 +138,9 @@ def test_register_views(test_app):
# assert context['verification_successful'] == True
# TODO: Would be good to test messages here when we can do so...
- new_user = mg_globals.database.User.query.filter_by(
- username=u'angrygirl').first()
+ new_user = mg_globals.database.LocalUser.query.filter(
+ LocalUser.username==u'angrygirl'
+ ).first()
assert new_user
## Verify the email activation works
@@ -149,8 +151,9 @@ def test_register_views(test_app):
'mediagoblin/user_pages/user.html']
# assert context['verification_successful'] == True
# TODO: Would be good to test messages here when we can do so...
- new_user = mg_globals.database.User.query.filter_by(
- username=u'angrygirl').first()
+ new_user = mg_globals.database.LocalUser.query.filter(
+ LocalUser.username==u'angrygirl'
+ ).first()
assert new_user
# Uniqueness checks
diff --git a/mediagoblin/tests/test_basic_auth.py b/mediagoblin/tests/test_basic_auth.py
index e7157bee..3a42e407 100644
--- a/mediagoblin/tests/test_basic_auth.py
+++ b/mediagoblin/tests/test_basic_auth.py
@@ -16,7 +16,7 @@
import six.moves.urllib.parse as urlparse
-from mediagoblin.db.models import User
+from mediagoblin.db.models import User, LocalUser
from mediagoblin.plugins.basic_auth import tools as auth_tools
from mediagoblin.tests.tools import fixture_add_user
from mediagoblin.tools import template
@@ -88,7 +88,7 @@ def test_change_password(test_app):
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
# test_user has to be fetched again in order to have the current values
- test_user = User.query.filter_by(username=u'chris').first()
+ test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
assert auth_tools.bcrypt_check_password('123456', test_user.pw_hash)
# test that the password cannot be changed if the given
@@ -100,5 +100,5 @@ def test_change_password(test_app):
'new_password': '098765',
})
- test_user = User.query.filter_by(username=u'chris').first()
+ test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
assert not auth_tools.bcrypt_check_password('098765', test_user.pw_hash)
diff --git a/mediagoblin/tests/test_csrf_middleware.py b/mediagoblin/tests/test_csrf_middleware.py
index a272caf6..4452112b 100644
--- a/mediagoblin/tests/test_csrf_middleware.py
+++ b/mediagoblin/tests/test_csrf_middleware.py
@@ -25,7 +25,7 @@ def test_csrf_cookie_set(test_app):
# assert that the mediagoblin nonce cookie has been set
assert 'Set-Cookie' in response.headers
- assert cookie_name in response.cookies_set
+ assert cookie_name in test_app.cookies
# assert that we're also sending a vary header
assert response.headers.get('Vary', False) == 'Cookie'
@@ -34,7 +34,7 @@ def test_csrf_cookie_set(test_app):
# We need a fresh app for this test on webtest < 1.3.6.
# We do not understand why, but it fixes the tests.
# If we require webtest >= 1.3.6, we can switch to a non fresh app here.
-#
+#
# ... this comment might be irrelevant post-pytest-fixtures, but I'm not
# removing it yet in case we move to module-level tests :)
# -- cwebber
diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py
index 384929cb..632c8e3c 100644
--- a/mediagoblin/tests/test_edit.py
+++ b/mediagoblin/tests/test_edit.py
@@ -19,7 +19,7 @@ import six.moves.urllib.parse as urlparse
import pytest
from mediagoblin import mg_globals
-from mediagoblin.db.models import User, MediaEntry
+from mediagoblin.db.models import User, LocalUser, MediaEntry
from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry
from mediagoblin import auth
from mediagoblin.tools import template, mail
@@ -44,12 +44,12 @@ class TestUserEdit(object):
self.login(test_app)
# Make sure user exists
- assert User.query.filter_by(username=u'chris').first()
+ assert LocalUser.query.filter(LocalUser.username==u'chris').first()
res = test_app.post('/edit/account/delete/', {'confirmed': 'y'})
# Make sure user has been deleted
- assert User.query.filter_by(username=u'chris').first() == None
+ assert LocalUser.query.filter(LocalUser.username==u'chris').first() == None
#TODO: make sure all corresponding items comments etc have been
# deleted too. Perhaps in submission test?
@@ -79,7 +79,7 @@ class TestUserEdit(object):
'bio': u'I love toast!',
'url': u'http://dustycloud.org/'})
- test_user = User.query.filter_by(username=u'chris').first()
+ test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
assert test_user.bio == u'I love toast!'
assert test_user.url == u'http://dustycloud.org/'
@@ -159,9 +159,10 @@ class TestUserEdit(object):
assert urlparse.urlsplit(res.location)[2] == '/'
# Email shouldn't be saved
- email_in_db = mg_globals.database.User.query.filter_by(
- email='new@example.com').first()
- email = User.query.filter_by(username='chris').first().email
+ email_in_db = mg_globals.database.LocalUser.query.filter(
+ LocalUser.email=='new@example.com'
+ ).first()
+ email = LocalUser.query.filter(LocalUser.username=='chris').first().email
assert email_in_db is None
assert email == 'chris@example.com'
@@ -172,7 +173,7 @@ class TestUserEdit(object):
res.follow()
# New email saved?
- email = User.query.filter_by(username='chris').first().email
+ email = LocalUser.query.filter(LocalUser.username=='chris').first().email
assert email == 'new@example.com'
# test changing the url inproperly
@@ -181,8 +182,10 @@ class TestMetaDataEdit:
def setup(self, test_app):
# set up new user
self.user_password = u'toast'
- self.user = fixture_add_user(password = self.user_password,
- privileges=[u'active',u'admin'])
+ self.user = fixture_add_user(
+ password = self.user_password,
+ privileges=[u'active',u'admin']
+ )
self.test_app = test_app
def login(self, test_app):
diff --git a/mediagoblin/tests/test_exif.py b/mediagoblin/tests/test_exif.py
index e3869ec8..d0495a7a 100644
--- a/mediagoblin/tests/test_exif.py
+++ b/mediagoblin/tests/test_exif.py
@@ -306,7 +306,7 @@ def test_exif_extraction():
'Image Orientation': {'field_length': 2,
'field_offset': 42,
'field_type': 3,
- 'printable': u'Rotated 90 CCW',
+ 'printable': u'Rotated 90 CW',
'tag': 274,
'values': [6]},
'Image ResolutionUnit': {'field_length': 2,
@@ -388,8 +388,10 @@ def test_exif_image_orientation():
assert image.size in ((428, 640), (640, 428))
# If this pixel looks right, the rest of the image probably will too.
+ # It seems different values are being seen on different platforms/systems
+ # as of ccca39f1 it seems we're adding to the list those which are seen.
assert_in(image.getdata()[10000],
- ((41, 28, 11), (43, 27, 11))
+ ((37, 23, 14), (41, 28, 11), (43, 27, 11))
)
diff --git a/mediagoblin/tests/test_ldap.py b/mediagoblin/tests/test_ldap.py
index f251d150..6ac0fc46 100644
--- a/mediagoblin/tests/test_ldap.py
+++ b/mediagoblin/tests/test_ldap.py
@@ -26,6 +26,7 @@ import six.moves.urllib.parse as urlparse
from mediagoblin import mg_globals
from mediagoblin.db.base import Session
+from mediagoblin.db.models import LocalUser
from mediagoblin.tests.tools import get_app
from mediagoblin.tools import template
@@ -114,8 +115,9 @@ def test_ldap_plugin(ldap_plugin_app):
ldap_plugin_app.get('/auth/logout/')
# Get user and detach from session
- test_user = mg_globals.database.User.query.filter_by(
- username=u'chris').first()
+ test_user = mg_globals.database.LocalUser.query.filter(
+ LocalUser.username==u'chris'
+ ).first()
Session.expunge(test_user)
# Log back in
diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py
index b3e59c09..558a9bd7 100644
--- a/mediagoblin/tests/test_misc.py
+++ b/mediagoblin/tests/test_misc.py
@@ -24,7 +24,7 @@ from mediagoblin.db.base import Session
from mediagoblin.media_types import sniff_media
from mediagoblin.submit.lib import new_upload_entry
from mediagoblin.submit.task import collect_garbage
-from mediagoblin.db.models import User, MediaEntry, MediaComment
+from mediagoblin.db.models import User, MediaEntry, TextComment, Comment
from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry
@@ -46,25 +46,31 @@ def test_user_deletes_other_comments(test_app):
Session.flush()
# Create all 4 possible comments:
- for u_id in (user_a.id, user_b.id):
- for m_id in (media_a.id, media_b.id):
- cmt = MediaComment()
- cmt.media_entry = m_id
- cmt.author = u_id
+ for u in (user_a, user_b):
+ for m in (media_a, media_b):
+ cmt = TextComment()
+ cmt.actor = u.id
cmt.content = u"Some Comment"
Session.add(cmt)
+ # think i need this to get the command ID
+ Session.flush()
+
+ link = Comment()
+ link.target = m
+ link.comment = cmt
+ Session.add(link)
Session.flush()
usr_cnt1 = User.query.count()
med_cnt1 = MediaEntry.query.count()
- cmt_cnt1 = MediaComment.query.count()
+ cmt_cnt1 = TextComment.query.count()
User.query.get(user_a.id).delete(commit=False)
usr_cnt2 = User.query.count()
med_cnt2 = MediaEntry.query.count()
- cmt_cnt2 = MediaComment.query.count()
+ cmt_cnt2 = TextComment.query.count()
# One user deleted
assert usr_cnt2 == usr_cnt1 - 1
@@ -77,7 +83,7 @@ def test_user_deletes_other_comments(test_app):
usr_cnt2 = User.query.count()
med_cnt2 = MediaEntry.query.count()
- cmt_cnt2 = MediaComment.query.count()
+ cmt_cnt2 = TextComment.query.count()
# All users gone
assert usr_cnt2 == usr_cnt1 - 2
diff --git a/mediagoblin/tests/test_modelmethods.py b/mediagoblin/tests/test_modelmethods.py
index 1ab0c476..4c66e27b 100644
--- a/mediagoblin/tests/test_modelmethods.py
+++ b/mediagoblin/tests/test_modelmethods.py
@@ -20,8 +20,8 @@
from __future__ import print_function
from mediagoblin.db.base import Session
-from mediagoblin.db.models import MediaEntry, User, Privilege, Activity, \
- Generator
+from mediagoblin.db.models import MediaEntry, User, LocalUser, Privilege, \
+ Activity, Generator
from mediagoblin.tests import MGClientTestCase
from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry, \
@@ -56,7 +56,7 @@ class TestMediaEntrySlugs(object):
entry.title = title or u"Some title"
entry.slug = slug
entry.id = this_id
- entry.uploader = uploader or self.chris_user.id
+ entry.actor = uploader or self.chris_user.id
entry.media_type = u'image'
if save:
@@ -168,10 +168,10 @@ class TestUserHasPrivilege:
privileges=[u'admin',u'moderator',u'active'])
fixture_add_user(u'aeva',
privileges=[u'moderator',u'active'])
- self.natalie_user = User.query.filter(
- User.username==u'natalie').first()
- self.aeva_user = User.query.filter(
- User.username==u'aeva').first()
+ self.natalie_user = LocalUser.query.filter(
+ LocalUser.username==u'natalie').first()
+ self.aeva_user = LocalUser.query.filter(
+ LocalUser.username==u'aeva').first()
def test_privilege_added_correctly(self, test_app):
self._setup()
@@ -232,55 +232,3 @@ class TestUserUrlForSelf(MGClientTestCase):
self.user(u'lindsay').url_for_self(fake_urlgen())
assert excinfo.errisinstance(TypeError)
assert 'object is not callable' in str(excinfo)
-
-class TestActivitySetGet(object):
- """ Test methods on the Activity and ActivityIntermediator models """
-
- @pytest.fixture(autouse=True)
- def setup(self, test_app):
- self.app = test_app
- self.user = fixture_add_user()
- self.obj = fixture_media_entry()
- self.target = fixture_media_entry()
-
- def test_set_activity_object(self):
- """ Activity.set_object should produce ActivityIntermediator """
- # The fixture will set self.obj as the object on the activity.
- activity = fixture_add_activity(self.obj, actor=self.user)
-
- # Assert the media has been associated with an AI
- assert self.obj.activity is not None
-
- # Assert the AI on the media and object are the same
- assert activity.object == self.obj.activity
-
- def test_activity_set_target(self):
- """ Activity.set_target should produce ActivityIntermediator """
- # This should set everything needed on the target
- activity = fixture_add_activity(self.obj, actor=self.user)
- activity.set_target(self.target)
-
- # Assert the media has been associated with the AI
- assert self.target.activity is not None
-
- # assert the AI on the media and target are the same
- assert activity.target == self.target.activity
-
- def test_get_activity_object(self):
- """ Activity.get_object should return a set object """
- activity = fixture_add_activity(self.obj, actor=self.user)
-
- print("self.obj.activity = {0}".format(self.obj.activity))
-
- # check we now can get the object
- assert activity.get_object is not None
- assert activity.get_object.id == self.obj.id
-
- def test_get_activity_target(self):
- """ Activity.set_target should return a set target """
- activity = fixture_add_activity(self.obj, actor=self.user)
- activity.set_target(self.target)
-
- # check we can get the target
- assert activity.get_target is not None
- assert activity.get_target.id == self.target.id
diff --git a/mediagoblin/tests/test_moderation.py b/mediagoblin/tests/test_moderation.py
index e7a0ebef..55bb4c4b 100644
--- a/mediagoblin/tests/test_moderation.py
+++ b/mediagoblin/tests/test_moderation.py
@@ -18,7 +18,8 @@ import pytest
from mediagoblin.tests.tools import (fixture_add_user,
fixture_add_comment_report, fixture_add_comment)
-from mediagoblin.db.models import User, CommentReport, MediaComment, UserBan
+from mediagoblin.db.models import User, LocalUser, Report, TextComment, \
+ UserBan, GenericModelReference
from mediagoblin.tools import template, mail
from webtest import AppError
@@ -47,9 +48,9 @@ class TestModerationViews:
self.query_for_users()
def query_for_users(self):
- self.admin_user = User.query.filter(User.username==u'admin').first()
- self.mod_user = User.query.filter(User.username==u'moderator').first()
- self.user = User.query.filter(User.username==u'regular').first()
+ self.admin_user = LocalUser.query.filter(LocalUser.username==u'admin').first()
+ self.mod_user = LocalUser.query.filter(LocalUser.username==u'moderator').first()
+ self.user = LocalUser.query.filter(LocalUser.username==u'regular').first()
def do_post(self, data, *context_keys, **kwargs):
url = kwargs.pop('url', '/submit/')
@@ -102,15 +103,15 @@ class TestModerationViews:
# to a reported comment
#----------------------------------------------------------------------
fixture_add_comment_report(reported_user=self.user)
- comment_report = CommentReport.query.filter(
- CommentReport.reported_user==self.user).first()
+ comment_report = Report.query.filter(
+ Report.reported_user==self.user).first()
response = self.test_app.get('/mod/reports/{0}/'.format(
comment_report.id))
assert response.status == '200 OK'
self.query_for_users()
- comment_report = CommentReport.query.filter(
- CommentReport.reported_user==self.user).first()
+ comment_report = Report.query.filter(
+ Report.reported_user==self.user).first()
response, context = self.do_post({'action_to_resolve':[u'takeaway'],
'take_away_privileges':[u'commenter'],
@@ -118,15 +119,15 @@ class TestModerationViews:
url='/mod/reports/{0}/'.format(comment_report.id))
self.query_for_users()
- comment_report = CommentReport.query.filter(
- CommentReport.reported_user==self.user).first()
+ comment_report = Report.query.filter(
+ Report.reported_user==self.user).first()
assert response.status == '302 FOUND'
assert not self.user.has_privilege(u'commenter')
assert comment_report.is_archived_report() is True
fixture_add_comment_report(reported_user=self.user)
- comment_report = CommentReport.query.filter(
- CommentReport.reported_user==self.user).first()
+ comment_report = Report.query.filter(
+ Report.reported_user==self.user).first()
# Then, test a moderator sending an email to a user in response to a
# reported comment
@@ -139,8 +140,8 @@ class TestModerationViews:
url='/mod/reports/{0}/'.format(comment_report.id))
self.query_for_users()
- comment_report = CommentReport.query.filter(
- CommentReport.reported_user==self.user).first()
+ comment_report = Report.query.filter(
+ Report.reported_user==self.user).first()
assert response.status == '302 FOUND'
assert mail.EMAIL_TEST_MBOX_INBOX == [{'to': [u'regular@example.com'],
'message': 'Content-Type: text/plain; charset="utf-8"\n\
@@ -157,13 +158,17 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
self.query_for_users()
fixture_add_comment(author=self.user.id,
comment=u'Comment will be removed')
- test_comment = MediaComment.query.filter(
- MediaComment.author==self.user.id).first()
+ test_comment = TextComment.query.filter(
+ TextComment.actor==self.user.id).first()
fixture_add_comment_report(comment=test_comment,
reported_user=self.user)
- comment_report = CommentReport.query.filter(
- CommentReport.comment==test_comment).filter(
- CommentReport.resolved==None).first()
+ comment_gmr = GenericModelReference.query.filter_by(
+ obj_pk=test_comment.id,
+ model_type=test_comment.__tablename__
+ ).first()
+ comment_report = Report.query.filter(
+ Report.object_id==comment_gmr.id).filter(
+ Report.resolved==None).first()
response, context = self.do_post(
{'action_to_resolve':[u'userban', u'delete'],
@@ -176,17 +181,17 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
test_user_ban = UserBan.query.filter(
UserBan.user_id == self.user.id).first()
assert test_user_ban is not None
- test_comment = MediaComment.query.filter(
- MediaComment.author==self.user.id).first()
+ test_comment = TextComment.query.filter(
+ TextComment.actor==self.user.id).first()
assert test_comment is None
# Then, test what happens when a moderator attempts to punish an admin
# from a reported comment on an admin.
#----------------------------------------------------------------------
fixture_add_comment_report(reported_user=self.admin_user)
- comment_report = CommentReport.query.filter(
- CommentReport.reported_user==self.admin_user).filter(
- CommentReport.resolved==None).first()
+ comment_report = Report.query.filter(
+ Report.reported_user==self.admin_user).filter(
+ Report.resolved==None).first()
response, context = self.do_post({'action_to_resolve':[u'takeaway'],
'take_away_privileges':[u'active'],
diff --git a/mediagoblin/tests/test_notifications.py b/mediagoblin/tests/test_notifications.py
index 385da569..19bf8665 100644
--- a/mediagoblin/tests/test_notifications.py
+++ b/mediagoblin/tests/test_notifications.py
@@ -20,8 +20,7 @@ import six.moves.urllib.parse as urlparse
from mediagoblin.tools import template, mail
-from mediagoblin.db.models import Notification, CommentNotification, \
- CommentSubscription
+from mediagoblin.db.models import Notification, CommentSubscription
from mediagoblin.db.base import Session
from mediagoblin.notifications import mark_comment_notification_seen
@@ -109,28 +108,41 @@ class TestNotifications:
notification = notifications[0]
- assert type(notification) == CommentNotification
assert notification.seen == False
assert notification.user_id == user.id
- assert notification.subject.get_author.id == self.test_user.id
- assert notification.subject.content == u'Test comment #42'
+ assert notification.obj().get_actor.id == self.test_user.id
+ assert notification.obj().content == u'Test comment #42'
if wants_email == True:
- assert mail.EMAIL_TEST_MBOX_INBOX == [
- {'from': 'notice@mediagoblin.example.org',
- 'message': 'Content-Type: text/plain; \
+ # Why the `or' here? In Werkzeug 0.11.0 and above
+ # werkzeug stopped showing the port for localhost when
+ # rendering something like this. As long as we're
+ # supporting pre-0.11.0 we'll keep this `or', but maybe
+ # in the future we can kill it.
+ assert (
+ mail.EMAIL_TEST_MBOX_INBOX == [
+ {'from': 'notice@mediagoblin.example.org',
+ 'message': 'Content-Type: text/plain; \
charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: \
base64\nSubject: GNU MediaGoblin - chris commented on your \
post\nFrom: notice@mediagoblin.example.org\nTo: \
otherperson@example.com\n\nSGkgb3RoZXJwZXJzb24sCmNocmlzIGNvbW1lbnRlZCBvbiB5b3VyIHBvc3QgKGh0dHA6Ly9sb2Nh\nbGhvc3Q6ODAvdS9vdGhlcnBlcnNvbi9tL3NvbWUtdGl0bGUvYy8xLyNjb21tZW50KSBhdCBHTlUg\nTWVkaWFHb2JsaW4KClRlc3QgY29tbWVudCAjNDIKCkdOVSBNZWRpYUdvYmxpbg==\n',
- 'to': [u'otherperson@example.com']}]
+ 'to': [u'otherperson@example.com']}]
+ or mail.EMAIL_TEST_MBOX_INBOX == [
+ {'from': 'notice@mediagoblin.example.org',
+ 'message': 'Content-Type: text/plain; \
+charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: \
+base64\nSubject: GNU MediaGoblin - chris commented on your \
+post\nFrom: notice@mediagoblin.example.org\nTo: \
+otherperson@example.com\n\nSGkgb3RoZXJwZXJzb24sCmNocmlzIGNvbW1lbnRlZCBvbiB5b3VyIHBvc3QgKGh0dHA6Ly9sb2Nh\nbGhvc3QvdS9vdGhlcnBlcnNvbi9tL3NvbWUtdGl0bGUvYy8xLyNjb21tZW50KSBhdCBHTlUgTWVk\naWFHb2JsaW4KClRlc3QgY29tbWVudCAjNDIKCkdOVSBNZWRpYUdvYmxpbg==\n',
+ 'to': [u'otherperson@example.com']}])
else:
assert mail.EMAIL_TEST_MBOX_INBOX == []
# Save the ids temporarily because of DetachedInstanceError
notification_id = notification.id
- comment_id = notification.subject.id
+ comment_id = notification.obj().get_comment_link().id
self.logout()
self.login('otherperson', 'nosreprehto')
diff --git a/mediagoblin/tests/test_openid.py b/mediagoblin/tests/test_openid.py
index a3ab176a..71767032 100644
--- a/mediagoblin/tests/test_openid.py
+++ b/mediagoblin/tests/test_openid.py
@@ -28,7 +28,7 @@ openid_consumer = pytest.importorskip(
from mediagoblin import mg_globals
from mediagoblin.db.base import Session
-from mediagoblin.db.models import User
+from mediagoblin.db.models import User, LocalUser
from mediagoblin.plugins.openid.models import OpenIDUserURL
from mediagoblin.tests.tools import get_app, fixture_add_user
from mediagoblin.tools import template
@@ -192,8 +192,9 @@ class TestOpenIDPlugin(object):
openid_plugin_app.get('/auth/logout')
# Get user and detach from session
- test_user = mg_globals.database.User.query.filter_by(
- username=u'chris').first()
+ test_user = mg_globals.database.LocalUser.query.filter(
+ LocalUser.username==u'chris'
+ ).first()
Session.expunge(test_user)
# Log back in
diff --git a/mediagoblin/tests/test_persona.py b/mediagoblin/tests/test_persona.py
index a8466b8a..437cb7a1 100644
--- a/mediagoblin/tests/test_persona.py
+++ b/mediagoblin/tests/test_persona.py
@@ -28,7 +28,7 @@ pytest.importorskip("requests")
from mediagoblin import mg_globals
from mediagoblin.db.base import Session
-from mediagoblin.db.models import Privilege
+from mediagoblin.db.models import Privilege, LocalUser
from mediagoblin.tests.tools import get_app
from mediagoblin.tools import template
@@ -117,14 +117,16 @@ class TestPersonaPlugin(object):
persona_plugin_app.get('/auth/logout/')
# Get user and detach from session
- test_user = mg_globals.database.User.query.filter_by(
- username=u'chris').first()
+ test_user = mg_globals.database.LocalUser.query.filter(
+ LocalUser.username==u'chris'
+ ).first()
active_privilege = Privilege.query.filter(
Privilege.privilege_name==u'active').first()
test_user.all_privileges.append(active_privilege)
test_user.save()
- test_user = mg_globals.database.User.query.filter_by(
- username=u'chris').first()
+ test_user = mg_globals.database.LocalUser.query.filter(
+ LocalUser.username==u'chris'
+ ).first()
Session.expunge(test_user)
# Add another user for _test_edit_persona
diff --git a/mediagoblin/tests/test_privileges.py b/mediagoblin/tests/test_privileges.py
index 8ea3d754..2e0b7347 100644
--- a/mediagoblin/tests/test_privileges.py
+++ b/mediagoblin/tests/test_privileges.py
@@ -21,7 +21,7 @@ from webtest import AppError
from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry
-from mediagoblin.db.models import User, UserBan
+from mediagoblin.db.models import User, LocalUser, UserBan
from mediagoblin.tools import template
from .resources import GOOD_JPG
@@ -64,9 +64,9 @@ class TestPrivilegeFunctionality:
return response, context_data
def query_for_users(self):
- self.admin_user = User.query.filter(User.username==u'alex').first()
- self.mod_user = User.query.filter(User.username==u'meow').first()
- self.user = User.query.filter(User.username==u'natalie').first()
+ self.admin_user = LocalUser.query.filter(LocalUser.username==u'alex').first()
+ self.mod_user = LocalUser.query.filter(LocalUser.username==u'meow').first()
+ self.user = LocalUser.query.filter(LocalUser.username==u'natalie').first()
def testUserBanned(self):
self.login(u'natalie')
diff --git a/mediagoblin/tests/test_reporting.py b/mediagoblin/tests/test_reporting.py
index 6a9fe205..803fc849 100644
--- a/mediagoblin/tests/test_reporting.py
+++ b/mediagoblin/tests/test_reporting.py
@@ -20,8 +20,7 @@ import six
from mediagoblin.tools import template
from mediagoblin.tests.tools import (fixture_add_user, fixture_media_entry,
fixture_add_comment, fixture_add_comment_report)
-from mediagoblin.db.models import (MediaReport, CommentReport, User,
- MediaComment)
+from mediagoblin.db.models import Report, User, LocalUser, TextComment
class TestReportFiling:
@@ -56,8 +55,8 @@ class TestReportFiling:
return response, context_data
def query_for_users(self):
- return (User.query.filter(User.username==u'allie').first(),
- User.query.filter(User.username==u'natalie').first())
+ return (LocalUser.query.filter(LocalUser.username==u'allie').first(),
+ LocalUser.query.filter(LocalUser.username==u'natalie').first())
def testMediaReports(self):
self.login(u'allie')
@@ -80,7 +79,7 @@ class TestReportFiling:
assert response.status == "302 FOUND"
- media_report = MediaReport.query.first()
+ media_report = Report.query.first()
allie_user, natalie_user = self.query_for_users()
assert media_report is not None
@@ -88,7 +87,6 @@ class TestReportFiling:
assert media_report.reporter_id == allie_id
assert media_report.reported_user_id == natalie_user.id
assert media_report.created is not None
- assert media_report.discriminator == 'media_report'
def testCommentReports(self):
self.login(u'allie')
@@ -98,9 +96,11 @@ class TestReportFiling:
media_entry = fixture_media_entry(uploader=natalie_user.id,
state=u'processed')
mid = media_entry.id
- fixture_add_comment(media_entry=mid,
- author=natalie_user.id)
- comment = MediaComment.query.first()
+ fixture_add_comment(
+ media_entry=media_entry,
+ author=natalie_user.id
+ )
+ comment = TextComment.query.first()
comment_uri_slug = '/u/{0}/m/{1}/c/{2}/'.format(natalie_user.username,
media_entry.slug,
@@ -115,7 +115,7 @@ class TestReportFiling:
assert response.status == "302 FOUND"
- comment_report = CommentReport.query.first()
+ comment_report = Report.query.first()
allie_user, natalie_user = self.query_for_users()
assert comment_report is not None
@@ -123,7 +123,6 @@ class TestReportFiling:
assert comment_report.reporter_id == allie_id
assert comment_report.reported_user_id == natalie_user.id
assert comment_report.created is not None
- assert comment_report.discriminator == 'comment_report'
def testArchivingReports(self):
self.login(u'natalie')
@@ -132,14 +131,14 @@ class TestReportFiling:
fixture_add_comment(author=allie_user.id,
comment=u'Comment will be removed')
- test_comment = MediaComment.query.filter(
- MediaComment.author==allie_user.id).first()
+ test_comment = TextComment.query.filter(
+ TextComment.actor==allie_user.id).first()
fixture_add_comment_report(comment=test_comment,
reported_user=allie_user,
report_content=u'Testing Archived Reports #1',
reporter=natalie_user)
- comment_report = CommentReport.query.filter(
- CommentReport.reported_user==allie_user).first()
+ comment_report = Report.query.filter(
+ Report.reported_user==allie_user).first()
assert comment_report.report_content == u'Testing Archived Reports #1'
response, context = self.do_post(
@@ -151,10 +150,10 @@ class TestReportFiling:
assert response.status == "302 FOUND"
allie_user, natalie_user = self.query_for_users()
- archived_report = CommentReport.query.filter(
- CommentReport.reported_user==allie_user).first()
+ archived_report = Report.query.filter(
+ Report.reported_user==allie_user).first()
- assert CommentReport.query.count() != 0
+ assert Report.query.count() != 0
assert archived_report is not None
assert archived_report.report_content == u'Testing Archived Reports #1'
assert archived_report.reporter_id == natalie_id
@@ -164,5 +163,3 @@ class TestReportFiling:
assert archived_report.result == u'''This is a test of archiving reports.
natalie banned user allie indefinitely.
natalie deleted the comment.'''
- assert archived_report.discriminator == 'comment_report'
-
diff --git a/mediagoblin/tests/test_response.py b/mediagoblin/tests/test_response.py
new file mode 100644
index 00000000..7f929155
--- /dev/null
+++ b/mediagoblin/tests/test_response.py
@@ -0,0 +1,65 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import absolute_import, unicode_literals
+
+from werkzeug.wrappers import Request
+
+from ..tools.response import redirect, redirect_obj
+
+class TestRedirect(object):
+ def test_redirect_respects_location(self):
+ """Test that redirect returns a 302 to location specified."""
+ request = Request({})
+ response = redirect(request, location='/test')
+ assert response.status_code == 302
+ assert response.location == '/test'
+
+ def test_redirect_respects_querystring(self):
+ """Test that redirect includes querystring in returned location."""
+ request = Request({})
+ response = redirect(request, location='', querystring='#baz')
+ assert response.location == '#baz'
+
+ def test_redirect_respects_urlgen_args(self):
+ """Test that redirect returns a 302 to location from urlgen args."""
+
+ # Using a mock urlgen here so we're only testing redirect itself. We
+ # could instantiate a url_map and map_adaptor with WSGI environ as per
+ # app.py, but that would really just be testing Werkzeug.
+ def urlgen(endpoint, **kwargs):
+ return '/test?foo=bar'
+
+ request = Request({})
+ request.urlgen = urlgen
+ response = redirect(request, 'test-endpoint', foo='bar')
+ assert response.status_code == 302
+ assert response.location == '/test?foo=bar'
+
+ def test_redirect_obj_calls_url_for_self(self):
+ """Test that redirect_obj returns a 302 to obj's url_for_self()."""
+
+ # Using a mock obj here so that we're only testing redirect_obj itself,
+ # rather than also testing the url_for_self implementation.
+ class Foo(object):
+ def url_for_self(*args, **kwargs):
+ return '/foo'
+
+ request = Request({})
+ request.urlgen = None
+ response = redirect_obj(request, Foo())
+ assert response.status_code == 302
+ assert response.location == '/foo'
diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
index 65c4b3a3..f9031d37 100644
--- a/mediagoblin/tests/test_submission.py
+++ b/mediagoblin/tests/test_submission.py
@@ -35,7 +35,7 @@ Gst.init(None)
from mediagoblin.tests.tools import fixture_add_user
from .media_tools import create_av
from mediagoblin import mg_globals
-from mediagoblin.db.models import MediaEntry, User
+from mediagoblin.db.models import MediaEntry, User, LocalUser
from mediagoblin.db.base import Session
from mediagoblin.tools import template
from mediagoblin.media_types.image import ImageMediaManager
@@ -72,7 +72,7 @@ class TestSubmission:
#### totally stupid.
#### Also if we found a way to make this run it should be a
#### property.
- return User.query.filter(User.username==u'chris').first()
+ return LocalUser.query.filter(LocalUser.username==u'chris').first()
def login(self):
self.test_app.post(
@@ -99,8 +99,14 @@ class TestSubmission:
return {'upload_files': [('file', filename)]}
def check_comments(self, request, media_id, count):
- comments = request.db.MediaComment.query.filter_by(media_entry=media_id)
- assert count == len(list(comments))
+ gmr = request.db.GenericModelReference.query.filter_by(
+ obj_pk=media_id,
+ model_type=request.db.MediaEntry.__tablename__
+ ).first()
+ if gmr is None and count <= 0:
+ return # Yerp it's fine.
+ comments = request.db.Comment.query.filter_by(target_id=gmr.id)
+ assert count == comments.count()
def test_missing_fields(self):
# Test blank form
@@ -153,6 +159,16 @@ class TestSubmission:
# Reload user
assert self.our_user().uploaded == file_size
+ def test_public_id_populated(self):
+ # Upload the image first.
+ response, request = self.do_post({'title': u'Balanced Goblin'},
+ *REQUEST_CONTEXT, do_follow=True,
+ **self.upload_data(GOOD_JPG))
+ media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
+
+ # Now check that the public_id attribute is set.
+ assert media.public_id != None
+
def test_normal_png(self):
self.check_normal_upload(u'Normal upload 2', GOOD_PNG)
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index dec95e83..77a9a86c 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -25,9 +25,9 @@ from paste.deploy import loadapp
from webtest import TestApp
from mediagoblin import mg_globals
-from mediagoblin.db.models import User, MediaEntry, Collection, MediaComment, \
- CommentSubscription, CommentNotification, Privilege, CommentReport, Client, \
- RequestToken, AccessToken, Activity, Generator
+from mediagoblin.db.models import User, LocalUser, MediaEntry, Collection, TextComment, \
+ CommentSubscription, Notification, Privilege, Report, Client, \
+ RequestToken, AccessToken, Activity, Generator, Comment
from mediagoblin.tools import testing
from mediagoblin.init.config import read_mediagoblin_config
from mediagoblin.db.base import Session
@@ -176,9 +176,9 @@ def assert_db_meets_expected(db, expected):
def fixture_add_user(username=u'chris', password=u'toast',
privileges=[], wants_comment_notification=True):
# Reuse existing user or create a new one
- test_user = User.query.filter_by(username=username).first()
+ test_user = LocalUser.query.filter(LocalUser.username==username).first()
if test_user is None:
- test_user = User()
+ test_user = LocalUser()
test_user.username = username
test_user.email = username + u'@example.com'
if password is not None:
@@ -190,8 +190,11 @@ def fixture_add_user(username=u'chris', password=u'toast',
test_user.all_privileges.append(query.one())
test_user.save()
- # Reload
- test_user = User.query.filter_by(username=username).first()
+
+ # Reload - The `with_polymorphic` needs to be there to eagerly load
+ # the attributes on the LocalUser as this can't be done post detachment.
+ user_query = LocalUser.query.with_polymorphic(LocalUser)
+ test_user = user_query.filter(LocalUser.username==username).first()
# ... and detach from session:
Session.expunge(test_user)
@@ -201,12 +204,12 @@ def fixture_add_user(username=u'chris', password=u'toast',
def fixture_comment_subscription(entry, notify=True, send_email=None):
if send_email is None:
- uploader = User.query.filter_by(id=entry.uploader).first()
- send_email = uploader.wants_comment_notification
+ actor = LocalUser.query.filter_by(id=entry.actor).first()
+ send_email = actor.wants_comment_notification
cs = CommentSubscription(
media_entry_id=entry.id,
- user_id=entry.uploader,
+ user_id=entry.actor,
notify=notify,
send_email=send_email)
@@ -219,14 +222,16 @@ def fixture_comment_subscription(entry, notify=True, send_email=None):
return cs
-def fixture_add_comment_notification(entry_id, subject_id, user_id,
+def fixture_add_comment_notification(entry, subject, user,
seen=False):
- cn = CommentNotification(user_id=user_id,
- seen=seen,
- subject_id=subject_id)
+ cn = Notification(
+ user_id=user,
+ seen=seen,
+ )
+ cn.obj = subject
cn.save()
- cn = CommentNotification.query.filter_by(id=cn.id).first()
+ cn = Notification.query.filter_by(id=cn.id).first()
Session.expunge(cn)
@@ -251,7 +256,7 @@ def fixture_media_entry(title=u"Some title", slug=None,
entry = MediaEntry()
entry.title = title
entry.slug = slug
- entry.uploader = uploader
+ entry.actor = uploader
entry.media_type = u'image'
entry.state = state
@@ -275,15 +280,21 @@ def fixture_media_entry(title=u"Some title", slug=None,
return entry
-def fixture_add_collection(name=u"My first Collection", user=None):
+def fixture_add_collection(name=u"My first Collection", user=None,
+ collection_type=Collection.USER_DEFINED_TYPE):
if user is None:
user = fixture_add_user()
- coll = Collection.query.filter_by(creator=user.id, title=name).first()
+ coll = Collection.query.filter_by(
+ actor=user.id,
+ title=name,
+ type=collection_type
+ ).first()
if coll is not None:
return coll
coll = Collection()
- coll.creator = user.id
+ coll.actor = user.id
coll.title = name
+ coll.type = collection_type
coll.generate_slug()
coll.save()
@@ -300,22 +311,27 @@ def fixture_add_comment(author=None, media_entry=None, comment=None):
author = fixture_add_user().id
if media_entry is None:
- media_entry = fixture_media_entry().id
+ media_entry = fixture_media_entry()
if comment is None:
comment = \
'Auto-generated test comment by user #{0} on media #{0}'.format(
author, media_entry)
- comment = MediaComment(author=author,
- media_entry=media_entry,
- content=comment)
+ text_comment = TextComment(
+ actor=author,
+ content=comment
+ )
+ text_comment.save()
- comment.save()
+ comment_link = Comment()
+ comment_link.target = media_entry
+ comment_link.comment = text_comment
+ comment_link.save()
- Session.expunge(comment)
+ Session.expunge(comment_link)
- return comment
+ return text_comment
def fixture_add_comment_report(comment=None, reported_user=None,
reporter=None, created=None, report_content=None):
@@ -335,12 +351,13 @@ def fixture_add_comment_report(comment=None, reported_user=None,
report_content = \
'Auto-generated test report'
- comment_report = CommentReport(comment=comment,
- reported_user = reported_user,
- reporter = reporter,
- created = created,
- report_content=report_content)
-
+ comment_report = Report()
+ comment_report.obj = comment
+ comment_report.reported_user = reported_user
+ comment_report.reporter = reporter
+ comment_report.created = created
+ comment_report.report_content = report_content
+ comment_report.obj = comment
comment_report.save()
Session.expunge(comment_report)
@@ -370,4 +387,4 @@ def fixture_add_activity(obj, verb="post", target=None, generator=None, actor=No
activity.set_target(target)
activity.save()
- return activity \ No newline at end of file
+ return activity