def setUp(self):
     super().setUp()
     PersonFactory.create(id=2009, name="Tessa Jowell")
     self.test_upload_user = User.objects.create_user(
         "john", "*****@*****.**", "notagoodpassword")
     self.test_upload_user.terms_agreement.assigned_to_dc = True
     self.test_upload_user.terms_agreement.save()
    def setUp(self):
        self.user2 = User.objects.create_user("jane", "*****@*****.**",
                                              "notagoodpassword")
        test_person_9876 = PersonFactory.create(
            id=9876, name="Test Candidate for the Leaderboard")
        test_person_1234 = PersonFactory.create(
            id=1234, name="Another Test Candidate for the Leaderboard")

        self.action1 = LoggedAction.objects.create(
            user=self.user,
            action_type="person-create",
            ip_address="127.0.0.1",
            person=test_person_9876,
            popit_person_new_version="1234567890abcdef",
            source="Just for tests...",
        )
        self.action2 = LoggedAction.objects.create(
            user=self.user2,
            action_type="candidacy-delete",
            ip_address="127.0.0.1",
            person=test_person_1234,
            popit_person_new_version="987654321",
            source="Also just for testing",
        )
        self.action2 = LoggedAction.objects.create(
            user=self.user2,
            action_type="candidacy-delete",
            ip_address="127.0.0.1",
            person=test_person_1234,
            popit_person_new_version="987654321",
            source="Also just for testing",
        )
Пример #3
0
    def setUp(self):
        cache.clear()

        self.election = ElectionFactory(
            name="2017 General Election",
            election_date="2017-06-08",
            slug="parl.2017-06-08",
            any_non_by_elections=True,
        )
        self.post = PostFactory(ynr_id="WMC:E14000639",
                                label="Cities of London and Westminster")
        self.post_election = PostElectionFactory(
            ballot_paper_id="parl.cities-of-london-and-westminster.2017-06-08",
            post=self.post,
            election=self.election,
        )
        PersonFactory.reset_sequence()
        person = PersonFactory()
        pe = PostElectionFactory(election=self.election, post=self.post)
        PersonPostFactory(
            post_election=pe,
            election=self.election,
            person=person,
            post=self.post,
            party=PartyFactory(),
        )
        self.expected_response = [{
            "ballot_paper_id":
            "parl.cities-of-london-and-westminster.2017-06-08",
            "absolute_url":
            "http://testserver/elections/parl.cities-of-london-and-westminster.2017-06-08/cities-of-london-and-westminster/",
            "election_date":
            "2017-06-08",
            "election_id":
            "parl.2017-06-08",
            "election_name":
            "2017 General Election",
            "post": {
                "post_name": "Cities of London and Westminster",
                "post_slug": "WMC:E14000639",
            },
            "cancelled":
            False,
            "replaced_by":
            None,
            "ballot_locked":
            False,
            "candidates": [{
                "list_position": None,
                "party": {
                    "party_id": "PP01",
                    "party_name": "Test Party",
                },
                "person": {
                    "absolute_url": "http://testserver/person/0/candidate-0",
                    "ynr_id": 0,
                    "name": "Candidate 0",
                },
            }],
        }]
 def tests_all_user_ids(self):
     joe = PersonFactory.create(id=1, name="Joe Bloggs")
     joe.identifiers.create(identifier="246", scheme="twitter")
     jane = PersonFactory.create(id=2, name="Jane Bloggs")
     jane.identifiers.create(identifier="357", scheme="twitter")
     twitter_data = TwitterAPIData()
     self.assertEqual(["246", "357"], sorted(twitter_data.all_user_ids))
    def setUp(self):
        super().setUp()

        tessa_jowell = PersonFactory.create(id=2009, name="Tessa Jowell")
        MembershipFactory.create(
            person=tessa_jowell,
            post=self.dulwich_post,
            party=self.labour_party,
            party_list_position=1,
            post_election=self.dulwich_post_pee,
        )

        winner = PersonFactory.create(id=4322, name="Helen Hayes")
        MembershipFactory.create(
            person=winner,
            post=self.dulwich_post,
            party=self.labour_party,
            party_list_position=2,
            post_election=self.dulwich_post_pee,
        )

        james_smith = PersonFactory.create(id=2010, name="James Smith")
        MembershipFactory.create(
            person=james_smith,
            post=self.dulwich_post,
            party=self.labour_party,
            party_list_position=3,
            post_election=self.dulwich_post_pee,
        )
