def test_child_visibility(self):
        # 4 ballots in the same group with different moderation statuses
        group = ElectionWithStatusFactory(
            group_type="election",
            moderation_status=related_status("Approved"))
        approved = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Approved"))
        suggested = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Suggested"))
        rejected = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Rejected"))
        deleted = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Deleted"))

        resp = self.client.get("/api/elections/{}/".format(group.election_id))
        self.assertEqual(200, resp.status_code)
        data = resp.json()
        # only the approved child election should be in the response
        self.assertEqual(1, len(data["children"]))
        self.assertEqual([approved.election_id], data["children"])

        # delete the group
        ModerationHistoryFactory(
            election=group,
            status=ModerationStatusFactory(short_label="Deleted"))
        resp = self.client.get("/api/elections/{}/?deleted=1".format(
            group.election_id))
        self.assertEqual(200, resp.status_code)
        data = resp.json()
        # deleted and approved child elections should be in the response
        self.assertTrue(deleted.election_id in data["children"])
        self.assertTrue(approved.election_id in data["children"])
        # we should never show suggested or rejected elections in API outputs
        self.assertTrue(suggested.election_id not in data["children"])
        self.assertTrue(rejected.election_id not in data["children"])
Exemple #2
0
    def test_election_status(self):
        # 4 ballots with different moderation statuses
        approved = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Approved"))
        suggested = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Suggested"))
        rejected = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Rejected"))
        deleted = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Deleted"))

        # approved elections shoud be visible via the DetailView
        resp = self.client.get("/elections/{}/".format(approved.election_id))
        self.assertEqual(200, resp.status_code)

        # we shouldn't be able to access elections which are
        # suggsted, rejected or deleted via the DetailView
        resp = self.client.get("/api/elections/{}/".format(
            rejected.election_id))
        self.assertEqual(404, resp.status_code)
        resp = self.client.get("/api/elections/{}/".format(
            suggested.election_id))
        self.assertEqual(404, resp.status_code)
        resp = self.client.get("/api/elections/{}/".format(
            deleted.election_id))
        self.assertEqual(404, resp.status_code)
 def test_has_approved_parents_two_level(self):
     org_group = ElectionWithStatusFactory(
         group=None, moderation_status=related_status("Suggested"))
     ballot = ElectionWithStatusFactory(
         group=org_group, moderation_status=related_status("Approved"))
     self.assertFalse(has_approved_parents(ballot))
     ModerationHistoryFactory(
         election=org_group,
         status=ModerationStatusFactory(short_label="Approved"))
     self.assertTrue(has_approved_parents(ballot))
 def test_public_private_filter_simple(self):
     # simple case: each election only has a single status event
     ElectionWithStatusFactory(
         group=None, moderation_status=related_status("Suggested"))
     ElectionWithStatusFactory(group=None,
                               moderation_status=related_status("Approved"))
     ElectionWithStatusFactory(group=None,
                               moderation_status=related_status("Rejected"))
     ElectionWithStatusFactory(group=None,
                               moderation_status=related_status("Deleted"))
     self.assertEqual(1, Election.public_objects.count())
     self.assertEqual(4, Election.private_objects.count())
    def test_has_approved_child(self):
        org_group = ElectionWithStatusFactory(group=None)
        ballots = [
            ElectionWithStatusFactory(
                group=org_group,
                moderation_status=related_status("Suggested")),
            ElectionWithStatusFactory(
                group=org_group,
                moderation_status=related_status("Suggested")),
        ]
        self.assertFalse(has_approved_child(org_group))

        # approve one of the 2 child ballots
        ModerationHistoryFactory(
            election=ballots[0],
            status=ModerationStatusFactory(short_label="Approved"))
        self.assertTrue(has_approved_child(org_group))
    def test_approve(self):
        self.login()
        # 4 ballots with different moderation statuses
        approved = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Approved"))
        rejected = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Rejected"))
        deleted = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Deleted"))

        suggested_parent = ElectionWithStatusFactory(
            group=None,
            group_type="organisation",
            moderation_status=related_status("Suggested"),
        )
        suggested_child = ElectionWithStatusFactory(
            group=suggested_parent,
            moderation_status=related_status("Suggested"))

        resp = self.client.get("/election_radar/moderation_queue/")
        self.assertEqual(200, resp.status_code)

        # only suggested ballot should be shown
        self.assertNotContains(resp, approved.election_id, html=True)
        self.assertNotContains(resp, rejected.election_id, html=True)
        self.assertNotContains(resp, deleted.election_id, html=True)

        # only ballots should be shown
        self.assertContains(resp, suggested_child.election_id, html=True)
        self.assertNotContains(resp, suggested_parent.election_id, html=True)

        self.client.post(
            "/election_radar/moderation_queue/",
            {
                "election": suggested_child.pk,
                "{}-status".format(suggested_child.pk): "Approved",
            },
        )

        # approving the child should
        # implicitly approve the parent
        # if it is not already approved
        self.assertEqual("Approved",
                         suggested_child.moderation_status.short_label)
        self.assertEqual("Approved",
                         suggested_parent.moderation_status.short_label)
    def test_deleted_filter_detail(self):
        election = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Deleted"))
        id_ = election.election_id

        resp = self.client.get("/api/elections/{}/".format(id_))
        self.assertEqual(404, resp.status_code)

        resp = self.client.get("/api/elections/{}/?deleted=1".format(id_))
        self.assertEqual(200, resp.status_code)
    def test_has_approved_parents_three_level(self):
        election_group = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Suggested"))
        org_group = ElectionWithStatusFactory(
            group=election_group,
            moderation_status=related_status("Suggested"))
        ballot = ElectionWithStatusFactory(group=org_group)
        self.assertFalse(has_approved_parents(ballot))

        ModerationHistoryFactory(
            election=election_group,
            status=ModerationStatusFactory(short_label="Approved"),
        )
        # still false because only one of our 2 parents is approved
        self.assertFalse(has_approved_parents(ballot))

        ModerationHistoryFactory(
            election=org_group,
            status=ModerationStatusFactory(short_label="Approved"))
        # now both parents are approved
        self.assertTrue(has_approved_parents(ballot))
