Sith/core/tests.py

234 lines
11 KiB
Python
Raw Normal View History

from django.test import SimpleTestCase, Client, TestCase
2015-11-19 10:23:08 +00:00
from django.core.urlresolvers import reverse
2015-11-24 13:01:10 +00:00
from django.contrib.auth.models import Group
2015-11-19 10:23:08 +00:00
2015-11-24 15:09:46 +00:00
from core.models import User
2015-12-02 16:14:47 +00:00
#from core.views.forms import RegisteringForm, LoginForm
2015-11-19 10:23:08 +00:00
"""
to run these tests :
python3 manage.py test
"""
class UserRegistrationTest(TestCase):
2015-11-24 13:01:10 +00:00
def setUp(self):
try:
Group.objects.create(name="root")
except:
pass
2015-11-19 10:23:08 +00:00
def test_register_user_form_ok(self):
"""
Should register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'guy@git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
2015-11-19 10:23:08 +00:00
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_OK' in str(response.content))
def test_register_user_form_fail_password(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'bibou@git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
2015-11-19 10:23:08 +00:00
'password1': 'plop',
'password2': 'plop2',
})
self.assertTrue(response.status_code == 200)
2015-11-19 13:44:48 +00:00
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
2015-11-19 10:23:08 +00:00
def test_register_user_form_fail_email(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'bibou.git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
2015-11-19 10:23:08 +00:00
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
2015-11-19 13:44:48 +00:00
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
2015-11-19 10:23:08 +00:00
def test_register_user_form_fail_missing_name(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': '',
'email': 'bibou@git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
def test_register_user_form_fail_missing_date_of_birth(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': '',
'last_name': 'Carlier',
'email': 'bibou@git.an',
'date_of_birth': '',
2015-11-19 10:23:08 +00:00
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
2015-11-19 13:44:48 +00:00
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
2015-11-19 10:23:08 +00:00
def test_register_user_form_fail_missing_first_name(self):
"""
Should not register a user correctly
"""
c = Client()
response = c.post(reverse('core:register'), {'first_name': '',
'last_name': 'Carlier',
'email': 'bibou@git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
2015-11-19 10:23:08 +00:00
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
2015-11-19 13:44:48 +00:00
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
2015-11-19 10:23:08 +00:00
def test_register_user_form_fail_already_exists(self):
"""
Should not register a user correctly
"""
c = Client()
c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'bibou@git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
2015-11-19 10:23:08 +00:00
'password1': 'plop',
'password2': 'plop',
})
response = c.post(reverse('core:register'), {'first_name': 'Bibou',
'last_name': 'Carlier',
'email': 'bibou@git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
2015-11-19 10:23:08 +00:00
'password1': 'plop',
'password2': 'plop',
})
self.assertTrue(response.status_code == 200)
2015-11-19 13:44:48 +00:00
self.assertTrue('TEST_REGISTER_USER_FORM_FAIL' in str(response.content))
2015-11-18 08:44:06 +00:00
2015-11-19 13:44:48 +00:00
def test_login_success(self):
"""
Should login a user correctly
"""
c = Client()
c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'bibou@git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
2015-11-19 13:44:48 +00:00
'password1': 'plop',
'password2': 'plop',
})
response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'plop'})
2015-12-02 16:14:47 +00:00
self.assertTrue(response.status_code == 302)
#self.assertTrue('Hello, world' in str(response.content))
2015-11-19 13:44:48 +00:00
def test_login_fail(self):
"""
Should not login a user correctly
"""
c = Client()
c.post(reverse('core:register'), {'first_name': 'Guy',
'last_name': 'Carlier',
'email': 'bibou@git.an',
2015-11-22 17:23:21 +00:00
'date_of_birth': '12/6/1942',
2015-11-19 13:44:48 +00:00
'password1': 'plop',
'password2': 'plop',
})
response = c.post(reverse('core:login'), {'username': 'gcarlier', 'password': 'guy'})
self.assertTrue(response.status_code == 200)
2015-12-02 16:14:47 +00:00
self.assertTrue('Please try again' in str(response.content))
class PageHandlingTest(TestCase):
2015-12-02 16:14:47 +00:00
def setUp(self):
try:
Group.objects.create(name="root")
except:
pass
2015-11-24 09:53:16 +00:00
def test_create_page_ok(self):
"""
Should create a page correctly
"""
c = Client()
response = c.post(reverse('core:page_prop', kwargs={'page_name': 'guy'}), {'parent': '',
2015-11-24 09:53:16 +00:00
'name': 'guy',
2015-12-02 16:14:47 +00:00
'owner_group': '1',
2015-11-24 09:53:16 +00:00
})
self.assertTrue(response.status_code == 200)
self.assertTrue('PAGE_SAVED' in str(response.content))
def test_create_child_page_ok(self):
"""
Should create a page correctly
"""
c = Client()
c.post(reverse('core:page_prop', kwargs={'page_name': 'guy'}), {'parent': '',
2015-11-24 09:53:16 +00:00
'name': 'guy',
2015-12-02 16:14:47 +00:00
'owner_group': 1,
2015-11-24 09:53:16 +00:00
})
response = c.post(reverse('core:page_prop', kwargs={'page_name': 'guy/bibou'}), {'parent': '1',
2015-11-24 09:53:16 +00:00
'name': 'bibou',
2015-12-02 16:14:47 +00:00
'owner_group': 1,
2015-11-24 09:53:16 +00:00
})
self.assertTrue(response.status_code == 200)
self.assertTrue('PAGE_SAVED' in str(response.content))
def test_access_child_page_ok(self):
"""
Should display a page correctly
"""
c = Client()
c.post(reverse('core:page_prop', kwargs={'page_name': 'guy'}), {'parent': '',
2015-11-24 09:53:16 +00:00
'name': 'guy',
'title': 'Guy',
'Content': 'Guyéuyuyé',
})
c.post(reverse('core:page_prop', kwargs={'page_name': 'guy/bibou'}), {'parent': '1',
2015-11-24 09:53:16 +00:00
'name': 'bibou',
'title': 'Bibou',
'Content':
'Bibibibiblblblblblbouuuuuuuuu',
})
response = c.get(reverse('core:page', kwargs={'page_name': 'guy/bibou'}))
self.assertTrue(response.status_code == 200)
self.assertTrue('PAGE_FOUND : Bibou' in str(response.content))
def test_access_page_not_found(self):
"""
Should not display a page correctly
"""
c = Client()
response = c.get(reverse('core:page', kwargs={'page_name': 'swagg'}))
self.assertTrue(response.status_code == 200)
2015-12-02 16:14:47 +00:00
self.assertTrue('<a href="/page/swagg/prop">Create it?</a>' in str(response.content))
2015-11-24 13:01:10 +00:00
#TODO: many tests on the pages:
# - renaming a page
# - changing a page's parent --> check that page's children's full_name
# - changing the different groups of the page