Пример #6
0
    def setUp(self):
        super().setUp()
        update_lock(self.camberwell_post, self.election, True)
        post_locked = self.camberwell_post
        self.post_id = self.dulwich_post.id
        person = PersonFactory.create(id=4170, name="Naomi Newstead")

        MembershipFactory.create(
            person=person,
            post=post_locked,
            party=self.green_party,
            post_election=post_locked.postextraelection_set.get(
                election=self.election
            ),
        )

        person = PersonFactory.create(id=4322, name="Helen Hayes")

        MembershipFactory.create(
            person=person,
            post=self.dulwich_post,
            party=self.green_party,
            post_election=self.dulwich_post.postextraelection_set.get(
                election=self.election
            ),
        )
Пример #7
0
    def setUp(self):
        super().setUp()
        person_2009 = PersonFactory.create(id=2009, name="Tessa Jowell")
        person_2007 = PersonFactory.create(id=2007, name="Tessa Jowell")
        MembershipFactory.create(
            person=person_2009,
            post=self.dulwich_post,
            party=self.labour_party,
            ballot=self.dulwich_post_ballot,
        )
        MembershipFactory.create(
            person=person_2007,
            post=self.dulwich_post,
            party=self.labour_party,
            ballot=self.dulwich_post_ballot,
        )

        self.test_upload_user = User.objects.create_user(
            "john", "*****@*****.**", "notagoodpassword")
        self.test_upload_user.terms_agreement.assigned_to_dc = True
        self.test_upload_user.terms_agreement.save()
        self.test_reviewer = User.objects.create_superuser(
            "jane", "*****@*****.**", "alsonotagoodpassword")
        self.test_reviewer.terms_agreement.assigned_to_dc = True
        self.test_reviewer.terms_agreement.save()
        group, _ = Group.objects.get_or_create(name=PHOTO_REVIEWERS_GROUP_NAME)
        self.test_reviewer.groups.add(group)
        self.q1 = QueuedImage.objects.create(
            why_allowed="public-domain",
            justification_for_use="It's their Twitter avatar",
            decision="undecided",
            image=self.storage_filename,
            person=person_2009,
            user=self.test_upload_user,
        )
        self.q2 = QueuedImage.objects.create(
            why_allowed="copyright-assigned",
            justification_for_use="I took this last week",
            decision="approved",
            image=self.storage_filename,
            person=person_2007,
            user=self.test_upload_user,
        )
        self.q3 = QueuedImage.objects.create(
            why_allowed="other",
            justification_for_use="I found it somewhere",
            decision="rejected",
            image=self.storage_filename,
            person=person_2007,
            user=self.test_reviewer,
        )
        self.q_no_uploading_user = QueuedImage.objects.create(
            why_allowed="profile-photo",
            justification_for_use="Auto imported from Twitter",
            decision="undecided",
            image=self.storage_filename,
            person=person_2009,
            user=None,
        )
Пример #8
0
 def setUp(self):
     # super().setUp()
     self.person = PersonFactory(name=faker_factory.name())
     self.pi = PersonIdentifier.objects.create(
         person=self.person,
         value="democlub",
         value_type="twitter_username",
         internal_identifier="123456",
     )