Exemple #9
0
    def test_child_election_status(self):
        # 4 ballots in the same group with different moderation statuses
        group = ElectionWithStatusFactory(
            group_type="election",
            moderation_status=related_status("Approved"))
        approved = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Approved"))
        suggested = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Suggested"))
        rejected = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Rejected"))
        deleted = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Deleted"))

        # DetailView should only show approved child elections
        resp = self.client.get("/elections/{}/".format(group.election_id))
        self.assertEqual(200, resp.status_code)
        self.assertContains(resp, approved.election_id, html=True)
        self.assertNotContains(resp, suggested.election_id, html=True)
        self.assertNotContains(resp, rejected.election_id, html=True)
        self.assertNotContains(resp, deleted.election_id, html=True)
    def test_deleted_filter_list(self):
        approved = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Approved"))
        deleted = ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Deleted"))
        ElectionWithStatusFactory(group=None,
                                  moderation_status=related_status("Rejected"))
        ElectionWithStatusFactory(
            group=None, moderation_status=related_status("Suggested"))

        resp = self.client.get("/api/elections/")
        data = resp.json()
        self.assertEqual(1, data["count"])
        self.assertEqual(data["results"][0]["election_id"],
                         approved.election_id)
        self.assertEqual(data["results"][0]["deleted"], False)

        resp = self.client.get("/api/elections/?deleted=1")
        data = resp.json()
        self.assertEqual(1, data["count"])
        self.assertEqual(data["results"][0]["election_id"],
                         deleted.election_id)
        self.assertEqual(data["results"][0]["deleted"], True)
    def test_identifier_type_filter(self):
        group = ElectionWithStatusFactory(
            group_type="election",
            moderation_status=related_status("Approved"))
        ballot = ElectionWithStatusFactory(
            group=group, moderation_status=related_status("Approved"))

        resp = self.client.get("/api/elections/?identifier_type=election")
        data = resp.json()
        self.assertEqual(1, data["count"])
        self.assertEqual(data["results"][0]["election_id"], group.election_id)

        resp = self.client.get("/api/elections/?identifier_type=ballot")
        data = resp.json()
        self.assertEqual(1, data["count"])
        self.assertEqual(data["results"][0]["election_id"], ballot.election_id)

        resp = self.client.get("/api/elections/?identifier_type=organisation")
        data = resp.json()
        self.assertEqual(0, data["count"])

        resp = self.client.get("/api/elections/?identifier_type=foobar")
        data = resp.json()
        self.assertEqual(0, data["count"])