From 30985a9efe4100efcff474020155f480c578765f Mon Sep 17 00:00:00 2001 From: Isaac Bythewood Date: Thu, 10 May 2012 02:34:15 +0000 Subject: [PATCH] Added basic core app tests. --- pinry/core/models.py | 0 pinry/core/tests.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 pinry/core/models.py create mode 100644 pinry/core/tests.py diff --git a/pinry/core/models.py b/pinry/core/models.py new file mode 100644 index 0000000..e69de29 diff --git a/pinry/core/tests.py b/pinry/core/tests.py new file mode 100644 index 0000000..b1f113b --- /dev/null +++ b/pinry/core/tests.py @@ -0,0 +1,82 @@ +from django.utils import unittest +from django.test.client import Client +from django.core.urlresolvers import reverse + + +class HomeTest(unittest.TestCase): + def setUp(self): + self.client = Client() + self.url = reverse('core:home') + + def test_url(self): + self.assertEqual(self.url, '/') + + def test_status_code(self): + response = self.client.get(self.url) + self.assertEqual(response.status_code, 302) + + +class RegisterTest(unittest.TestCase): + def setUp(self): + self.client = Client() + self.url = reverse('core:register') + + def test_url(self): + self.assertEqual(self.url, '/register/') + + def test_status_code(self): + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + + def test_successful_registration(self): + # If 302 was success, if 200 same page registration failed. + response = self.client.post(self.url, { + 'username': 'test_registration_success', + 'password1': 'test_password', + 'password2': 'test_password', + }) + self.assertEqual(response.status_code, 302) + + def test_failed_registration(self): + # If 302 was success, if 200 same page registration failed. + response = self.client.post(self.url, { + 'username': 'test_registration_failed', + 'password1': 'test_password', + 'password2': 'test_wrong_password', + }) + self.assertEqual(response.status_code, 200) + + +class LoginTest(unittest.TestCase): + def setUp(self): + self.client = Client() + self.url = reverse('core:login') + + def test_url(self): + self.assertEqual(self.url, '/login/') + + def test_status_code(self): + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + + +class LogoutTest(unittest.TestCase): + def setUp(self): + self.client = Client() + self.url = reverse('core:logout') + self.client.post(self.url, { + 'username': 'test_user_logout', + 'password1': 'test_password', + 'password2': 'test_password', + }) + + def test_url(self): + self.assertEqual(self.url, '/logout/') + + def test_logout_with_logged_in_user(self): + self.client.post(self.url, { + 'username': 'test_user_logout', + 'password': 'test_password' + }) + response = self.client.get(self.url) + self.assertEqual(response.status_code, 302)