Пример #9
0
    def setUp(self):
        cache.clear()

        self.election = ElectionFactory(
            name="2017 General Election",
            election_date="2017-06-08",
            slug="parl.2017-06-08",
            any_non_by_elections=True,
        )
        self.post = PostFactory(
            ynr_id="WMC:E14000639", label="Cities of London and Westminster"
        )
        self.post_election = PostElectionFactory(
            ballot_paper_id="parl.cities-of-london-and-westminster.2017-06-08",
            post=self.post,
            election=self.election,
        )
        PersonFactory.reset_sequence()
        person = PersonFactory()
        pe = PostElectionFactory(election=self.election, post=self.post)
        PersonPostFactory(
            post_election=pe,
            election=self.election,
            person=person,
            post=self.post,
            party=PartyFactory(),
        )
        self.expected_response = [
            {
                "ballot_paper_id": "parl.cities-of-london-and-westminster.2017-06-08",
                "absolute_url": "http://testserver/elections/parl.cities-of-london-and-westminster.2017-06-08/cities-of-london-and-westminster/",
                "election_date": "2017-06-08",
                "election_id": "parl.2017-06-08",
                "election_name": "2017 General Election",
                "post": {
                    "post_name": "Cities of London and Westminster",
                    "post_slug": "WMC:E14000639",
                },
                "cancelled": False,
                "replaced_by": None,
                "ballot_locked": False,
                "candidates": [
                    {
                        "list_position": None,
                        "party": {
                            "party_id": "PP01",
                            "party_name": "Test Party",
                        },
                        "person": {
                            "absolute_url": "http://testserver/person/0/candidate-0",
                            "ynr_id": 0,
                            "name": "Candidate 0",
                        },
                    }
                ],
            }
        ]
Пример #10
0
    def set_data(self):
        self.company1 = CompanyFactory(index=1, name="Company")
        self.company2 = CompanyFactory(index=2, name="Corporation")
        self.company3 = CompanyFactory(index=3, name="Enterprise")

        self.person1 = PersonFactory(index=1, company=self.company1)
        self.person2 = PersonFactory(index=2, company=self.company1)
        self.person3 = PersonFactory(index=3, company=self.company1)
        self.person4 = PersonFactory(index=4, company=self.company3)
    def setUp(self):
        super().setUp()
        person = PersonFactory.create(id=2009, name="Tessa Jowell")
        dulwich_not_stand = PersonFactory.create(id=4322, name="Helen Hayes")
        MembershipFactory.create(
            person=person,
            post=self.dulwich_post,
            party=self.labour_party,
            post_election=self.dulwich_post_pee,
        )

        winner_post = self.edinburgh_east_post

        edinburgh_candidate = PersonFactory.create(
            id="818", name="Sheila Gilmore"
        )
        edinburgh_winner = PersonFactory.create(
            id="5795", name="Tommy Sheppard"
        )
        edinburgh_may_stand = PersonFactory.create(
            id="5163", name="Peter McColl"
        )

        MembershipFactory.create(
            person=dulwich_not_stand,
            post=self.dulwich_post,
            party=self.labour_party,
            post_election=self.dulwich_post_pee_earlier,
        )
        dulwich_not_stand.not_standing.add(self.election)

        MembershipFactory.create(
            person=edinburgh_winner,
            post=winner_post,
            party=self.labour_party,
            elected=True,
            post_election=self.election.postextraelection_set.get(
                post=winner_post
            ),
        )

        MembershipFactory.create(
            person=edinburgh_candidate,
            post=winner_post,
            party=self.labour_party,
            post_election=self.dulwich_post_pee,
        )

        MembershipFactory.create(
            person=edinburgh_may_stand,
            post=winner_post,
            party=self.labour_party,
            post_election=self.earlier_election.postextraelection_set.get(
                post=winner_post
            ),
        )
 def setUp(self):
     super().setUp()
     PersonFactory.create(id=2009, name="Tessa Jowell")
     self.test_upload_user = User.objects.create_user(
         "john", "*****@*****.**", "notagoodpassword")
     self.test_upload_user.terms_agreement.assigned_to_dc = True
     self.test_upload_user.terms_agreement.save()
     upload_form_url = reverse("photo-upload", kwargs={"person_id": "2009"})
     self.form_page_response = self.app.get(upload_form_url,
                                            user=self.test_upload_user)
