# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
import urlparse
import pkg_resources
+import re
from nose.tools import assert_equal, assert_true, assert_false
self.test_user = test_user
+ self.login()
+
+ def login(self):
self.test_app.post(
'/auth/login/', {
'username': u'chris',
'password': 'toast'})
+ def logout(self):
+ self.test_app.get('/auth/logout/')
+
def test_missing_fields(self):
# Test blank form
# ---------------
assert template.TEMPLATE_TEST_CONTEXT.has_key(
'mediagoblin/user_pages/user.html')
+ # Make sure the media view is at least reachable, logged in...
+ self.test_app.get('/u/chris/m/normal-upload-1/')
+ # ... and logged out too.
+ self.logout()
+ self.test_app.get('/u/chris/m/normal-upload-1/')
+ # Log back in for the remaining tests.
+ self.login()
+
# Test PNG
# --------
template.clear_test_template_context()
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/user_pages/user.html']
request = context['request']
media = request.db.MediaEntry.find({'title': 'Balanced Goblin'})[0]
- assert_equal(media['tags'],
+ assert_equal(media.tags,
[{'name': u'yin', 'slug': u'yin'},
{'name': u'yang', 'slug': u'yang'}])
# Does media entry exist?
assert_true(media)
+ # Add a comment, so we can test for its deletion later.
+ get_comments = lambda: list(
+ request.db.MediaComment.find({'media_entry': media._id}))
+ assert_false(get_comments())
+ response = self.test_app.post(
+ request.urlgen('mediagoblin.user_pages.media_post_comment',
+ user=self.test_user.username,
+ media=media._id),
+ {'comment_content': 'i love this test'})
+ response.follow()
+ assert_true(get_comments())
+
# Do not confirm deletion
# ---------------------------------------------------
response = self.test_app.post(
request.db.MediaEntry.find(
{'_id': media._id}).count())
+ # How about the comment?
+ assert_false(get_comments())
+
def test_malicious_uploads(self):
# Test non-suppoerted file with non-supported extension
# -----------------------------------------------------
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html']
form = context['submit_form']
- assert form.file.errors == [u'Invalid file type.']
+ assert re.match(r'^Could not extract any file extension from ".*?"$', str(form.file.errors[0]))
+ assert len(form.file.errors) == 1
# NOTE: The following 2 tests will ultimately fail, but they
# *will* pass the initial form submission step. Instead,
entry = mg_globals.database.MediaEntry.find_one(
{'title': 'Malicious Upload 2'})
- assert_equal(entry['state'], 'failed')
+ assert_equal(entry.state, 'failed')
assert_equal(
- entry['fail_error'],
+ entry.fail_error,
u'mediagoblin.processing:BadMediaFail')
# Test non-supported file with .png extension
entry = mg_globals.database.MediaEntry.find_one(
{'title': 'Malicious Upload 3'})
- assert_equal(entry['state'], 'failed')
+ assert_equal(entry.state, 'failed')
assert_equal(
- entry['fail_error'],
+ entry.fail_error,
u'mediagoblin.processing:BadMediaFail')