Skip to content

Commit

Permalink
Refactor template tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VirginiaDooley committed Feb 23, 2021
1 parent a73e75a commit da66f08
Showing 1 changed file with 214 additions and 0 deletions.
214 changes: 214 additions & 0 deletions wcivf/apps/people/tests/test_person_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ElectionFactory,
PostFactory,
PostElectionFactory,
ElectionFactoryLazySlug,
)
from people.views import PersonView

Expand Down Expand Up @@ -174,3 +175,216 @@ def view_obj(self, rf):
def test_get_template_names(self, view_obj, object, expected):
view_obj.object = object
assert view_obj.get_template_names() == [expected]
# def test_one_candidacy_intro(self):
# election = ElectionFactory()
# party = PartyFactory(party_name="Conservative and Unionist", party_id="ConUnion")
# PersonPostFactory(
# person=self.person, election=election, party=party
# )
# response = self.client.get(self.person_url, follow=True)
# self.assertContains(
# response, "Tony Devenish is the Conservative and Unionist Party candidate in West Central in the London Assembly elections (Constituencies)."
# )

# def test_no_previous_elections(self):
# response = self.client.get(self.person_url, follow=True)
# self.assertEqual(response.template_name, ["people/person_detail.html"])
# self.assertNotContains(response, "Previous Elections")

# def test_previous_elections(self):
# election=ElectionFactory()
# party = PartyFactory(party_name="Liberal Democrat", party_id="foo")
# person_post=PersonPostFactory(
# person=self.person, election=election, party=party, votes_cast=1000
# )
# response = self.client.get(self.person_url, follow=True)
# self.assertEqual(response.template_name, ["people/person_detail.html"])
# self.assertContains(response, "Previous Elections")
# # self.assertContains(response, self.person_post.election.election_date)
# # self.assertContains(response, self.person_post.election)
# # self.assertContains(response, self.person_post.party.party_name)
# self.assertContains(response, self.person_post.votes_cast)

def test_no_statement_to_voters(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "Statement to voters")

def test_statement_to_voters(self):
self.person.statement_to_voters = "I believe in equal rights."
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(response, "Statement to voters")

# def test_no_manifesto(self):
# party = PartyFactory(party_name="Liberal Democrat", party_id="foo")
# PersonPostFactory(person=self.person, party=party, election=ElectionFactory())
# response = self.client.get(self.person_url, follow=True)
# self.assertEqual(response.template_name, ["people/person_detail.html"])
# self.assertNotContains(response, "Party manifesto")

# def test_manifesto(self):
# self.person.manifestos = "http://www.mymanifesto.org"
# self.person.save()
# party = PartyFactory(party_name="Liberal Democrat", party_id="foo")
# PersonPostFactory(person=self.person, party=party, election=ElectionFactory())
# response = self.client.get(self.person_url, follow=True)
# self.assertEqual(response.template_name, ["people/person_detail.html"])
# self.assertContains(response, "Party manifesto")

# def test_leaflets(self):
# self.person.leaflet_set.exists = True
# self.person.save()
# PersonPostFactory(person=self.person, election=ElectionFactory())
# response = self.client.get(self.person_url, follow=True)
# self.assertEqual(response.template_name, ["people/person_detail.html"])
# self.assertContains(response, "Recent leaflets from ")

def test_no_pledges(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "Candidate pledges")

# def test_pledges(self):
# self.person.pledges =
# self.person.save()
# PersonPostFactory(person=self.person, election=ElectionFactory())
# response = self.client.get(self.person_url, follow=True)
# self.assertEqual(response.template_name, ["people/person_detail.html"])
# self.assertContains(response, "Candidate pledges")

def test_no_TWFY(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "Record in office")

def test_TWFY(self):
self.person.twfy_id = 123
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(response, "Record in office")

# def test_no_CV(self):
# PersonPostFactory(person=self.person, election=ElectionFactory())
# response = self.client.get(self.person_url, follow=True)
# self.assertEqual(response.template_name, ["people/person_detail.html"])
# self.assertNotContains(response, "CV")

# def test_CV(self):
# self.person.cv =
# self.person.save()
# PersonPostFactory(person=self.person, election=ElectionFactory())
# response = self.client.get(self.person_url, follow=True)
# self.assertEqual(response.template_name, ["people/person_detail.html"])
# self.assertContains(response, "CV")

def test_no_wikipedia(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "Wikipedia")

def test_wikipedia(self):
self.person.wikipedia_bio = "yo"
self.person.wikipedia_url = "https//www.wikipedia.com/yo"
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(response, "Wikipedia")

def test_no_facebook(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "username")

def test_facebook(self):
self.person.facebook_personal_url = "https//www.facebook.com/yo"
self.person.facebook_page_url = "https//www.facebook.com/yo"
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(response, "yo")

def test_no_linkedin(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "LinkedIn")

def test_linkedin(self):
self.person.linkedin_url = "https://www.linkedin.com/yo"
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(response, "LinkedIn")

def test_instagram(self):
self.person.instagram_url = "https://www.instagram.com/yo"
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(response, "Instagram")

def test_no_instagram(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "Instagram")

def test_party_page(self):
self.person.party_ppc_page_url = "https://www.voteforme.com/bob"
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(
response, "The party's candidate page for this person"
)

def test_no_party_page(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(
response, "The party's candidate page for this person"
)

def test_no_youtube(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "YouTube")

def test_youtube(self):
self.person.youtube_profile = "Mary123"
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(response, "YouTube")

def test_email(self):
self.person.email = "me@voteforme.com"
self.person.save()
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertContains(response, "Email")

def test_no_email(self):
PersonPostFactory(person=self.person, election=ElectionFactory())
response = self.client.get(self.person_url, follow=True)
self.assertEqual(response.template_name, ["people/person_detail.html"])
self.assertNotContains(response, "Email")

0 comments on commit da66f08

Please sign in to comment.