Пример #13
0
 def test_all_screen_names(self):
     joe = PersonFactory.create(id=1, name="Joe Bloggs")
     joe.tmp_person_identifiers.create(value="joenotreallyatwitteraccount",
                                       value_type="twitter_username")
     jane = PersonFactory.create(id=2, name="Jane Bloggs")
     jane.tmp_person_identifiers.create(
         value="janenotreallyatwitteraccount",
         value_type="twitter_username")
     twitter_data = TwitterAPIData()
     self.assertEqual(
         ["janenotreallyatwitteraccount", "joenotreallyatwitteraccount"],
         sorted(twitter_data.all_screen_names),
     )
    def test_current_elections_standing_down(self):
        person = PersonFactory(name=faker_factory.name())
        self.assertEqual(person.current_elections_standing_down(), [])
        Membership.objects.create(
            ballot=self.dulwich_post_ballot_earlier,
            party=self.ld_party,
            person=person,
            elected=True,
        )

        person.not_standing.add(self.election)
        self.assertEqual(person.current_elections_standing_down(),
                         [self.election])
 def setUp(self):
     super().setUp()
     self.person_no_other = PersonFactory.create(id=1234, name="John Smith")
     self.person_other_names = PersonFactory.create(id=5678, name="Fozzie")
     self.fozziewig = OtherName.objects.create(
         content_object=self.person_other_names,
         name="Mr Fozziewig",
         note="In a Muppet Christmas Carol",
     )
     self.fozzie_bear = OtherName.objects.create(
         content_object=self.person_other_names,
         name="Fozzie Bear",
         note="Full name",
     )
 def test_all_screen_names(self):
     joe = PersonFactory.create(id=1, name="Joe Bloggs")
     joe.contact_details.create(
         value="joenotreallyatwitteraccount", contact_type="twitter"
     )
     jane = PersonFactory.create(id=2, name="Jane Bloggs")
     jane.contact_details.create(
         value="janenotreallyatwitteraccount", contact_type="twitter"
     )
     twitter_data = TwitterAPIData()
     self.assertEqual(
         ["janenotreallyatwitteraccount", "joenotreallyatwitteraccount"],
         sorted(twitter_data.all_screen_names),
     )
Пример #17
0
    def test_party_detail_candidate_count_view(self):
        # Make a 2nd candidate
        pe = PostElectionFactory(
            election=ElectionFactory(slug="2010", name="2010 GE"),
            post=self.post,
        )
        PersonPostFactory(
            post_election=pe,
            party=self.party,
            election=pe.election,
            post=self.post,
        )
        p2 = PersonFactory(name="Test 3")
        PersonPostFactory(
            post_election=self.pe,
            person=p2,
            post=self.post,
            election=self.election,
            party=self.party,
        )

        # TODO Use reverse here
        response = self.client.get("/parties/{}/london".format(
            self.party.party_id),
                                   follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "3 candidates")
        x = response.context_data["object"]
        assert len(x.personpost_set.all().counts_by_post()) == 2
Пример #18
0
 def setUp(self):
     for person_details in [
         {
             "attr": "just_screen_name",
             "name": "Person with just a Twitter screen name",
             # We'll get the API to return 321 for their user_id
             "screen_name": "notreallyatwitteraccount",
         },
         {
             "attr": "just_userid",
             "name": "Person with just a Twitter user ID",
             "user_id": "987",
         },
         {
             "attr": "no_twitter",
             "name": "Person with no Twitter details"
         },
         {
             "attr": "screen_name_and_user_id",
             "name": "Someone with a Twitter screen name and user ID",
             "user_id": "765",
             "screen_name": "notatwitteraccounteither",
         },
     ]:
         person = PersonFactory.create(name=person_details["name"])
         setattr(self, person_details["attr"], person)
         if "user_id" in person_details:
             person.identifiers.create(identifier=person_details["user_id"],
                                       scheme="twitter")
         if "screen_name" in person_details:
             person.contact_details.create(
                 value=person_details["screen_name"],
                 contact_type="twitter")
Пример #19
0
 def test_candidates_for_postcode_view(self):
     person = PersonFactory()  # Make a person
     PersonPostFactory(election=self.election,
                       person=person,
                       post=self.post,
                       party=PartyFactory())
     url = reverse('api:candidates-for-postcode-list')
     with self.assertNumQueries(2):
         req = self.client.get("{}?postcode=EC1A4EU".format(url))
     assert req.status_code == 200
     assert req.data == [{
         'election_date':
         datetime.date(2017, 6, 8),
         'election_id':
         'parl.2017-06-08',
         'election_name':
         '2017 General Election',
         'post': {
             'post_name': 'Cities of London and Westminster',
             'post_slug': 'WMC:E14000639'
         },
         'candidates': [{
             'list_position': None,
             'party': {
                 'party_id': 'PP01',
                 'party_name': 'Test Party'
             },
             'person': {
                 'ynr_id': '0',
                 'name': 'Candidate 0'
             }
         }],
     }]
Пример #20
0
class PersonViewTests(TestCase):
    def setUp(self):
        self.person = PersonFactory()
        self.person_url = self.person.get_absolute_url()

    def test_person_view(self):
        response = self.client.get(self.person_url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'people/person_detail.html')


    def test__correct_elections_listed(self):
        response = self.client.get(self.person_url, follow=True)

        election_name = "FooBar Election 2017"

        self.assertNotContains(response, election_name)
        election = ElectionFactory(
            name=election_name,
            current=True,
            slug="foobar")
        PersonPostFactory(election=election, person=self.person)

        response = self.client.get(self.person_url, follow=True)
        self.assertContains(response, election_name)
Пример #21
0
    def test_delete_elections_with_related_membership(self, mock_requests):
        # import some data
        mock_requests.get.side_effect = create_mock_with_fixtures({
            urljoin(EE_BASE_URL, "/api/elections/?current=True"):
            local_highland,
            urljoin(EE_BASE_URL, "/api/elections/?current=1&deleted=1"):
            no_results,
        })
        call_command("uk_create_elections_from_every_election")
        self.assertEqual(
            every_election.PostExtraElection.objects.all().count(), 1)
        self.assertEqual(every_election.YNRElection.objects.all().count(), 1)

        # create a membership which references the PEE we just imported
        MembershipFactory(
            person=PersonFactory.create(id=2009, name="Tessa Jowell"),
            post_election=every_election.PostExtraElection.objects.all()[0],
        )

        # now we've switched the fixtures round
        # so the records we just imported are deleted in EE
        mock_requests.get.side_effect = create_mock_with_fixtures({
            urljoin(EE_BASE_URL, "/api/elections/?current=True"):
            no_results,
            urljoin(EE_BASE_URL, "/api/elections/?current=1&deleted=1"):
            local_highland,
        })
        # make sure we throw an exception
        with self.assertRaises(Exception):
            call_command("uk_create_elections_from_every_election")

        # we should also roll back the whole transaction so nothing is deleted
        self.assertEqual(
            every_election.PostExtraElection.objects.all().count(), 1)
        self.assertEqual(every_election.YNRElection.objects.all().count(), 1)
Пример #22
0
    def setUp(self):
        for person_details in [
            {
                "attr": "just_screen_name",
                "name": "Person with just a Twitter screen name",
                # We'll get the API to return 321 for their user_id
                "screen_name": "notreallyatwitteraccount",
            },
            {
                "attr": "just_userid",
                "name": "Person with just a Twitter user ID",
                "user_id": "987",
            },
            {
                "attr": "no_twitter",
                "name": "Person with no Twitter details"
            },
            {
                "attr": "screen_name_and_user_id",
                "name": "Someone with a Twitter screen name and user ID",
                "user_id": "765",
                "screen_name": "notatwitteraccounteither",
            },
        ]:
            person = PersonFactory.create(name=person_details["name"])
            setattr(self, person_details["attr"], person)

            person.tmp_person_identifiers.create(
                internal_identifier=person_details.get("user_id", None),
                value_type="twitter_username",
                value=person_details.get("screen_name", ""),
            )
 def test_constituency_unlock(self):
     MembershipFactory(
         ballot=self.dulwich_post_ballot,
         person=PersonFactory(),
         party=PartyFactory(),
     )
     ballot = self.dulwich_post_ballot
     ballot.candidates_locked = True
     ballot.save()
     response = self.app.get(
         self.dulwich_post_ballot.get_absolute_url(),
         user=self.user_who_can_lock,
     )
     csrftoken = self.app.cookies["csrftoken"]
     self.assertContains(response, "Unlock candidate list")
     response = self.app.post(
         reverse(
             "constituency-lock",
             kwargs={"ballot_id": ballot.ballot_paper_id},
         ),
         params={"csrfmiddlewaretoken": csrftoken},
         user=self.user_who_can_lock,
     )
     ballot.refresh_from_db()
     self.assertFalse(ballot.candidates_locked)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.location,
                      self.dulwich_post_ballot.get_absolute_url())
Пример #24
0
 def setUp(self):
     super().setUp()
     person_2009 = PersonFactory.create(id=2009, name="Tessa Jowell")
     person_2007 = PersonFactory.create(id=2007, name="Tessa Jowell")
     MembershipFactory.create(
         person=person_2009,
         post=self.dulwich_post,
         party=self.labour_party,
         ballot=self.dulwich_post_ballot,
     )
     MembershipFactory.create(
         person=person_2007,
         post=self.dulwich_post,
         party=self.labour_party,
         ballot=self.dulwich_post_ballot,
     )
    def setUp(self):
        super().setUp()
        constituencies = {}
        for slug, cons_name, country in [
            ("66090", "Cardiff Central", "Wales"),
            ("65672", "Doncaster North", "England"),
            ("65719", "South Shields", "England"),
        ]:
            constituencies[cons_name] = PostFactory.create(
                elections=(self.election, self.earlier_election),
                organization=self.commons,
                slug=slug,
                label="Member of Parliament for {}".format(cons_name),
                group=country,
            )

        person = PersonFactory.create(id=3056, name="Ed Miliband")
        MembershipFactory.create(
            person=person,
            post=constituencies["Doncaster North"],
            party=self.labour_party,
            ballot=self.election.ballot_set.get(
                post=constituencies["Doncaster North"]
            ),
        )
        person = PersonFactory.create(id=3814, name="David Miliband")
        MembershipFactory.create(
            person=person,
            post=constituencies["South Shields"],
            party=self.labour_party,
            ballot=self.earlier_election.ballot_set.get(
                post=constituencies["South Shields"]
            ),
        )
        conservative_opponent = PersonFactory.create(
            id="6648", name="Mark Fletcher"
        )
        MembershipFactory.create(
            person=conservative_opponent,
            post=constituencies["South Shields"],
            party=self.conservative_party,
            ballot=self.election.ballot_set.get(
                post=constituencies["South Shields"]
            ),
        )
 def setUp(self):
     super().setUp()
     person = PersonFactory.create(id=2009, name="Tessa Jowell")
     MembershipFactory.create(
         person=person,
         post=self.dulwich_post,
         party=self.labour_party,
         post_election=self.dulwich_post_pee,
     )
Пример #27
0
 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,
         post_election=self.camberwell_post_pee_earlier,
     )
Пример #28
0
 def setUp(self):
     self.election = ElectionFactory()
     self.post = PostFactory()
     people = [PersonFactory() for p in range(5)]
     for person in people:
         PersonPostFactory(
             election=self.election,
             post=self.post,
             person=person,
         )
