Fix tests

This commit is contained in:
Skia 2016-08-02 22:20:06 +02:00
parent 7002139176
commit db712c86b8
4 changed files with 34 additions and 25 deletions

View File

@ -2,49 +2,56 @@ from django.test import TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.management import call_command from django.core.management import call_command
from core.models import User
from club.models import Club
# Create your tests here. # Create your tests here.
class ClubTest(TestCase): class ClubTest(TestCase):
def setUp(self): def setUp(self):
call_command("populate") call_command("populate")
self.skia = User.objects.filter(username="skia").first()
self.rbatsbak = User.objects.filter(username="rbatsbak").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):
self.client.login(username='root', password='plop') self.client.login(username='root', password='plop')
self.client.post(reverse("club:club_members", kwargs={"club_id":4}), {"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":4})) 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("<li>Woenzel&#39;UT - skia - Responsable info</li>" in str(response.content)) self.assertTrue("skia - Responsable info</li>" 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":4}), {"user": 3, "role": 3}) response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 3, "role": 3})
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("User must be subscriber to take part to a club" 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":4})) response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
self.assertFalse("<li>Woenzel&#39;UT - guy - Responsable info</li>" in str(response.content)) self.assertFalse("guy - Responsable info</li>" 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":4}), {"user": 2, "role": 3}) self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 2, "role": 3})
response = self.client.get(reverse("club:club_members", kwargs={"club_id":4})) response = self.client.get(reverse("club:club_members", kwargs={"club_id":self.bdf.id}))
self.assertTrue("<li>Woenzel&#39;UT - skia - Responsable info</li>" in str(response.content)) self.assertTrue("skia - Responsable info</li>" in str(response.content))
response = self.client.post(reverse("club:club_members", kwargs={"club_id":4}), {"user": 2, "role": 4}) response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 2, "role": 4})
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertFalse("<li>Woenzel&#39;UT - skia - Secrétaire</li>" in str(response.content)) self.assertFalse("skia - Secrétaire</li>" 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":4}), {"user": 2, "role": 10}) self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 2, "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":4}), {"user": 7, "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":4})) 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("<li>Woenzel&#39;UT - rbatsbak - Vice-Pr" in str(response.content)) self.assertTrue("rbatsbak - Vice-Pr" 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":4}), {"user": 7, "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":4}), {"user": 4, "role": 10}) response = self.client.post(reverse("club:club_members", kwargs={"club_id":self.bdf.id}), {"user": 4, "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

@ -447,7 +447,10 @@ class Page(models.Model):
return '/'.join([self.parent.get_full_name(), self.name]) return '/'.join([self.parent.get_full_name(), self.name])
def get_display_name(self): def get_display_name(self):
return self.revisions.last().title try:
return self.revisions.last().title
except:
return self.name
class PageRev(models.Model): class PageRev(models.Model):
""" """

View File

@ -13,7 +13,7 @@
<p>{% trans %}Born: {% endtrans %}{{ profile.date_of_birth|date("d/m/Y") }}</p> <p>{% trans %}Born: {% endtrans %}{{ profile.date_of_birth|date("d/m/Y") }}</p>
</div> </div>
{% if user.membership.filter(end_date=None).exists() %} {% if user.membership.filter(end_date=None).exists() or user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) %}
{# if the user is member of a club, he can view the subscription state #} {# if the user is member of a club, he can view the subscription state #}
<p> <p>
{% if get_subscriber(profile).is_subscribed() %} {% if get_subscriber(profile).is_subscribed() %}

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('Please try again' in str(response.content)) self.assertTrue('<ul class="errorlist nonfield">' in str(response.content))
class PageHandlingTest(TestCase): class PageHandlingTest(TestCase):
def setUp(self): def setUp(self):
@ -188,7 +188,7 @@ class PageHandlingTest(TestCase):
}) })
response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy'})) response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy'}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("<strong>guy</strong>" in str(response.content)) self.assertTrue('<a href="/page/guy/hist">' in str(response.content))
def test_create_child_page_ok(self): def test_create_child_page_ok(self):
""" """
@ -206,7 +206,7 @@ class PageHandlingTest(TestCase):
}) })
response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy/bibou'})) response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy/bibou'}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue("<strong>guy/bibou</strong>" in str(response.content)) self.assertTrue('<a href="/page/guy/bibou/">' in str(response.content))
def test_access_child_page_ok(self): def test_access_child_page_ok(self):
""" """
@ -227,7 +227,6 @@ class PageHandlingTest(TestCase):
}) })
response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy/bibou'})) response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy/bibou'}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
#self.assertTrue('PAGE_FOUND : Bibou' in str(response.content))
def test_access_page_not_found(self): def test_access_page_not_found(self):
""" """
@ -235,7 +234,7 @@ class PageHandlingTest(TestCase):
""" """
response = self.client.get(reverse('core:page', kwargs={'page_name': 'swagg'})) response = self.client.get(reverse('core:page', kwargs={'page_name': 'swagg'}))
self.assertTrue(response.status_code == 200) self.assertTrue(response.status_code == 200)
self.assertTrue('<a href="/page/create?page=swagg">Create it?</a>' in str(response.content)) self.assertTrue('<a href="/page/create?page=swagg">' in str(response.content))
def test_create_page_markdown_safe(self): def test_create_page_markdown_safe(self):
""" """