Exemplo n.º 1
0
    def setUp(self):
        super(TestRegion, self).setUp()

        self.org = factories.Org()

        self.temba_groups = {
            '1': TembaGroup.create(uuid="1", name="Uganda"),
            '2': TembaGroup.create(uuid="2", name="Kampala"),
            '3': TembaGroup.create(uuid="3", name="Entebbe"),
            '4': TembaGroup.create(uuid="4", name="Makerere"),
        }

        self.uganda = factories.Region(org=self.org, uuid='1', name="Uganda")
        self.kampala = factories.Region(org=self.org,
                                        uuid='2',
                                        name="Kampala",
                                        parent=self.uganda)
        self.entebbe = factories.Region(org=self.org,
                                        uuid='3',
                                        name="Entebbe",
                                        parent=self.uganda)
        self.makerere = factories.Region(org=self.org,
                                         uuid='4',
                                         name="makerere",
                                         parent=self.kampala)
        self.inactive = factories.Region(org=self.org,
                                         uuid='5',
                                         name="inactive",
                                         parent=self.kampala,
                                         is_active=False)

        self.mock_temba_client.get_contacts.return_value = []
Exemplo n.º 2
0
    def make_regions(self):
        """Create a collection of nested regions."""
        self.region_uganda = factories.Region(org=self.org, name="Uganda")
        self.region_kampala = factories.Region(org=self.org,
                                               name="Kampala",
                                               parent=self.region_uganda)
        self.region_makerere = factories.Region(org=self.org,
                                                name="Makerere",
                                                parent=self.region_kampala)
        self.region_entebbe = factories.Region(org=self.org,
                                               name="Entebbe",
                                               parent=self.region_uganda)
        self.region_kenya = factories.Region(org=self.org, name="Kenya")
        self.region_nairobi = factories.Region(org=self.org,
                                               name="Nairobi",
                                               parent=self.region_kenya)
        self.region_mombasa = factories.Region(org=self.org,
                                               name="Mombasa",
                                               parent=self.region_kenya)

        self.region_inactive = factories.Region(org=self.org,
                                                name="Inactive",
                                                parent=self.region_nairobi,
                                                is_active=False)

        return Region.get_all(self.org)
Exemplo n.º 3
0
    def setUp(self):
        super(TestSetRegion, self).setUp()
        self.org = factories.Org()
        self.region = factories.Region(org=self.org)

        self.user = factories.User()
        self.user.regions.add(self.region)

        self.login(self.user)
Exemplo n.º 4
0
 def test_post_other_org_parent(self):
     """Submitted data should not reference parents from another org."""
     other_region = factories.Region()  # another org
     regions = self.make_regions()
     structure = self.get_structure(regions)
     structure[regions.first().pk] = [other_region.pk, None]
     self.assertErrorResponse(
         data={'data': json.dumps(structure)},
         message="Region parent must be a region from the same org, or "
         "null.")
Exemplo n.º 5
0
 def test_post_extra_regions(self):
     """Submitted data should provide data for all regions in the org."""
     other_region = factories.Region()  # another org
     regions = self.make_regions()
     structure = self.get_structure(regions)
     structure[other_region.pk] = [None, None]
     self.assertErrorResponse(
         data={'data': json.dumps(structure)},
         message="Data must map region id to parent id for every region "
         "in this org.")
Exemplo n.º 6
0
 def test_not_in_user_regions(self):
     """Cannot set a region the user doesn't have access to."""
     another_region = factories.Region(org=self.org)
     response = self.set_region({'region': another_region.pk})
     self.assertEqual(response.status_code, 400)
     self.assertFalse(self.session_key in self.client.session)
Exemplo n.º 7
0
    def setUp(self):
        super(PollChartTest, self).setUp()

        self.org = factories.Org()

        self.poll = factories.Poll(org=self.org)

        self.region1 = factories.Region(org=self.org, name="Beta")
        self.region2 = factories.Region(org=self.org, name="Acme")

        self.question1 = factories.Question(
            poll=self.poll, question_type=models.Question.TYPE_MULTIPLE_CHOICE)
        self.question2 = factories.Question(
            poll=self.poll, question_type=models.Question.TYPE_OPEN)
        self.question3 = factories.Question(
            poll=self.poll, question_type=models.Question.TYPE_NUMERIC)

        self.pollrun = factories.UniversalPollRun(poll=self.poll)

        self.contact1 = factories.Contact(org=self.org, region=self.region1)
        self.response1 = factories.Response(
            contact=self.contact1, pollrun=self.pollrun,
            status=models.Response.STATUS_COMPLETE)
        factories.Answer(
            response=self.response1, question=self.question1,
            value="4.00000", category="1 - 5")
        factories.Answer(
            response=self.response1, question=self.question2,
            value="It's very rainy", category="All Responses")
        factories.Answer(
            response=self.response1, question=self.question3,
            value="4.00000", category="1 - 5")

        self.contact2 = factories.Contact(org=self.org, region=self.region1)
        self.response2 = factories.Response(
            contact=self.contact2, pollrun=self.pollrun,
            status=models.Response.STATUS_COMPLETE)
        factories.Answer(
            response=self.response2, question=self.question1,
            value="3.00000", category="1 - 5")
        factories.Answer(
            response=self.response2, question=self.question2,
            value="rainy and rainy", category="All Responses")
        factories.Answer(
            response=self.response2, question=self.question3,
            value="3.00000", category="1 - 5")

        self.contact3 = factories.Contact(org=self.org, region=self.region2)
        self.response3 = factories.Response(
            contact=self.contact3, pollrun=self.pollrun,
            status=models.Response.STATUS_COMPLETE)
        factories.Answer(
            response=self.response3, question=self.question1,
            value="8.00000", category="6 - 10")
        factories.Answer(
            response=self.response3, question=self.question2,
            value="Sunny sunny", category="All Responses")
        factories.Answer(
            response=self.response3, question=self.question3,
            value="8.00000", category="6 - 10")

        self.pollruns = models.PollRun.objects.filter(pk=self.pollrun.pk)
        self.responses = models.Response.objects.filter(pollrun=self.pollrun)
Exemplo n.º 8
0
 def _create_region(self, boundary):
     """Wrapper to create a region for the boundary."""
     return factories.Region(org=self.org, boundary=boundary)
Exemplo n.º 9
0
 def region(self):
     """Ensure that region and poll share the same org."""
     from tracpro.test import factories
     return factories.Region(org=self.poll.org)