Fix tests

This commit is contained in:
Skia 2016-11-06 11:36:54 +01:00
parent 59f5917b8c
commit 20ff409547
3 changed files with 13 additions and 11 deletions

View File

@ -12,6 +12,7 @@ class ClubTest(TestCase):
call_command("populate") call_command("populate")
self.skia = User.objects.filter(username="skia").first() self.skia = User.objects.filter(username="skia").first()
self.rbatsbak = User.objects.filter(username="rbatsbak").first() self.rbatsbak = User.objects.filter(username="rbatsbak").first()
self.guy = User.objects.filter(username="guy").first()
self.bdf = Club.objects.filter(unix_name="bdf").first() self.bdf = Club.objects.filter(unix_name="bdf").first()
def test_create_add_user_to_club_from_root_ok(self): def test_create_add_user_to_club_from_root_ok(self):
@ -19,39 +20,39 @@ class ClubTest(TestCase):
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 3}) self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 3})
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id})) response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("skia - Responsable info</li>" in str(response.content)) self.assertTrue("S&#39; Kia</a></td>\\n <td>Responsable info</td>" in str(response.content))
def test_create_add_user_to_club_from_root_fail_not_subscriber(self): def test_create_add_user_to_club_from_root_fail_not_subscriber(self):
self.client.login(username='root', password='plop') self.client.login(username='root', password='plop')
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 3, "role": 3}) response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.guy.id, "role": 3})
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('<ul class="errorlist nonfield"><li>' in str(response.content)) self.assertTrue('<ul class="errorlist nonfield"><li>' in str(response.content))
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id})) response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
self.assertFalse("guy - Responsable info</li>" in str(response.content)) self.assertFalse("Guy Carlier</a></td>\\n <td>Responsable info</td>" in str(response.content))
def test_create_add_user_to_club_from_root_fail_already_in_club(self): def test_create_add_user_to_club_from_root_fail_already_in_club(self):
self.client.login(username='root', password='plop') self.client.login(username='root', password='plop')
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 2, "role": 3}) self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 3})
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id})) response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
self.assertTrue("skia - Responsable info</li>" in str(response.content)) self.assertTrue("S&#39; Kia</a></td>\\n <td>Responsable info</td>" in str(response.content))
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 2, "role": 4}) response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 4})
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertFalse("skia - Secrétaire</li>" in str(response.content)) self.assertFalse("S&#39; Kia</a></td>\\n <td>Secrétaire</td>" in str(response.content))
def test_create_add_user_to_club_from_skia_ok(self): def test_create_add_user_to_club_from_skia_ok(self):
self.client.login(username='root', password='plop') self.client.login(username='root', password='plop')
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 2, "role": 10}) self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 10})
self.client.login(username='skia', password='plop') self.client.login(username='skia', password='plop')
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.rbatsbak.id, "role": 9}) self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.rbatsbak.id, "role": 9})
response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id})) response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("rbatsbak - Vice-Pr" in str(response.content)) self.assertTrue("""Richard Batsbak</a></td>\\n <td>Vice-Pr\\xc3\\xa9sident</td>""" in str(response.content))
def test_create_add_user_to_club_from_richard_fail(self): def test_create_add_user_to_club_from_richard_fail(self):
self.client.login(username='root', password='plop') self.client.login(username='root', password='plop')
self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.rbatsbak.id, "role": 3}) self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.rbatsbak.id, "role": 3})
self.client.login(username='rbatsbak', password='plop') self.client.login(username='rbatsbak', password='plop')
response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 4, "role": 10}) response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": self.skia.id, "role": 10})
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("<li>You do not have the permission to do that</li>" in str(response.content)) self.assertTrue("<li>You do not have the permission to do that</li>" in str(response.content))

View File

@ -146,6 +146,7 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, UpdateView):
request.user.is_root): request.user.is_root):
return self.form_valid(form) return self.form_valid(form)
else: else:
form.add_error(None, _("You do not have the permission to do that"))
return self.form_invalid(form) return self.form_invalid(form)
else: else:
return self.form_invalid(form) return self.form_invalid(form)

View File

@ -161,7 +161,7 @@ class UserRegistrationTest(TestCase):
}) })
response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'guy'}) response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'guy'})
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('<ul class="errorlist nonfield">' in str(response.content)) self.assertTrue("""<p>Votre nom d\\'utilisateur et votre mot de passe ne correspondent pas. Merci de r\\xc3\\xa9essayer.</p>""" in str(response.content))
class PageHandlingTest(TestCase): class PageHandlingTest(TestCase):
def setUp(self): def setUp(self):