Merge lp:~mhall119/loco-team-portal/fix.806005 into lp:~daker/loco-team-portal/fix.806005

Proposed by Michael Hall
Status: Merged
Merge reported by: Adnane Belmadiaf
Merged at revision: not available
Proposed branch: lp:~mhall119/loco-team-portal/fix.806005
Merge into: lp:~daker/loco-team-portal/fix.806005
Diff against target: 91 lines (+67/-15)
1 file modified
loco_directory/events/tests.py (+67/-15)
To merge this branch: bzr merge lp:~mhall119/loco-team-portal/fix.806005
Reviewer Review Type Date Requested Status
Adnane Belmadiaf Pending
Review via email: mp+68181@code.launchpad.net

Description of the change

Adds a test case to show that the validation works

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/events/tests.py'
2--- loco_directory/events/tests.py 2009-12-21 20:45:43 +0000
3+++ loco_directory/events/tests.py 2011-07-17 18:14:28 +0000
4@@ -4,20 +4,72 @@
5
6 Replace these with more appropriate tests for your application.
7 """
8+import datetime
9
10 from django.test import TestCase
11-
12-class SimpleTest(TestCase):
13- def test_basic_addition(self):
14- """
15- Tests that 1 + 1 always equals 2.
16- """
17- self.failUnlessEqual(1 + 1, 2)
18-
19-__test__ = {"doctest": """
20-Another way to test that 1 + 1 is equal to 2.
21-
22->>> 1 + 1 == 2
23-True
24-"""}
25-
26+from django.contrib.auth.models import User, Group
27+from teams.models import Country, Team
28+from venues.models import Venue
29+from events.models import TeamEvent
30+
31+
32+class FormTests(TestCase):
33+
34+ def setUp(self):
35+ # setup country record for testing
36+ self.country = Country.objects.create(name='Test Country')
37+
38+ # setup team record for testing
39+ self.team = Team.objects.create(
40+ lp_name='test-team',
41+ name='Test Team',
42+ )
43+ self.team.countries.add(self.country)
44+
45+ # setup venue record for testing
46+ self.venue = Venue.objects.create(
47+ name='Test Venue',
48+ country=self.country,
49+ )
50+
51+ # setup event record for testing
52+ self.event = TeamEvent.objects.create(
53+ name='Test Event',
54+ date_begin=datetime.datetime.now(),
55+ date_end=datetime.datetime.now() + datetime.timedelta(hours=1),
56+ venue=self.venue,
57+ )
58+ self.event.teams.add(self.team)
59+
60+ # setup user record for testing
61+ self.team_group = Group.objects.create(
62+ name=self.team.lp_name,
63+ )
64+ self.user = User.objects.create(
65+ username='testuser',
66+ )
67+ self.user.set_password('test')
68+ self.user.groups.add(self.team_group)
69+ self.user.save()
70+
71+
72+ def test_large_guest_validation(self):
73+ 'Validate the guests size and show friendly error message when too big'
74+
75+ # register attendence form data
76+ path = '/events/%s/%s/register/' % (self.team.lp_name, self.event.id)
77+ data = {
78+ 'promise': 'sure',
79+ 'guests': 1000000,
80+ }
81+ # login so we're not redirected when posting the form data
82+ self.client.login(username='testuser', password='test')
83+
84+ # post the form data
85+ response = self.client.post(path, data)
86+
87+ # should get a 200 if the integer size is caught by form validation
88+ self.assertEquals(response.status_code, 200)
89+
90+ # check that the user friendly error message exists in the response
91+ self.assertContains(response, 'Ensure this value is less than or equal to 100.')

Subscribers

People subscribed via source and target branches

to all changes: