From: Stephen Finucane Date: Mon, 20 Jun 2016 14:07:50 +0000 (+0100) Subject: tests: Clean up 'test_encodings' X-Git-Tag: v2.0.0-rc1~321 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=faf25f233863fcfe556fd6e10b339e72966519a3;p=thirdparty%2Fpatchwork.git tests: Clean up 'test_encodings' * Don't use hardcode routes: use the reverse function instead * Make use of 'create_' helper functions * Remove unneeded 'XXX.objects.delete()' calls (all objects are deleted on teardown of each test) * Include every import on its own line * Use underscore_case, rather than camelCase Signed-off-by: Stephen Finucane Reviewed-by: Andy Doan --- diff --git a/patchwork/tests/test_encodings.py b/patchwork/tests/test_encodings.py index fa5c8895..a7961d69 100644 --- a/patchwork/tests/test_encodings.py +++ b/patchwork/tests/test_encodings.py @@ -13,77 +13,46 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from django.test.client import Client +from django.core.urlresolvers import reverse from django.test import TestCase -from patchwork.models import Patch, Person -from patchwork.tests.utils import defaults, read_patch +from patchwork.tests.utils import create_person +from patchwork.tests.utils import create_patch +from patchwork.tests.utils import read_patch class UTF8PatchViewTest(TestCase): + fixtures = ['default_states'] - patch_filename = '0002-utf-8.patch' - patch_encoding = 'utf-8' def setUp(self): - defaults.project.save() - defaults.patch_author_person.save() - self.patch_content = read_patch(self.patch_filename, - encoding=self.patch_encoding) - self.patch = Patch(project=defaults.project, - msgid='x', name=defaults.patch_name, - submitter=defaults.patch_author_person, - diff=self.patch_content) - self.patch.save() - self.client = Client() + patch_content = read_patch('0002-utf-8.patch', encoding='utf-8') + self.patch = create_patch(diff=patch_content) - def testPatchView(self): - response = self.client.get('/patch/%d/' % self.patch.id) + def test_patch_view(self): + response = self.client.get(reverse( + 'patch-detail', args=[self.patch.id])) self.assertContains(response, self.patch.name) - def testMboxView(self): - response = self.client.get('/patch/%d/mbox/' % self.patch.id) + def test_mbox_view(self): + response = self.client.get(reverse('patch-mbox', args=[self.patch.id])) self.assertEqual(response.status_code, 200) - self.assertTrue(self.patch.diff in - response.content.decode(self.patch_encoding)) + self.assertTrue(self.patch.diff in response.content.decode('utf-8')) - def testRawView(self): - response = self.client.get('/patch/%d/raw/' % self.patch.id) + def test_raw_view(self): + response = self.client.get(reverse('patch-raw', args=[self.patch.id])) self.assertEqual(response.status_code, 200) - self.assertEqual(response.content.decode(self.patch_encoding), - self.patch.diff) - - def tearDown(self): - self.patch.delete() - defaults.patch_author_person.delete() - defaults.project.delete() + self.assertEqual(response.content.decode('utf-8'), self.patch.diff) class UTF8HeaderPatchViewTest(UTF8PatchViewTest): + fixtures = ['default_states'] - patch_filename = '0002-utf-8.patch' - patch_encoding = 'utf-8' - patch_author_name = u'P\xe4tch Author' def setUp(self): - defaults.project.save() - self.patch_author = Person(name=self.patch_author_name, - email=defaults.patch_author_person.email) - self.patch_author.save() - self.patch_content = read_patch(self.patch_filename, - encoding=self.patch_encoding) - self.patch = Patch(project=defaults.project, - msgid='x', name=defaults.patch_name, - submitter=self.patch_author, - diff=self.patch_content) - self.patch.save() - self.client = Client() - - def tearDown(self): - self.patch.delete() - self.patch_author.delete() - defaults.project.delete() + author = create_person(name=u'P\xe4tch Author') + patch_content = read_patch('0002-utf-8.patch', encoding='utf-8') + self.patch = create_patch(submitter=author, diff=patch_content)