From c0e87ec9d2ff79c98372fe802ac64e35d7e30853 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Tue, 20 Mar 2012 22:30:57 -0400 Subject: [PATCH] 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. --- mediagoblin/tests/test_submission.py | 44 +++++++++++----------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index 65c3bac7..70093b58 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -89,37 +89,27 @@ class TestSubmission: response, form = self.do_post({'title': 'test title'}, *FORM_CONTEXT) assert form.file.errors == [u'You must provide a file.'] - - def test_normal_uploads(self): - # Test JPG - # -------- - response, context = self.do_post({'title': 'Normal upload 1'}, - do_follow=True, - **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') - + def check_url(self, response, path): + assert_equal(urlparse.urlsplit(response.location)[2], path) + + def check_normal_upload(self, title, filename): + response, context = self.do_post({'title': title}, do_follow=True, + **self.upload_data(filename)) + self.check_url(response, '/u/{0}/'.format(self.test_user.username)) + assert_true(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/') + url = '/u/{0}/m/{1}/'.format(self.test_user.username, + title.lower().replace(' ', '-')) + self.test_app.get(url) # ... 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() + self.test_app.get(url) - # Test PNG - # -------- - response, context = self.do_post({'title': 'Normal upload 2'}, - do_follow=True, - **self.upload_data(GOOD_PNG)) - assert_equal( - urlparse.urlsplit(response.location)[2], - '/u/chris/') - assert template.TEMPLATE_TEST_CONTEXT.has_key( - 'mediagoblin/user_pages/user.html') + def test_normal_jpg(self): + self.check_normal_upload('Normal upload 1', GOOD_JPG) + + def test_normal_png(self): + self.check_normal_upload('Normal upload 2', GOOD_PNG) def check_media(self, request, find_data, count=None): media = request.db.MediaEntry.find(find_data) -- 2.25.1