Mercurial > public > sg101
changeset 744:8789299c75b1
Django 1.6: test discovery as per unittest.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 29 Dec 2013 14:45:26 -0600 (2013-12-29) |
parents | 66d46d31d543 |
children | bace7db5678c |
files | accounts/tests/__init__.py accounts/tests/test_views.py accounts/tests/view_tests.py antispam/tests/__init__.py antispam/tests/test_utils.py antispam/tests/utils_tests.py bio/tests/__init__.py bio/tests/form_tests.py bio/tests/test_forms.py bio/tests/test_views.py bio/tests/view_tests.py contests/tests/__init__.py contests/tests/model_tests.py contests/tests/test_models.py contests/tests/test_views.py contests/tests/view_tests.py forums/tests/__init__.py forums/tests/test_views.py forums/tests/view_tests.py legacy/tests.py polls/tests/__init__.py polls/tests/test_views.py polls/tests/view_tests.py potd/tests/__init__.py potd/tests/test_tools.py potd/tests/tools_tests.py ygroup/tests.py |
diffstat | 27 files changed, 1151 insertions(+), 1179 deletions(-) [+] |
line wrap: on
line diff
--- a/accounts/tests/__init__.py Sun Dec 29 13:45:49 2013 -0600 +++ b/accounts/tests/__init__.py Sun Dec 29 14:45:26 2013 -0600 @@ -1,1 +0,0 @@ -from view_tests import *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accounts/tests/test_views.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,292 @@ +""" +View tests for the accounts application. + +""" +import datetime + +from django.test import TestCase +from django.core.urlresolvers import reverse +from django.core import mail +from django.contrib.auth.models import User +from django.contrib.auth.hashers import check_password + +from accounts.models import PendingUser +from accounts.models import IllegalUsername +from accounts.models import IllegalEmail + + +class RegistrationTest(TestCase): + + def setUp(self): + u = User.objects.create_user('existing_user', 'existing_user@example.com', 'pw') + u.save() + + # a 2nd user has the same email as another + u = User.objects.create_user('existing_user2', 'existing_user@example.com', 'pw') + u.save() + + PendingUser.objects.create(username='pending_user', + email='pending_user@example.com', + password='pw', + date_joined=datetime.datetime.now(), + key='key') + + IllegalUsername.objects.create(username='illegalusername') + IllegalEmail.objects.create(email='illegal@example.com') + + def test_get_view(self): + """ + Test a simple get of the registration view + + """ + response = self.client.get(reverse('accounts-register')) + self.assertEqual(response.status_code, 200) + + def test_existing_user(self): + """ + Ensure we can't register with an existing username. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'existing_user', + 'email': 'test@example.com', + 'password1': 'my_password', + 'password2': 'my_password', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': '', + }) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'A user with that username already exists') + + def test_pending_user(self): + """ + Ensure we can't register with a pending username. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'pending_user', + 'email': 'test@example.com', + 'password1': 'my_password', + 'password2': 'my_password', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': '', + }) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'A pending user with that username already exists') + + def test_illegal_username(self): + """ + Ensure we can't register with a banned username. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'illegalusername', + 'email': 'test@example.com', + 'password1': 'my_password', + 'password2': 'my_password', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': '', + }) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'That username is not allowed') + + def test_duplicate_existing_email(self): + """ + Ensure we can't register with a duplicate email address. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'a_new_user', + 'email': 'existing_user@example.com', + 'password1': 'my_password', + 'password2': 'my_password', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': '', + }) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'A user with that email address already exists') + + def test_duplicate_pending_email(self): + """ + Ensure we can't register with a duplicate email address. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'a_new_user', + 'email': 'pending_user@example.com', + 'password1': 'my_password', + 'password2': 'my_password', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': '', + }) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'A pending user with that email address already exists') + + def test_illegal_email(self): + """ + Ensure we can't register with a banned email address. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'a_new_user', + 'email': 'illegal@example.com', + 'password1': 'my_password', + 'password2': 'my_password', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': '', + }) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'That email address is not allowed') + + def test_password_match(self): + """ + Ensure the passwords match. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'a_new_user', + 'email': 'test@example.com', + 'password1': 'my_password', + 'password2': 'my_password_doesnt match', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': '', + }) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, "The two password fields didn't match") + + def test_question1(self): + """ + Ensure our anti-spam question is answered. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'a_new_user', + 'email': 'test@example.com', + 'password1': 'my_password', + 'password2': 'my_password_doesnt match', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': 'huh', + 'question2': '', + }) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Incorrect answer to our anti-spam question") + + def test_question2(self): + """ + Ensure our honeypot question check works. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'a_new_user', + 'email': 'test@example.com', + 'password1': 'my_password', + 'password2': 'my_password_doesnt match', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': 'non blank', + }) + + self.assertEqual(response.status_code, 200) + + def test_success(self): + """ + Ensure we can successfully register. + + """ + response = self.client.post(reverse('accounts-register'), { + 'username': 'a_new_user', + 'email': 'test@example.com', + 'password1': 'my_password', + 'password2': 'my_password', + 'agree_age': 'on', + 'agree_tos': 'on', + 'agree_privacy': 'on', + 'question1': '101', + 'question2': '', + }) + + self.assertEqual(response.status_code, 302) + + try: + pending = PendingUser.objects.get(username='a_new_user') + except PendingUser.DoesNotExist: + self.fail("PendingUser was not created") + + self.assertEqual(pending.email, 'test@example.com') + self.assertTrue(datetime.datetime.now() - pending.date_joined < + datetime.timedelta(minutes=1)) + self.assertTrue(check_password('my_password', pending.password)) + + +class ForgotUsernameTest(TestCase): + + def setUp(self): + u = User.objects.create_user('existing_user', 'existing_user@example.com', 'pw') + u.save() + + def test_get_query_view(self): + """Test a simple get of the username query view""" + response = self.client.get(reverse('accounts-username_query')) + self.assertEqual(response.status_code, 200) + + def test_get_username_sent_view(self): + """Test a simple get of the username sent view""" + response = self.client.get(reverse('accounts-username_sent')) + self.assertEqual(response.status_code, 200) + + def test_invalid_email(self): + """Test form submittal of unknown email address.""" + response = self.client.post(reverse('accounts-username_query'), { + 'email': 'bad_address@example.com', + }, + follow=True) + + self.assertRedirects(response, reverse('accounts-username_sent')) + + self.assertEqual(len(mail.outbox), 0) + + def test_valid_email(self): + """Test form submittal of valid email address.""" + response = self.client.post(reverse('accounts-username_query'), { + 'email': 'existing_user@example.com', + }, + follow=True) + + self.assertRedirects(response, reverse('accounts-username_sent')) + + self.assertEqual(len(mail.outbox), 1) + if len(mail.outbox): + self.assertTrue(mail.outbox[0].subject.startswith('Forgotten username'))
--- a/accounts/tests/view_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,292 +0,0 @@ -""" -View tests for the accounts application. - -""" -import datetime - -from django.test import TestCase -from django.core.urlresolvers import reverse -from django.core import mail -from django.contrib.auth.models import User -from django.contrib.auth.hashers import check_password - -from accounts.models import PendingUser -from accounts.models import IllegalUsername -from accounts.models import IllegalEmail - - -class RegistrationTest(TestCase): - - def setUp(self): - u = User.objects.create_user('existing_user', 'existing_user@example.com', 'pw') - u.save() - - # a 2nd user has the same email as another - u = User.objects.create_user('existing_user2', 'existing_user@example.com', 'pw') - u.save() - - PendingUser.objects.create(username='pending_user', - email='pending_user@example.com', - password='pw', - date_joined=datetime.datetime.now(), - key='key') - - IllegalUsername.objects.create(username='illegalusername') - IllegalEmail.objects.create(email='illegal@example.com') - - def test_get_view(self): - """ - Test a simple get of the registration view - - """ - response = self.client.get(reverse('accounts-register')) - self.assertEqual(response.status_code, 200) - - def test_existing_user(self): - """ - Ensure we can't register with an existing username. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'existing_user', - 'email': 'test@example.com', - 'password1': 'my_password', - 'password2': 'my_password', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': '', - }) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, 'A user with that username already exists') - - def test_pending_user(self): - """ - Ensure we can't register with a pending username. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'pending_user', - 'email': 'test@example.com', - 'password1': 'my_password', - 'password2': 'my_password', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': '', - }) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, 'A pending user with that username already exists') - - def test_illegal_username(self): - """ - Ensure we can't register with a banned username. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'illegalusername', - 'email': 'test@example.com', - 'password1': 'my_password', - 'password2': 'my_password', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': '', - }) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, 'That username is not allowed') - - def test_duplicate_existing_email(self): - """ - Ensure we can't register with a duplicate email address. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'a_new_user', - 'email': 'existing_user@example.com', - 'password1': 'my_password', - 'password2': 'my_password', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': '', - }) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, 'A user with that email address already exists') - - def test_duplicate_pending_email(self): - """ - Ensure we can't register with a duplicate email address. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'a_new_user', - 'email': 'pending_user@example.com', - 'password1': 'my_password', - 'password2': 'my_password', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': '', - }) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, 'A pending user with that email address already exists') - - def test_illegal_email(self): - """ - Ensure we can't register with a banned email address. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'a_new_user', - 'email': 'illegal@example.com', - 'password1': 'my_password', - 'password2': 'my_password', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': '', - }) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, 'That email address is not allowed') - - def test_password_match(self): - """ - Ensure the passwords match. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'a_new_user', - 'email': 'test@example.com', - 'password1': 'my_password', - 'password2': 'my_password_doesnt match', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': '', - }) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, "The two password fields didn't match") - - def test_question1(self): - """ - Ensure our anti-spam question is answered. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'a_new_user', - 'email': 'test@example.com', - 'password1': 'my_password', - 'password2': 'my_password_doesnt match', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': 'huh', - 'question2': '', - }) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, "Incorrect answer to our anti-spam question") - - def test_question2(self): - """ - Ensure our honeypot question check works. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'a_new_user', - 'email': 'test@example.com', - 'password1': 'my_password', - 'password2': 'my_password_doesnt match', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': 'non blank', - }) - - self.assertEqual(response.status_code, 200) - - def test_success(self): - """ - Ensure we can successfully register. - - """ - response = self.client.post(reverse('accounts-register'), { - 'username': 'a_new_user', - 'email': 'test@example.com', - 'password1': 'my_password', - 'password2': 'my_password', - 'agree_age': 'on', - 'agree_tos': 'on', - 'agree_privacy': 'on', - 'question1': '101', - 'question2': '', - }) - - self.assertEqual(response.status_code, 302) - - try: - pending = PendingUser.objects.get(username='a_new_user') - except PendingUser.DoesNotExist: - self.fail("PendingUser was not created") - - self.assertEqual(pending.email, 'test@example.com') - self.assertTrue(datetime.datetime.now() - pending.date_joined < - datetime.timedelta(minutes=1)) - self.assertTrue(check_password('my_password', pending.password)) - - -class ForgotUsernameTest(TestCase): - - def setUp(self): - u = User.objects.create_user('existing_user', 'existing_user@example.com', 'pw') - u.save() - - def test_get_query_view(self): - """Test a simple get of the username query view""" - response = self.client.get(reverse('accounts-username_query')) - self.assertEqual(response.status_code, 200) - - def test_get_username_sent_view(self): - """Test a simple get of the username sent view""" - response = self.client.get(reverse('accounts-username_sent')) - self.assertEqual(response.status_code, 200) - - def test_invalid_email(self): - """Test form submittal of unknown email address.""" - response = self.client.post(reverse('accounts-username_query'), { - 'email': 'bad_address@example.com', - }, - follow=True) - - self.assertRedirects(response, reverse('accounts-username_sent')) - - self.assertEqual(len(mail.outbox), 0) - - def test_valid_email(self): - """Test form submittal of valid email address.""" - response = self.client.post(reverse('accounts-username_query'), { - 'email': 'existing_user@example.com', - }, - follow=True) - - self.assertRedirects(response, reverse('accounts-username_sent')) - - self.assertEqual(len(mail.outbox), 1) - if len(mail.outbox): - self.assertTrue(mail.outbox[0].subject.startswith('Forgotten username'))
--- a/antispam/tests/__init__.py Sun Dec 29 13:45:49 2013 -0600 +++ b/antispam/tests/__init__.py Sun Dec 29 14:45:26 2013 -0600 @@ -1,1 +0,0 @@ -from utils_tests import *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/antispam/tests/test_utils.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,115 @@ +""" +Tests for the antispam application. + +""" +import datetime + +from django.test import TestCase +from django.contrib.auth.models import User +from django.contrib.contenttypes.models import ContentType +from django.core.cache import cache + +from antispam import SPAM_PHRASE_KEY +from antispam.models import SpamPhrase +from antispam.utils import contains_spam, deactivate_spammer + +from comments.models import Comment +from polls.models import Poll +from elsewhere.models import WebsiteProfile +from shoutbox.models import Shout +from bio.models import STA_SPAMMER + + +class AntispamCase(TestCase): + + def test_no_phrases(self): + """ + Tests that an empty spam phrase table works. + + """ + cache.delete(SPAM_PHRASE_KEY) + self.assertFalse(contains_spam("Here is some random text.")) + + def test_phrases(self): + """ + Simple test of some phrases. + + """ + SpamPhrase.objects.create(phrase="grytner") + SpamPhrase.objects.create(phrase="allday.ru") + SpamPhrase.objects.create(phrase="stefa.pl") + + self.assert_(contains_spam("grytner")) + self.assert_(contains_spam("11grytner")) + self.assert_(contains_spam("11grytner>")) + self.assert_(contains_spam("1djkl jsd stefa.pl")) + self.assert_(contains_spam("1djkl jsd <stefa.pl---sd8")) + self.assert_(contains_spam("1dsdjallday.rukl jsd <stefa.pl---sd8")) + self.assert_(contains_spam(" 1djallday.rukl")) + self.assertFalse(contains_spam("this one is spam free.")) + + def test_deactivate_spammer(self): + """ + Test the deactivate_spammer() function. + + """ + user = User.objects.create_user('spammer_guy', '', 'password') + user.save() + + profile = user.get_profile() + profile.location = 'Spamville' + profile.country = 'US' + profile.birthday = datetime.date.today() + profile.occupation = 'Spammer' + profile.interests = 'Spamming websites' + profile.profile_text = 'I spam a lot.' + profile.signature = 'I spammed you!' + profile.save() + + now=datetime.datetime.now() + + # create a poll item to comment on + poll = Poll(start_date=now, + end_date=now, + is_enabled=True, + question='?') + poll.save() + + comment = Comment( + content_type=ContentType.objects.get_for_model(poll), + object_id=poll.pk, + user=user, + comment='Spam Spam Spam', + ip_address='127.0.0.1', + is_public=True, + is_removed=False) + comment.save() + + website = WebsiteProfile(user=user, name='spam', url='spam') + website.save() + + shout = Shout(user=user, shout_date=now, shout='spam') + shout.save() + + deactivate_spammer(user) + + profile = user.get_profile() + self.assertFalse(profile.location) + self.assertFalse(profile.country) + self.assertIsNone(profile.birthday) + self.assertFalse(profile.occupation) + self.assertFalse(profile.interests) + self.assertFalse(profile.profile_text) + self.assertFalse(profile.profile_html) + self.assertFalse(profile.signature) + self.assertFalse(profile.signature_html) + self.assertEqual(profile.status, STA_SPAMMER) + + status_date = datetime.date(year=profile.status_date.year, + month=profile.status_date.month, + day=profile.status_date.day) + self.assertEqual(status_date, datetime.date.today()) + + self.assertEqual(Comment.objects.filter(user=user).count(), 0) + self.assertEqual(WebsiteProfile.objects.filter(user=user).count(), 0) + self.assertEqual(Shout.objects.filter(user=user).count(), 0)
--- a/antispam/tests/utils_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -""" -Tests for the antispam application. - -""" -import datetime - -from django.test import TestCase -from django.contrib.auth.models import User -from django.contrib.contenttypes.models import ContentType -from django.core.cache import cache - -from antispam import SPAM_PHRASE_KEY -from antispam.models import SpamPhrase -from antispam.utils import contains_spam, deactivate_spammer - -from comments.models import Comment -from polls.models import Poll -from elsewhere.models import WebsiteProfile -from shoutbox.models import Shout -from bio.models import STA_SPAMMER - - -class AntispamCase(TestCase): - - def test_no_phrases(self): - """ - Tests that an empty spam phrase table works. - - """ - cache.delete(SPAM_PHRASE_KEY) - self.assertFalse(contains_spam("Here is some random text.")) - - def test_phrases(self): - """ - Simple test of some phrases. - - """ - SpamPhrase.objects.create(phrase="grytner") - SpamPhrase.objects.create(phrase="allday.ru") - SpamPhrase.objects.create(phrase="stefa.pl") - - self.assert_(contains_spam("grytner")) - self.assert_(contains_spam("11grytner")) - self.assert_(contains_spam("11grytner>")) - self.assert_(contains_spam("1djkl jsd stefa.pl")) - self.assert_(contains_spam("1djkl jsd <stefa.pl---sd8")) - self.assert_(contains_spam("1dsdjallday.rukl jsd <stefa.pl---sd8")) - self.assert_(contains_spam(" 1djallday.rukl")) - self.assertFalse(contains_spam("this one is spam free.")) - - def test_deactivate_spammer(self): - """ - Test the deactivate_spammer() function. - - """ - user = User.objects.create_user('spammer_guy', '', 'password') - user.save() - - profile = user.get_profile() - profile.location = 'Spamville' - profile.country = 'US' - profile.birthday = datetime.date.today() - profile.occupation = 'Spammer' - profile.interests = 'Spamming websites' - profile.profile_text = 'I spam a lot.' - profile.signature = 'I spammed you!' - profile.save() - - now=datetime.datetime.now() - - # create a poll item to comment on - poll = Poll(start_date=now, - end_date=now, - is_enabled=True, - question='?') - poll.save() - - comment = Comment( - content_type=ContentType.objects.get_for_model(poll), - object_id=poll.pk, - user=user, - comment='Spam Spam Spam', - ip_address='127.0.0.1', - is_public=True, - is_removed=False) - comment.save() - - website = WebsiteProfile(user=user, name='spam', url='spam') - website.save() - - shout = Shout(user=user, shout_date=now, shout='spam') - shout.save() - - deactivate_spammer(user) - - profile = user.get_profile() - self.assertFalse(profile.location) - self.assertFalse(profile.country) - self.assertIsNone(profile.birthday) - self.assertFalse(profile.occupation) - self.assertFalse(profile.interests) - self.assertFalse(profile.profile_text) - self.assertFalse(profile.profile_html) - self.assertFalse(profile.signature) - self.assertFalse(profile.signature_html) - self.assertEqual(profile.status, STA_SPAMMER) - - status_date = datetime.date(year=profile.status_date.year, - month=profile.status_date.month, - day=profile.status_date.day) - self.assertEqual(status_date, datetime.date.today()) - - self.assertEqual(Comment.objects.filter(user=user).count(), 0) - self.assertEqual(WebsiteProfile.objects.filter(user=user).count(), 0) - self.assertEqual(Shout.objects.filter(user=user).count(), 0)
--- a/bio/tests/__init__.py Sun Dec 29 13:45:49 2013 -0600 +++ b/bio/tests/__init__.py Sun Dec 29 14:45:26 2013 -0600 @@ -1,2 +0,0 @@ -from view_tests import * -from form_tests import *
--- a/bio/tests/form_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -""" -Form tests for the bio application. - -""" -from django.test import TestCase - -from bio.forms import EditUserProfileForm - - -class EditUserProfileFormTestCase(TestCase): - - def test_valid_timezone(self): - - post_data = {'time_zone': 'US/Central'} - form = EditUserProfileForm(post_data) - self.assertTrue(form.is_valid()) - - def test_invalid_timezone(self): - - post_data = {'time_zone': u'Am\xe9rica/Argentina_/_Buenos_Aires'} - form = EditUserProfileForm(post_data) - self.assertFalse(form.is_valid()) - - def test_blank_timezone(self): - - form = EditUserProfileForm({}) - self.assertTrue(form.is_valid()) -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bio/tests/test_forms.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,28 @@ +""" +Form tests for the bio application. + +""" +from django.test import TestCase + +from bio.forms import EditUserProfileForm + + +class EditUserProfileFormTestCase(TestCase): + + def test_valid_timezone(self): + + post_data = {'time_zone': 'US/Central'} + form = EditUserProfileForm(post_data) + self.assertTrue(form.is_valid()) + + def test_invalid_timezone(self): + + post_data = {'time_zone': u'Am\xe9rica/Argentina_/_Buenos_Aires'} + form = EditUserProfileForm(post_data) + self.assertFalse(form.is_valid()) + + def test_blank_timezone(self): + + form = EditUserProfileForm({}) + self.assertTrue(form.is_valid()) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bio/tests/test_views.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,76 @@ +""" +View tests for the bio application. + +""" +from django.contrib.auth.models import User +from django.test import TestCase +from django.core.urlresolvers import reverse, NoReverseMatch + + +class MemberSearchTest(TestCase): + + USERNAME = u'John' + + def setUp(self): + user = User.objects.create_user(self.USERNAME, '', 'password') + user.save() + + self.username = 'test_user' + self.pw = 'password' + self.user = User.objects.create_user(self.username, '', self.pw) + self.user.save() + self.assertTrue(self.client.login(username=self.username, + password=self.pw)) + + def tearDown(self): + self.client.logout() + + def testValidName(self): + """ + Test a valid username. + """ + + response = self.client.post(reverse('bio-member_search'), + {'username': self.USERNAME}, + follow=True) + + self.assertEqual(len(response.redirect_chain), 1) + if response.redirect_chain: + self.assertEqual(response.redirect_chain[0][0], + 'http://testserver' + reverse('bio-view_profile', + kwargs={'username': self.USERNAME})) + self.assertEqual(response.redirect_chain[0][1], 302) + + self.assertEqual(response.status_code, 200) + + def testInvalidName(self): + """ + Test a invalid username. + """ + + response = self.client.post(reverse('bio-member_search'), + {'username': self.USERNAME + '!'}) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, "That username does not exist.") + + def testTrailingSpace(self): + """ + Test a username with a trailing space. + """ + + try: + response = self.client.post(reverse('bio-member_search'), + {'username': self.USERNAME + ' '}, + follow=True) + except NoReverseMatch: + self.fail('bit by a MySQL bug?') + + self.assertEqual(len(response.redirect_chain), 1) + if response.redirect_chain: + self.assertEqual(response.redirect_chain[0][0], + 'http://testserver' + reverse('bio-view_profile', + kwargs={'username': self.USERNAME})) + self.assertEqual(response.redirect_chain[0][1], 302) + + self.assertEqual(response.status_code, 200)
--- a/bio/tests/view_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -""" -View tests for the bio application. - -""" -import datetime - -from django.contrib.auth.models import User -from django.test import TestCase -from django.core.urlresolvers import reverse, NoReverseMatch - - -class MemberSearchTest(TestCase): - - USERNAME = u'John' - - def setUp(self): - user = User.objects.create_user(self.USERNAME, '', 'password') - user.save() - - self.username = 'test_user' - self.pw = 'password' - self.user = User.objects.create_user(self.username, '', self.pw) - self.user.save() - self.assertTrue(self.client.login(username=self.username, - password=self.pw)) - - def tearDown(self): - self.client.logout() - - def testValidName(self): - """ - Test a valid username. - """ - - response = self.client.post(reverse('bio-member_search'), - {'username': self.USERNAME}, - follow=True) - - self.assertEqual(len(response.redirect_chain), 1) - if response.redirect_chain: - self.assertEqual(response.redirect_chain[0][0], - 'http://testserver' + reverse('bio-view_profile', - kwargs={'username': self.USERNAME})) - self.assertEqual(response.redirect_chain[0][1], 302) - - self.assertEqual(response.status_code, 200) - - def testInvalidName(self): - """ - Test a invalid username. - """ - - response = self.client.post(reverse('bio-member_search'), - {'username': self.USERNAME + '!'}) - - self.assertEqual(response.status_code, 200) - self.assertContains(response, "That username does not exist.") - - def testTrailingSpace(self): - """ - Test a username with a trailing space. - """ - - try: - response = self.client.post(reverse('bio-member_search'), - {'username': self.USERNAME + ' '}, - follow=True) - except NoReverseMatch: - self.fail('bit by a MySQL bug?') - - self.assertEqual(len(response.redirect_chain), 1) - if response.redirect_chain: - self.assertEqual(response.redirect_chain[0][0], - 'http://testserver' + reverse('bio-view_profile', - kwargs={'username': self.USERNAME})) - self.assertEqual(response.redirect_chain[0][1], 302) - - self.assertEqual(response.status_code, 200)
--- a/contests/tests/__init__.py Sun Dec 29 13:45:49 2013 -0600 +++ b/contests/tests/__init__.py Sun Dec 29 14:45:26 2013 -0600 @@ -1,2 +0,0 @@ -from model_tests import * -from view_tests import *
--- a/contests/tests/model_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -""" -Model tests for the contests application. - -""" -import datetime - -from django.test import TestCase -from django.contrib.auth.models import User - -from contests.models import Contest - - -class ContestTestCase(TestCase): - - def test_creation_date(self): - - c = Contest(title='test', - slug='test', - description='test', - is_public=False, - end_date=datetime.datetime.now() + datetime.timedelta(days=30)) - - c.save() - - self.assertTrue(c.creation_date) - self.assertTrue(datetime.datetime.now() - c.creation_date < - datetime.timedelta(seconds=1)) - - def test_is_active(self): - - now = datetime.datetime.now() - start = now + datetime.timedelta(days=7) - end = start + datetime.timedelta(days=30) - - c = Contest(title='test', - slug='test', - description='test', - is_public=False, - creation_date=start, - end_date=end) - - self.failIf(c.is_active()) - - start = now - datetime.timedelta(days=7) - end = start + datetime.timedelta(days=30) - - c = Contest(title='test', - slug='test', - description='test', - is_public=True, - creation_date=start, - end_date=end) - - self.assertTrue(c.is_active()) - - start = now - datetime.timedelta(days=7) - end = start - datetime.timedelta(days=3) - - c = Contest(title='test', - slug='test', - description='test', - is_public=True, - creation_date=start, - end_date=end) - - self.failIf(c.is_active()) - - def test_can_enter(self): - - now = datetime.datetime.now() - start = now + datetime.timedelta(days=7) - end = start + datetime.timedelta(days=30) - - c = Contest(title='test', - slug='test', - description='test', - is_public=False, - creation_date=start, - end_date=end) - - self.failIf(c.can_enter()) - - start = now - datetime.timedelta(days=7) - end = start + datetime.timedelta(days=30) - - c = Contest(title='test', - slug='test', - description='test', - is_public=True, - creation_date=start, - end_date=end) - - self.assertTrue(c.can_enter()) - - start = now - datetime.timedelta(days=7) - end = start - datetime.timedelta(days=3) - - c = Contest(title='test', - slug='test', - description='test', - is_public=True, - creation_date=start, - end_date=end) - - self.failIf(c.can_enter()) - - start = now - datetime.timedelta(days=7) - end = start + datetime.timedelta(days=30) - - user = User.objects.create_user('test_user', '', 'password') - user.save() - - c = Contest(title='test', - slug='test', - description='test', - is_public=True, - creation_date=start, - end_date=end, - winner=user, - win_date=now) - - self.failIf(c.can_enter()) - - start = now - datetime.timedelta(days=7) - end = start - datetime.timedelta(days=3) - - c = Contest(title='test', - slug='test', - description='test', - is_public=True, - creation_date=start, - end_date=end, - winner=user, - win_date=end + datetime.timedelta(days=1)) - - self.failIf(c.can_enter()) - - def test_pick_winner(self): - - now = datetime.datetime.now() - start = now - datetime.timedelta(days=7) - end = start - datetime.timedelta(days=3) - - c = Contest(title='test', - slug='test', - description='test', - is_public=False, - creation_date=start, - end_date=end) - c.save() - - user1 = User.objects.create_user('test_user1', '', 'password') - user1.save() - user2 = User.objects.create_user('test_user2', '', 'password') - user2.save() - user3 = User.objects.create_user('test_user3', '', 'password') - user3.save() - - c.contestants.add(user1, user2, user3) - - c.pick_winner() - - self.assertTrue(datetime.datetime.now() - c.win_date < - datetime.timedelta(seconds=1)) - self.assertTrue(c.winner.id in [user1.id, user2.id, user3.id]) -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contests/tests/test_models.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,166 @@ +""" +Model tests for the contests application. + +""" +import datetime + +from django.test import TestCase +from django.contrib.auth.models import User + +from contests.models import Contest + + +class ContestTestCase(TestCase): + + def test_creation_date(self): + + c = Contest(title='test', + slug='test', + description='test', + is_public=False, + end_date=datetime.datetime.now() + datetime.timedelta(days=30)) + + c.save() + + self.assertTrue(c.creation_date) + self.assertTrue(datetime.datetime.now() - c.creation_date < + datetime.timedelta(seconds=1)) + + def test_is_active(self): + + now = datetime.datetime.now() + start = now + datetime.timedelta(days=7) + end = start + datetime.timedelta(days=30) + + c = Contest(title='test', + slug='test', + description='test', + is_public=False, + creation_date=start, + end_date=end) + + self.assertFalse(c.is_active()) + + start = now - datetime.timedelta(days=7) + end = start + datetime.timedelta(days=30) + + c = Contest(title='test', + slug='test', + description='test', + is_public=True, + creation_date=start, + end_date=end) + + self.assertTrue(c.is_active()) + + start = now - datetime.timedelta(days=7) + end = start - datetime.timedelta(days=3) + + c = Contest(title='test', + slug='test', + description='test', + is_public=True, + creation_date=start, + end_date=end) + + self.assertFalse(c.is_active()) + + def test_can_enter(self): + + now = datetime.datetime.now() + start = now + datetime.timedelta(days=7) + end = start + datetime.timedelta(days=30) + + c = Contest(title='test', + slug='test', + description='test', + is_public=False, + creation_date=start, + end_date=end) + + self.assertFalse(c.can_enter()) + + start = now - datetime.timedelta(days=7) + end = start + datetime.timedelta(days=30) + + c = Contest(title='test', + slug='test', + description='test', + is_public=True, + creation_date=start, + end_date=end) + + self.assertTrue(c.can_enter()) + + start = now - datetime.timedelta(days=7) + end = start - datetime.timedelta(days=3) + + c = Contest(title='test', + slug='test', + description='test', + is_public=True, + creation_date=start, + end_date=end) + + self.assertFalse(c.can_enter()) + + start = now - datetime.timedelta(days=7) + end = start + datetime.timedelta(days=30) + + user = User.objects.create_user('test_user', '', 'password') + user.save() + + c = Contest(title='test', + slug='test', + description='test', + is_public=True, + creation_date=start, + end_date=end, + winner=user, + win_date=now) + + self.assertFalse(c.can_enter()) + + start = now - datetime.timedelta(days=7) + end = start - datetime.timedelta(days=3) + + c = Contest(title='test', + slug='test', + description='test', + is_public=True, + creation_date=start, + end_date=end, + winner=user, + win_date=end + datetime.timedelta(days=1)) + + self.assertFalse(c.can_enter()) + + def test_pick_winner(self): + + now = datetime.datetime.now() + start = now - datetime.timedelta(days=7) + end = start - datetime.timedelta(days=3) + + c = Contest(title='test', + slug='test', + description='test', + is_public=False, + creation_date=start, + end_date=end) + c.save() + + user1 = User.objects.create_user('test_user1', '', 'password') + user1.save() + user2 = User.objects.create_user('test_user2', '', 'password') + user2.save() + user3 = User.objects.create_user('test_user3', '', 'password') + user3.save() + + c.contestants.add(user1, user2, user3) + + c.pick_winner() + + self.assertTrue(datetime.datetime.now() - c.win_date < + datetime.timedelta(seconds=1)) + self.assertTrue(c.winner.id in [user1.id, user2.id, user3.id]) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contests/tests/test_views.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,124 @@ +""" +View tests for the contests application. + +""" +import datetime +import json + +from django.test import TestCase +from django.contrib.auth.models import User +from django.core.urlresolvers import reverse + +from contests.models import Contest + + +class NoConstestsTestCase(TestCase): + + def test_no_contests(self): + response = self.client.get(reverse('contests-index')) + self.assertEqual(response.status_code, 200) + + url = reverse('contests-contest', kwargs={'slug': 'test'}) + response = self.client.get(url) + self.assertEqual(response.status_code, 404) + + +class ConstestsTestCase(TestCase): + + def setUp(self): + now = datetime.datetime.now() + start = now - datetime.timedelta(days=7) + end = start - datetime.timedelta(days=3) + + user = User.objects.create_user('test_user', '', 'password') + user.save() + + c = Contest(title='test', + slug='test', + description='test', + is_public=True, + creation_date=start, + end_date=end, + winner=user, + win_date=end + datetime.timedelta(days=1)) + c.save() + self.contest_id = c.id + + def test_contests(self): + response = self.client.get(reverse('contests-index')) + self.assertEqual(response.status_code, 200) + + url = reverse('contests-contest', kwargs={'slug': 'test'}) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + + +class ContestEntryTestCase(TestCase): + + def setUp(self): + self.username = 'test_user' + self.pw = 'password' + self.user = User.objects.create_user(self.username, '', self.pw) + self.user.save() + self.assertTrue(self.client.login(username=self.username, + password=self.pw)) + + now = datetime.datetime.now() + start = now - datetime.timedelta(days=7) + end = now + datetime.timedelta(days=3) + + c = Contest(title='test', + slug='test', + description='test', + is_public=True, + creation_date=start, + end_date=end) + c.save() + self.contest_id = c.id + + def test_entry_toggle(self): + response = self.client.post(reverse('contests-enter'), + {'contest_id': self.contest_id}, + HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(response.status_code, 200) + + c = json.loads(response.content) + self.assertTrue(c['entered']) + + contest = Contest.objects.get(pk=self.contest_id) + self.assertTrue(self.user in contest.contestants.all()) + + response = self.client.post(reverse('contests-enter'), + {'contest_id': self.contest_id}, + HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(response.status_code, 200) + + c = json.loads(response.content) + self.assertFalse(c['entered']) + + contest = Contest.objects.get(pk=self.contest_id) + self.assertFalse(self.user in contest.contestants.all()) + + +class NoPublicConstestsTestCase(TestCase): + + def setUp(self): + now = datetime.datetime.now() + start = now - datetime.timedelta(days=7) + end = start - datetime.timedelta(days=3) + + c = Contest(title='test', + slug='test', + description='test', + is_public=False, + creation_date=start, + end_date=end) + c.save() + + def test_contests(self): + response = self.client.get(reverse('contests-index')) + self.assertEqual(response.status_code, 200) + + url = reverse('contests-contest', kwargs={'slug': 'test'}) + response = self.client.get(url) + self.assertEqual(response.status_code, 404)
--- a/contests/tests/view_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -""" -View tests for the contests application. - -""" -import datetime -import json - -from django.test import TestCase -from django.contrib.auth.models import User -from django.core.urlresolvers import reverse - -from contests.models import Contest - - -class NoConstestsTestCase(TestCase): - - def test_no_contests(self): - response = self.client.get(reverse('contests-index')) - self.assertEqual(response.status_code, 200) - - url = reverse('contests-contest', kwargs={'slug': 'test'}) - response = self.client.get(url) - self.assertEqual(response.status_code, 404) - - -class ConstestsTestCase(TestCase): - - def setUp(self): - now = datetime.datetime.now() - start = now - datetime.timedelta(days=7) - end = start - datetime.timedelta(days=3) - - user = User.objects.create_user('test_user', '', 'password') - user.save() - - c = Contest(title='test', - slug='test', - description='test', - is_public=True, - creation_date=start, - end_date=end, - winner=user, - win_date=end + datetime.timedelta(days=1)) - c.save() - self.contest_id = c.id - - def test_contests(self): - response = self.client.get(reverse('contests-index')) - self.assertEqual(response.status_code, 200) - - url = reverse('contests-contest', kwargs={'slug': 'test'}) - response = self.client.get(url) - self.assertEqual(response.status_code, 200) - - -class ContestEntryTestCase(TestCase): - - def setUp(self): - self.username = 'test_user' - self.pw = 'password' - self.user = User.objects.create_user(self.username, '', self.pw) - self.user.save() - self.assertTrue(self.client.login(username=self.username, - password=self.pw)) - - now = datetime.datetime.now() - start = now - datetime.timedelta(days=7) - end = now + datetime.timedelta(days=3) - - c = Contest(title='test', - slug='test', - description='test', - is_public=True, - creation_date=start, - end_date=end) - c.save() - self.contest_id = c.id - - def test_entry_toggle(self): - response = self.client.post(reverse('contests-enter'), - {'contest_id': self.contest_id}, - HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - c = json.loads(response.content) - self.assertTrue(c['entered']) - - contest = Contest.objects.get(pk=self.contest_id) - self.assertTrue(self.user in contest.contestants.all()) - - response = self.client.post(reverse('contests-enter'), - {'contest_id': self.contest_id}, - HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - c = json.loads(response.content) - self.failIf(c['entered']) - - contest = Contest.objects.get(pk=self.contest_id) - self.failIf(self.user in contest.contestants.all()) - - -class NoPublicConstestsTestCase(TestCase): - - def setUp(self): - now = datetime.datetime.now() - start = now - datetime.timedelta(days=7) - end = start - datetime.timedelta(days=3) - - c = Contest(title='test', - slug='test', - description='test', - is_public=False, - creation_date=start, - end_date=end) - c.save() - - def test_contests(self): - response = self.client.get(reverse('contests-index')) - self.assertEqual(response.status_code, 200) - - url = reverse('contests-contest', kwargs={'slug': 'test'}) - response = self.client.get(url) - self.assertEqual(response.status_code, 404)
--- a/forums/tests/__init__.py Sun Dec 29 13:45:49 2013 -0600 +++ b/forums/tests/__init__.py Sun Dec 29 14:45:26 2013 -0600 @@ -1,1 +0,0 @@ -from view_tests import *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/forums/tests/test_views.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,135 @@ +""" +Tests for the views in the forums application. + +""" +from django.test import TestCase +from django.contrib.auth.models import User +from django.core.urlresolvers import reverse + +from forums.models import Forum, Topic + + +class ForumPostTestCase(TestCase): + fixtures = ['forums.json'] + + def setUp(self): + self.username = 'test_user' + self.pw = 'password' + self.user = User.objects.create_user(self.username, '', self.pw) + self.user.save() + self.assertTrue(self.client.login(username=self.username, + password=self.pw)) + + def tearDown(self): + self.client.logout() + + def testBasicForumsTest(self): + + forum_slug = 'shallow-end' + topic_name = 'A test topic' + topic_body = 'testing 1, 2, 3...' + + response = self.client.post( + reverse('forums-new_topic', kwargs={'slug': forum_slug}), + {'name': topic_name, 'body': topic_body}, + follow=True) + + self.assertEqual(len(response.redirect_chain), 1) + + if response.redirect_chain: + self.assertEqual(response.redirect_chain[0][0], + 'http://testserver' + reverse('forums-new_topic_thanks', + kwargs={'tid': '1'})) + self.assertEqual(response.redirect_chain[0][1], 302) + + self.assertEqual(response.status_code, 200) + + forum = Forum.objects.get(slug=forum_slug) + try: + topic = Topic.objects.get(pk=1) + except Topic.DoesNotExist: + self.fail("topic doesn't exist") + + self.assertEqual(topic.forum.pk, forum.pk) + self.assertEqual(topic.user.pk, self.user.pk) + self.assertEqual(topic.name, topic_name) + self.assertEqual(topic.post_count, 1) + + post = topic.last_post + self.assertFalse(post is None) + + if post: + self.assertEqual(post.body, topic_body) + self.assertEqual(post.user.pk, self.user.pk) + + # post to the thread + response = self.client.get( + reverse('forums-topic_index', kwargs={'id': '1'})) + self.assertEqual(response.status_code, 200) + + post2_body = 'test quick post' + response = self.client.post( + reverse('forums-quick_reply'), + {'body': post2_body, 'topic_id': 1}) + self.assertEqual(response.status_code, 200) + try: + topic = Topic.objects.get(pk=1) + except Topic.DoesNotExist: + self.fail("topic doesn't exist") + + post = topic.last_post + self.assertFalse(post is None) + if post: + self.assertEqual(post.body, post2_body) + self.assertEqual(post.user.pk, self.user.pk) + self.assertEqual(topic.post_count, 2) + + # quote last post + response = self.client.get( + reverse('forums-new_post', kwargs={'topic_id': 1}), + {'quote_id': 2}) + self.assertEqual(response.status_code, 200) + + post3_body = 'new post 3 content' + response = self.client.post( + reverse('forums-new_post', kwargs={'topic_id': 1}), + {'body': post3_body, 'post_id': 2}, + follow=True) + self.assertEqual(response.status_code, 200) + try: + topic = Topic.objects.get(pk=1) + except Topic.DoesNotExist: + self.fail("topic doesn't exist") + + post = topic.last_post + self.assertFalse(post is None) + if post: + self.assertEqual(post.body, post3_body) + self.assertEqual(post.user.pk, self.user.pk) + self.assertEqual(topic.post_count, 3) + + # edit last post + response = self.client.get( + reverse('forums-edit_post', kwargs={'id': 3})) + self.assertEqual(response.status_code, 200) + + post3_body = 'edited post 3 content' + response = self.client.post( + reverse('forums-edit_post', kwargs={'id': 3}), + {'body': post3_body}, + follow=True) + self.assertEqual(response.status_code, 200) + try: + topic = Topic.objects.get(pk=1) + except Topic.DoesNotExist: + self.fail("topic doesn't exist") + + post = topic.last_post + self.assertFalse(post is None) + if post: + self.assertEqual(post.body, post3_body) + self.assertEqual(post.user.pk, self.user.pk) + self.assertEqual(topic.post_count, 3) + + profile = self.user.get_profile() + self.assertEqual(profile.forum_post_count, 3)
--- a/forums/tests/view_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -""" -Tests for the views in the forums application. - -""" -from django.test import TestCase -from django.contrib.auth.models import User -from django.core.urlresolvers import reverse - -from forums.models import Forum, Topic, Post - - -class ForumPostTestCase(TestCase): - fixtures = ['forums.json'] - - def setUp(self): - self.username = 'test_user' - self.pw = 'password' - self.user = User.objects.create_user(self.username, '', self.pw) - self.user.save() - self.assertTrue(self.client.login(username=self.username, - password=self.pw)) - - def tearDown(self): - self.client.logout() - - def testBasicForumsTest(self): - - forum_slug = 'shallow-end' - topic_name = 'A test topic' - topic_body = 'testing 1, 2, 3...' - - response = self.client.post( - reverse('forums-new_topic', kwargs={'slug': forum_slug}), - {'name': topic_name, 'body': topic_body}, - follow=True) - - self.assertEqual(len(response.redirect_chain), 1) - - if response.redirect_chain: - self.assertEqual(response.redirect_chain[0][0], - 'http://testserver' + reverse('forums-new_topic_thanks', - kwargs={'tid': '1'})) - self.assertEqual(response.redirect_chain[0][1], 302) - - self.assertEqual(response.status_code, 200) - - forum = Forum.objects.get(slug=forum_slug) - try: - topic = Topic.objects.get(pk=1) - except Topic.DoesNotExist: - self.fail("topic doesn't exist") - - self.assertEqual(topic.forum.pk, forum.pk) - self.assertEqual(topic.user.pk, self.user.pk) - self.assertEqual(topic.name, topic_name) - self.assertEqual(topic.post_count, 1) - - post = topic.last_post - self.failIf(post is None) - - if post: - self.assertEqual(post.body, topic_body) - self.assertEqual(post.user.pk, self.user.pk) - - # post to the thread - response = self.client.get( - reverse('forums-topic_index', kwargs={'id': '1'})) - self.assertEqual(response.status_code, 200) - - post2_body = 'test quick post' - response = self.client.post( - reverse('forums-quick_reply'), - {'body': post2_body, 'topic_id': 1}) - self.assertEqual(response.status_code, 200) - try: - topic = Topic.objects.get(pk=1) - except Topic.DoesNotExist: - self.fail("topic doesn't exist") - - post = topic.last_post - self.failIf(post is None) - if post: - self.assertEqual(post.body, post2_body) - self.assertEqual(post.user.pk, self.user.pk) - self.assertEqual(topic.post_count, 2) - - # quote last post - response = self.client.get( - reverse('forums-new_post', kwargs={'topic_id': 1}), - {'quote_id': 2}) - self.assertEqual(response.status_code, 200) - - post3_body = 'new post 3 content' - response = self.client.post( - reverse('forums-new_post', kwargs={'topic_id': 1}), - {'body': post3_body, 'post_id': 2}, - follow=True) - self.assertEqual(response.status_code, 200) - try: - topic = Topic.objects.get(pk=1) - except Topic.DoesNotExist: - self.fail("topic doesn't exist") - - post = topic.last_post - self.failIf(post is None) - if post: - self.assertEqual(post.body, post3_body) - self.assertEqual(post.user.pk, self.user.pk) - self.assertEqual(topic.post_count, 3) - - # edit last post - response = self.client.get( - reverse('forums-edit_post', kwargs={'id': 3})) - self.assertEqual(response.status_code, 200) - - post3_body = 'edited post 3 content' - response = self.client.post( - reverse('forums-edit_post', kwargs={'id': 3}), - {'body': post3_body}, - follow=True) - self.assertEqual(response.status_code, 200) - try: - topic = Topic.objects.get(pk=1) - except Topic.DoesNotExist: - self.fail("topic doesn't exist") - - post = topic.last_post - self.failIf(post is None) - if post: - self.assertEqual(post.body, post3_body) - self.assertEqual(post.user.pk, self.user.pk) - self.assertEqual(topic.post_count, 3) - - profile = self.user.get_profile() - self.assertEqual(profile.forum_post_count, 3)
--- a/legacy/tests.py Sun Dec 29 13:45:49 2013 -0600 +++ b/legacy/tests.py Sun Dec 29 14:45:26 2013 -0600 @@ -13,7 +13,7 @@ s1 = ""Look! No head!" - Laika & The Cosmonauts" s2 = unphpbb(s1) s3 = u'"Look! No head!" - Laika & The Cosmonauts' - self.failUnlessEqual(s2, s3) + self.assertEqual(s2, s3) def test_rem_uuid1(self): s1 = ("[url=http://www.thesurfites.com][color=black:3fdb565c83]" @@ -21,7 +21,7 @@ s2 = unphpbb(s1) s3 = (u'[url=http://www.thesurfites.com][color=black]' 'T H E - S U R F I T E S[/color][/url]') - self.failUnlessEqual(s2, s3) + self.assertEqual(s2, s3) class Html2MdTest(TestCase): @@ -35,4 +35,4 @@ md_writer.feed(s1) s2 = md_writer.markdown() s3 = u'[Pollo Del Mar](http://surfguitar101.com/modules.php?name=Web_Links&l_op=visit&lid=50) \n\n[Frankie & The Pool Boys](http://tinyurl.com/yjfmspj) \n\n[PDM on FaceBook](http://tinyurl.com/cnr27t) \n\n' - self.failUnlessEqual(s2, s3) + self.assertEqual(s2, s3)
--- a/polls/tests/__init__.py Sun Dec 29 13:45:49 2013 -0600 +++ b/polls/tests/__init__.py Sun Dec 29 14:45:26 2013 -0600 @@ -1,1 +0,0 @@ -from view_tests import *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/polls/tests/test_views.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,178 @@ +""" +Tests for the views in the polls application. + +""" +import datetime + +from django.contrib.auth.models import User +from django.test import TestCase +from django.core.urlresolvers import reverse +from polls.models import Poll, Choice + + +class PollHomeTest(TestCase): + + def setUp(self): + now = datetime.datetime.now() + Poll.objects.all().delete() + + past = now - datetime.timedelta(7) + future = now + datetime.timedelta(7) + + Poll.objects.create(start_date=past, + end_date=past, + is_enabled=True, + question='Old Poll') + + active = Poll.objects.create(start_date=past, + end_date=future, + is_enabled=True, + question='Active Poll') + + Poll.objects.create(start_date=future, + end_date=future, + is_enabled=True, + question='Future Poll') + + Poll.objects.create(start_date=past, + end_date=future, + is_enabled=False, + question='Disabled Poll') + + choice1 = Choice.objects.create(poll=active, choice="Yes") + choice2 = Choice.objects.create(poll=active, choice="Yes") + + self.username = 'test_user' + self.pw = 'password' + self.user = User.objects.create_user(self.username, '', self.pw) + self.user.save() + self.assertTrue(self.client.login(username=self.username, + password=self.pw)) + + def tearDown(self): + self.client.logout() + + def testHome(self): + response = self.client.get(reverse('polls-main')) + + old = response.context['old_polls'] + self.assertEqual(len(old), 1) + if old: + self.assertEqual(old[0].question, 'Old Poll') + + current = response.context['current_polls'] + self.assertEqual(len(current), 1) + if current: + self.assertEqual(current[0].question, 'Active Poll') + + self.assertNotContains(response, 'Future Poll') + self.assertNotContains(response, 'Disabled Poll') + + def testFuture(self): + poll = Poll.objects.get(question='Future Poll') + response = self.client.get(reverse('polls-detail', kwargs={'poll_id': + poll.id})) + self.assertEqual(response.status_code, 404) + + def testDisabled(self): + poll = Poll.objects.get(question='Disabled Poll') + response = self.client.get(reverse('polls-detail', kwargs={'poll_id': + poll.id})) + self.assertEqual(response.status_code, 404) + + def testOld(self): + poll = Poll.objects.get(question='Old Poll') + response = self.client.get(reverse('polls-detail', kwargs={'poll_id': + poll.id})) + self.assertEqual(response.status_code, 200) + + def testActive(self): + poll = Poll.objects.get(question='Active Poll') + response = self.client.get(reverse('polls-detail', kwargs={'poll_id': + poll.id})) + self.assertEqual(response.status_code, 200) + + def testVoteOld(self): + poll = Poll.objects.get(question='Old Poll') + response = self.client.get(reverse('polls-vote', kwargs={'poll_id': + poll.id}), follow=True) + + self.assertEqual(len(response.redirect_chain), 1) + if response.redirect_chain: + self.assertEqual(response.redirect_chain[0][0], + 'http://testserver' + reverse('polls-detail', kwargs={'poll_id': poll.id})) + self.assertEqual(response.redirect_chain[0][1], 302) + + self.assertEqual(response.status_code, 200) + + def testVoteActive(self): + poll = Poll.objects.get(question='Active Poll') + response = self.client.get(reverse('polls-vote', kwargs={'poll_id': + poll.id}), follow=True) + + self.assertEqual(len(response.redirect_chain), 0) + self.assertEqual(response.status_code, 200) + + def testVoteFuture(self): + poll = Poll.objects.get(question='Future Poll') + response = self.client.get(reverse('polls-vote', kwargs={'poll_id': + poll.id}), follow=True) + + self.assertEqual(len(response.redirect_chain), 1) + if response.redirect_chain: + self.assertEqual(response.redirect_chain[0][0], + 'http://testserver' + reverse('polls-detail', kwargs={'poll_id': poll.id})) + self.assertEqual(response.redirect_chain[0][1], 302) + + self.assertEqual(response.status_code, 404) + + def testVoteDisabled(self): + poll = Poll.objects.get(question='Disabled Poll') + response = self.client.get(reverse('polls-vote', kwargs={'poll_id': + poll.id}), follow=True) + + self.assertEqual(response.status_code, 404) + + def testVoteActivePost(self): + self._voteTest() + + def testDeleteVote(self): + poll = self._voteTest() + + response = self.client.post( + reverse('polls-delete_vote'), + {'poll_id': poll.id}, + follow=True) + + self.assertEqual(len(response.redirect_chain), 1) + if response.redirect_chain: + self.assertEqual(response.redirect_chain[0][0], + 'http://testserver' + reverse('polls-detail', kwargs={'poll_id': poll.id})) + self.assertEqual(response.redirect_chain[0][1], 302) + + self.assertEqual(response.status_code, 200) + + choice = Choice.objects.get(pk=1) + self.assertEqual(choice.votes, 0) + self.assertTrue(self.user not in choice.voters.all()) + + def _voteTest(self): + poll = Poll.objects.get(question='Active Poll') + response = self.client.post( + reverse('polls-vote', kwargs={'poll_id': poll.id}), + {'choices': 1}, + follow=True) + + self.assertEqual(len(response.redirect_chain), 1) + if response.redirect_chain: + self.assertEqual(response.redirect_chain[0][0], + 'http://testserver' + reverse('polls-detail', kwargs={'poll_id': poll.id})) + self.assertEqual(response.redirect_chain[0][1], 302) + + self.assertEqual(response.status_code, 200) + + choice = Choice.objects.get(pk=1) + self.assertEqual(choice.votes, 1) + self.assertTrue(self.user in choice.voters.all()) + + return poll
--- a/polls/tests/view_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,178 +0,0 @@ -""" -Tests for the views in the polls application. - -""" -import datetime - -from django.contrib.auth.models import User -from django.test import TestCase -from django.core.urlresolvers import reverse -from polls.models import Poll, Choice - - -class PollHomeTest(TestCase): - - def setUp(self): - now = datetime.datetime.now() - Poll.objects.all().delete() - - past = now - datetime.timedelta(7) - future = now + datetime.timedelta(7) - - Poll.objects.create(start_date=past, - end_date=past, - is_enabled=True, - question='Old Poll') - - active = Poll.objects.create(start_date=past, - end_date=future, - is_enabled=True, - question='Active Poll') - - Poll.objects.create(start_date=future, - end_date=future, - is_enabled=True, - question='Future Poll') - - Poll.objects.create(start_date=past, - end_date=future, - is_enabled=False, - question='Disabled Poll') - - choice1 = Choice.objects.create(poll=active, choice="Yes") - choice2 = Choice.objects.create(poll=active, choice="Yes") - - self.username = 'test_user' - self.pw = 'password' - self.user = User.objects.create_user(self.username, '', self.pw) - self.user.save() - self.assertTrue(self.client.login(username=self.username, - password=self.pw)) - - def tearDown(self): - self.client.logout() - - def testHome(self): - response = self.client.get(reverse('polls-main')) - - old = response.context['old_polls'] - self.assertEqual(len(old), 1) - if old: - self.assertEqual(old[0].question, 'Old Poll') - - current = response.context['current_polls'] - self.assertEqual(len(current), 1) - if current: - self.assertEqual(current[0].question, 'Active Poll') - - self.assertNotContains(response, 'Future Poll') - self.assertNotContains(response, 'Disabled Poll') - - def testFuture(self): - poll = Poll.objects.get(question='Future Poll') - response = self.client.get(reverse('polls-detail', kwargs={'poll_id': - poll.id})) - self.assertEqual(response.status_code, 404) - - def testDisabled(self): - poll = Poll.objects.get(question='Disabled Poll') - response = self.client.get(reverse('polls-detail', kwargs={'poll_id': - poll.id})) - self.assertEqual(response.status_code, 404) - - def testOld(self): - poll = Poll.objects.get(question='Old Poll') - response = self.client.get(reverse('polls-detail', kwargs={'poll_id': - poll.id})) - self.assertEqual(response.status_code, 200) - - def testActive(self): - poll = Poll.objects.get(question='Active Poll') - response = self.client.get(reverse('polls-detail', kwargs={'poll_id': - poll.id})) - self.assertEqual(response.status_code, 200) - - def testVoteOld(self): - poll = Poll.objects.get(question='Old Poll') - response = self.client.get(reverse('polls-vote', kwargs={'poll_id': - poll.id}), follow=True) - - self.assertEqual(len(response.redirect_chain), 1) - if response.redirect_chain: - self.assertEqual(response.redirect_chain[0][0], - 'http://testserver' + reverse('polls-detail', kwargs={'poll_id': poll.id})) - self.assertEqual(response.redirect_chain[0][1], 302) - - self.assertEqual(response.status_code, 200) - - def testVoteActive(self): - poll = Poll.objects.get(question='Active Poll') - response = self.client.get(reverse('polls-vote', kwargs={'poll_id': - poll.id}), follow=True) - - self.assertEqual(len(response.redirect_chain), 0) - self.assertEqual(response.status_code, 200) - - def testVoteFuture(self): - poll = Poll.objects.get(question='Future Poll') - response = self.client.get(reverse('polls-vote', kwargs={'poll_id': - poll.id}), follow=True) - - self.assertEqual(len(response.redirect_chain), 1) - if response.redirect_chain: - self.assertEqual(response.redirect_chain[0][0], - 'http://testserver' + reverse('polls-detail', kwargs={'poll_id': poll.id})) - self.assertEqual(response.redirect_chain[0][1], 302) - - self.assertEqual(response.status_code, 404) - - def testVoteDisabled(self): - poll = Poll.objects.get(question='Disabled Poll') - response = self.client.get(reverse('polls-vote', kwargs={'poll_id': - poll.id}), follow=True) - - self.assertEqual(response.status_code, 404) - - def testVoteActivePost(self): - self._voteTest() - - def testDeleteVote(self): - poll = self._voteTest() - - response = self.client.post( - reverse('polls-delete_vote'), - {'poll_id': poll.id}, - follow=True) - - self.assertEqual(len(response.redirect_chain), 1) - if response.redirect_chain: - self.assertEqual(response.redirect_chain[0][0], - 'http://testserver' + reverse('polls-detail', kwargs={'poll_id': poll.id})) - self.assertEqual(response.redirect_chain[0][1], 302) - - self.assertEqual(response.status_code, 200) - - choice = Choice.objects.get(pk=1) - self.assertEqual(choice.votes, 0) - self.assertTrue(self.user not in choice.voters.all()) - - def _voteTest(self): - poll = Poll.objects.get(question='Active Poll') - response = self.client.post( - reverse('polls-vote', kwargs={'poll_id': poll.id}), - {'choices': 1}, - follow=True) - - self.assertEqual(len(response.redirect_chain), 1) - if response.redirect_chain: - self.assertEqual(response.redirect_chain[0][0], - 'http://testserver' + reverse('polls-detail', kwargs={'poll_id': poll.id})) - self.assertEqual(response.redirect_chain[0][1], 302) - - self.assertEqual(response.status_code, 200) - - choice = Choice.objects.get(pk=1) - self.assertEqual(choice.votes, 1) - self.assertTrue(self.user in choice.voters.all()) - - return poll
--- a/potd/tests/__init__.py Sun Dec 29 13:45:49 2013 -0600 +++ b/potd/tests/__init__.py Sun Dec 29 14:45:26 2013 -0600 @@ -1,1 +0,0 @@ -from tools_tests import *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/potd/tests/test_tools.py Sun Dec 29 14:45:26 2013 -0600 @@ -0,0 +1,34 @@ +""" +Tests for the pick_potd() function. + +""" +from django.test import TestCase + +from potd.models import Current, Photo, Sequence +from potd.tools import pick_potd + + +class PickPotdTest(TestCase): + + fixtures = ['potd_test.json'] + + def test_pick(self): + + pick_potd() + + curr = Current.objects.get(pk=1) + self.assertEqual(curr.potd.pk, 2) + + def test_shuffle(self): + + photo = Photo.objects.get(pk=3) + curr = Current.objects.get(pk=1) + curr.potd = photo + curr.save() + + pick_potd() + + ids = Sequence.objects.get(pk=1).seq.split(',') + curr = Current.objects.get(pk=1) + self.assertEqual(len(ids), 3) + self.assertEqual(curr.potd.pk, int(ids[0]))
--- a/potd/tests/tools_tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -""" -Tests for the pick_potd() function. - -""" -from django.test import TestCase -from django.contrib.auth.models import User - -from potd.models import Current, Photo, Sequence -from potd.tools import pick_potd - - -class PickPotdTest(TestCase): - - fixtures = ['potd_test.json'] - - def test_pick(self): - - pick_potd() - - curr = Current.objects.get(pk=1) - self.assertEqual(curr.potd.pk, 2) - - def test_shuffle(self): - - photo = Photo.objects.get(pk=3) - curr = Current.objects.get(pk=1) - curr.potd = photo - curr.save() - - pick_potd() - - ids = Sequence.objects.get(pk=1).seq.split(',') - curr = Current.objects.get(pk=1) - self.assertEqual(len(ids), 3) - self.assertEqual(curr.potd.pk, int(ids[0]))
--- a/ygroup/tests.py Sun Dec 29 13:45:49 2013 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" - -from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2)