-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_candidacy_add_and_remove.py
More file actions
78 lines (66 loc) · 2.69 KB
/
Copy pathtest_candidacy_add_and_remove.py
File metadata and controls
78 lines (66 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import re
from django_webtest import WebTest
from official_documents.models import BallotSOPN
from people.tests.factories import PersonFactory
from ..models import Ballot
from .auth import TestUserMixin
from .factories import MembershipFactory
from .uk_examples import UK2015ExamplesMixin
class TestCandidacyCreateView(TestUserMixin, UK2015ExamplesMixin, WebTest):
def setUp(self):
super().setUp()
self.person = PersonFactory.create(id=2009, name="Tessa Jowell")
MembershipFactory.create(
person=self.person,
post=self.camberwell_post,
party=self.labour_party,
ballot=self.camberwell_post_ballot_earlier,
)
def test_create_candidacy_from_earlier_election(self):
self.assertEqual(self.person.memberships.count(), 1)
response = self.app.get(
self.camberwell_post_ballot.get_absolute_url(),
user=self.user_who_can_lock,
)
form = response.forms["candidacy-create_{}".format(self.person.pk)]
form["source"] = "Tests"
form.submit()
self.assertEqual(self.person.memberships.count(), 2)
class TestCandidacyDeleteView(TestUserMixin, UK2015ExamplesMixin, WebTest):
def setUp(self):
super().setUp()
self.person = PersonFactory.create(id=2009, name="Tessa Jowell")
MembershipFactory.create(
person=self.person,
post=self.dulwich_post,
party=self.green_party,
ballot=self.dulwich_post_ballot,
)
def test_delete_candidacy(self):
self.assertEqual(self.person.memberships.count(), 1)
response = self.app.get(
self.dulwich_post_ballot.get_absolute_url(),
user=self.user_who_can_lock,
)
form = response.forms["candidacy-delete_{}".format(self.person.pk)]
form["source"] = "Tests"
form.submit()
self.assertEqual(self.person.memberships.count(), 0)
class TestEditButtonsShown(TestUserMixin, UK2015ExamplesMixin, WebTest):
def test_can_see_add_button_with_no_sopn(self):
ballot: Ballot = self.dulwich_post_ballot
response = self.app.get(
ballot.get_absolute_url(),
user=self.user,
)
self.assertContains(response, "Add a new candidate")
# We allow adding candidates when there is a SOPN
# but we mark the button as 'secondary'
BallotSOPN.objects.create(ballot=ballot)
response = self.app.get(
ballot.get_absolute_url(),
user=self.user,
)
button = response.html.find("a", text=re.compile("Add a new candidate"))
self.assertIsNotNone(button)
self.assertIn("secondary", button["class"])