Пример #29
0
    def setUp(self):
        super().setUp()
        self.ballot = self.dulwich_post_ballot_earlier
        person = PersonFactory.create(id=2009, name="Tessa Jowell")
        MembershipFactory.create(
            person=person,
            post=self.dulwich_post,
            party=self.labour_party,
            ballot=self.ballot,
        )

        self.winner = PersonFactory.create(id=4322, name="Helen Hayes")

        MembershipFactory.create(
            person=self.winner,
            post=self.dulwich_post,
            party=self.labour_party,
            ballot=self.dulwich_post_ballot_earlier,
        )
    def setUp(self):
        super().setUp()
        person = PersonFactory.create(id=2009, name="Tessa Jowell")
        MembershipFactory.create(
            person=person,
            post=self.dulwich_post,
            party=self.labour_party,
            post_election=self.dulwich_post_pee,
        )

        self.winner = PersonFactory.create(id=4322, name="Helen Hayes")

        MembershipFactory.create(
            person=self.winner,
            post=self.dulwich_post,
            party=self.labour_party,
            elected=True,
            post_election=self.dulwich_post_pee,
        )
Пример #31
0
    def test_person_view(self):
        req = self.client.get(reverse("api:person-list"))
        assert req.status_code == 200
        assert req.data == []

        PersonFactory()  # Make a person

        req = self.client.get(reverse("api:person-list"))
        assert req.status_code == 200
        assert len(req.data) == 1
class AuthorFeedAnyLanguageTestCase(ViewTestMixin, TestCase):
    """Tests for the ``AuthorFeed`` view class."""

    def setUp(self):
        factories.NewsEntryFactory()
        self.author = PersonFactory()

    def get_view_name(self):
        return 'news_rss_any_author'

    def get_view_kwargs(self):
        # TODO ID is no pretty solution
        return {'author': self.author.id, 'any_language': True}

    def test_view(self):
        self.is_callable()

    def test_author_does_not_exist(self):
        self.author.delete()
        self.assertRaises(NoReverseMatch, self.is_callable)
 def setUp(self):
     factories.NewsEntryFactory()
     self.author = PersonFactory()
class PersonViewTests(TestCase):
    def setUp(self):
        self.party = PartyFactory()
        self.person = PersonFactory()
        self.person_url = self.person.get_absolute_url()

    def test_person_view(self):
        response = self.client.get(self.person_url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "people/person_detail.html")

    def test_correct_elections_listed(self):
        response = self.client.get(self.person_url, follow=True)

        election_name = "FooBar Election 2017"

        self.assertNotContains(response, election_name)
        election = ElectionFactory(
            name=election_name,
            current=True,
            election_date="2040-01-01",
            slug="local.foobar.2040-01-01",
        )
        post = PostFactory()
        pe = PostElectionFactory(
            election=election,
            post=post,
            ballot_paper_id="local.foo.bar.2040-01-01",
        )
        PersonPostFactory(
            post_election=pe,
            election=election,
            person=self.person,
            party=self.party,
        )

        response = self.client.get(self.person_url, follow=True)
        self.assertContains(response, election_name)
        self.assertContains(response, "is the")

    def test_election_in_past_listed(self):
        response = self.client.get(self.person_url, follow=True)

        election_name = "FooBar Election 2017"

        self.assertNotContains(response, election_name)
        election = ElectionFactory(
            name=election_name,
            current=True,
            election_date="2017-01-01",
            slug="local.foobar.2017-01-01",
        )
        post = PostFactory()
        pe = PostElectionFactory(
            election=election,
            post=post,
            ballot_paper_id="local.foo.bar.2017-01-01",
        )
        PersonPostFactory(
            post_election=pe,
            election=election,
            person=self.person,
            party=self.party,
        )

        response = self.client.get(self.person_url, follow=True)
        self.assertContains(response, election_name)
        self.assertContains(response, "was the")
 def setUp(self):
     self.party = PartyFactory()
     self.person = PersonFactory()
     self.person_url = self.person.get_absolute_url()