Refactor normal upload tests.

This is nice because it means we do *all* the normal sanity tests for *all*
the normal uploads.  check_url() can be used in other tests too.
This commit is contained in:
Brett Smith 2012-03-20 22:30:57 -04:00
parent 77445d13ad
commit c0e87ec9d2

View File

@ -89,37 +89,27 @@ class TestSubmission:
response, form = self.do_post({'title': 'test title'}, *FORM_CONTEXT) response, form = self.do_post({'title': 'test title'}, *FORM_CONTEXT)
assert form.file.errors == [u'You must provide a file.'] assert form.file.errors == [u'You must provide a file.']
def check_url(self, response, path):
assert_equal(urlparse.urlsplit(response.location)[2], path)
def test_normal_uploads(self): def check_normal_upload(self, title, filename):
# Test JPG response, context = self.do_post({'title': title}, do_follow=True,
# -------- **self.upload_data(filename))
response, context = self.do_post({'title': 'Normal upload 1'}, self.check_url(response, '/u/{0}/'.format(self.test_user.username))
do_follow=True, assert_true(context.has_key('mediagoblin/user_pages/user.html'))
**self.upload_data(GOOD_JPG))
assert_equal(
urlparse.urlsplit(response.location)[2],
'/u/chris/')
assert template.TEMPLATE_TEST_CONTEXT.has_key(
'mediagoblin/user_pages/user.html')
# Make sure the media view is at least reachable, logged in... # Make sure the media view is at least reachable, logged in...
self.test_app.get('/u/chris/m/normal-upload-1/') url = '/u/{0}/m/{1}/'.format(self.test_user.username,
title.lower().replace(' ', '-'))
self.test_app.get(url)
# ... and logged out too. # ... and logged out too.
self.logout() self.logout()
self.test_app.get('/u/chris/m/normal-upload-1/') self.test_app.get(url)
# Log back in for the remaining tests.
self.login()
# Test PNG def test_normal_jpg(self):
# -------- self.check_normal_upload('Normal upload 1', GOOD_JPG)
response, context = self.do_post({'title': 'Normal upload 2'},
do_follow=True, def test_normal_png(self):
**self.upload_data(GOOD_PNG)) self.check_normal_upload('Normal upload 2', GOOD_PNG)
assert_equal(
urlparse.urlsplit(response.location)[2],
'/u/chris/')
assert template.TEMPLATE_TEST_CONTEXT.has_key(
'mediagoblin/user_pages/user.html')
def check_media(self, request, find_data, count=None): def check_media(self, request, find_data, count=None):
media = request.db.MediaEntry.find(find_data) media = request.db.MediaEntry.find(find_data)