From 6819aa726422d42f7d396495085adb8640406ae6 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 23 May 2018 10:38:56 +0200 Subject: [PATCH] Add test for unsupported image format (tif) and add additional OpenID test --- ivatar/ivataraccount/test_views.py | 78 +++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/ivatar/ivataraccount/test_views.py b/ivatar/ivataraccount/test_views.py index e62c8c9..2466b2c 100644 --- a/ivatar/ivataraccount/test_views.py +++ b/ivatar/ivataraccount/test_views.py @@ -588,7 +588,9 @@ class Tester(TestCase): url = reverse('upload_photo') # rb => Read binary with open(os.path.join( - settings.STATIC_ROOT, 'img', 'broken.gif'), 'rb') as photo: + settings.STATIC_ROOT, + 'img', + 'broken.gif'), 'rb') as photo: response = self.client.post(url, { 'photo': photo, 'not_porn': True, @@ -602,6 +604,27 @@ class Tester(TestCase): self.user.photo_set.first().format, 'gif', 'Format must be gif, since we uploaded a GIF!') + def test_upload_unsupported_tif_image(self): + ''' + Test if unsupported format is correctly detected + ''' + self.login() + url = reverse('upload_photo') + # rb => Read binary + with open(os.path.join( + settings.STATIC_ROOT, + 'img', + 'hackergotchi_test.tif'), 'rb') as photo: + response = self.client.post(url, { + 'photo': photo, + 'not_porn': True, + 'can_distribute': True, + }, follow=True) + self.assertEqual( + str(list(response.context[0]['messages'])[0]), + 'Invalid Format', + 'Invalid img data should return error message!') + def test_automatic_photo_assign_to_confirmed_mail(self): self.test_upload_image() self.test_confirm_email() @@ -733,3 +756,56 @@ class Tester(TestCase): confirmed.openid = unconfirmed.openid confirmed.save() unconfirmed.delete() + + def test_add_openid_twice(self): + ''' + Test if adding OpenID a second time works - it shouldn't + ''' + self.login() + # Get page + response = self.client.get(reverse('add_openid')) + self.assertEqual( + response.status_code, + 200, + 'Fetching page to add OpenID fails?') + + response = self.client.post( + reverse('add_openid'), { + # Whohu, static... :-[ + 'openid': 'http://oliver.id.fedoraproject.org', + }, + ) + self.assertEqual(response.status_code, 302, 'OpenID must redirect') + + response = self.client.post( + reverse('add_openid'), { + # Whohu, static... :-[ + 'openid': 'http://oliver.id.fedoraproject.org', + }, + ) + self.assertEqual(response.status_code, 302, 'OpenID must redirect') + self.assertEqual( + self.user.unconfirmedopenid_set.count(), + 1, 'There must only be one unconfirmed ID!') + + # Manual confirm, since testing is _really_ hard! + unconfirmed = self.user.unconfirmedopenid_set.first() + confirmed = ConfirmedOpenId() + confirmed.user = unconfirmed.user + confirmed.ip_address = '127.0.0.1' + confirmed.openid = unconfirmed.openid + confirmed.save() + unconfirmed.delete() + + # Try adding it again - although already confirmed + response = self.client.post( + reverse('add_openid'), { + # Whohu, static... :-[ + 'openid': 'http://oliver.id.fedoraproject.org', + }, + ) + self.assertEqual(response.status_code, 302, 'OpenID must redirect') + self.assertEqual( + self.user.unconfirmedopenid_set.count(), + 0, 'There must be no unconfirmed ID, since we tried adding an\ + already confirmed ID!')