Beispiel #1
0
 def test_by_org(self):
     """Test by_org filter."""
     boundary1 = factories.Boundary()
     boundary2 = factories.Boundary()
     self.assertEqual(list(models.Boundary.objects.by_org(boundary1.org)),
                      [boundary1])
     self.assertEqual(list(models.Boundary.objects.by_org(boundary2.org)),
                      [boundary2])
Beispiel #2
0
    def setUp(self):
        """Set up common resources."""
        super(BaseMapsTest, self).setUp()

        self.org = factories.Org()
        self.poll = factories.Poll()
        self.pollrun = factories.PollRun(poll=self.poll)

        self.boundary_a = factories.Boundary(org=self.org)
        self.boundary_b = factories.Boundary(org=self.org)
Beispiel #3
0
 def test_from_temba__existing__parent_in_other_org(self):
     """Parent shouldn't be set if parent UUID exists, but only for another org."""
     parent = factories.Boundary()  # another org
     self.temba.parent = parent.rapidpro_uuid
     result = models.Boundary.objects.from_temba(self.org, self.temba)
     self.assertEqual(result, self.boundary)
     self.assertIsNone(result.parent)
Beispiel #4
0
 def test_from_temba__existing__parent(self):
     """Parent should be set if we have an existing object for it."""
     parent = factories.Boundary(org=self.org)
     self.temba.parent = parent.rapidpro_uuid
     result = models.Boundary.objects.from_temba(self.org, self.temba)
     self.assertEqual(result, self.boundary)
     self.assertEqual(result.parent, parent)
Beispiel #5
0
 def test_post_other_org_boundary(self):
     """Submitted data should not reference boundaries from another org."""
     other_boundary = factories.Boundary()  # another org
     regions = self.make_regions()
     structure = self.get_structure(regions)
     structure[regions.first().pk] = [None, other_boundary.pk]
     self.assertErrorResponse(
         data={'data': json.dumps(structure)},
         message="Region boundary must be a boundary from the same org, "
         "or null.")
Beispiel #6
0
    def setUp(self):
        super(TestBoundaryManager, self).setUp()

        self.org = factories.Org()
        self.boundary = factories.Boundary(
            org=self.org,
            parent=None,
            level=models.Boundary.LEVEL_STATE,
        )
        self.temba = factories.TembaBoundary(
            boundary=self.boundary.rapidpro_uuid,
            name=self.boundary.name,
            parent=None,
            level=models.Boundary.LEVEL_STATE,
        )
Beispiel #7
0
    def make_regions(self):
        """Create a collection of nested regions."""
        self.region_uganda = factories.Region(
            org=self.org,
            name="Uganda",
            parent=None,
            boundary=factories.Boundary(org=self.org))
        self.region_kampala = factories.Region(
            org=self.org,
            name="Kampala",
            parent=self.region_uganda,
            boundary=factories.Boundary(org=self.org))
        self.region_makerere = factories.Region(
            org=self.org,
            name="Makerere",
            parent=self.region_kampala,
            boundary=factories.Boundary(org=self.org))
        self.region_entebbe = factories.Region(
            org=self.org,
            name="Entebbe",
            parent=self.region_uganda,
            boundary=factories.Boundary(org=self.org))

        self.region_kenya = factories.Region(
            org=self.org,
            name="Kenya",
            parent=None,
            boundary=factories.Boundary(org=self.org))
        self.region_nairobi = factories.Region(
            org=self.org,
            name="Nairobi",
            parent=self.region_kenya,
            boundary=factories.Boundary(org=self.org))
        self.region_mombasa = factories.Region(
            org=self.org,
            name="Mombasa",
            parent=self.region_kenya,
            boundary=factories.Boundary(org=self.org))

        self.region_no_boundary = factories.Region(org=self.org,
                                                   name="No Boundary",
                                                   parent=None,
                                                   boundary=None)

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

        return models.Region.get_all(self.org)
Beispiel #8
0
 def test_str(self):
     """Smoke test for string representation."""
     boundary = factories.Boundary(name="hello")
     self.assertEqual(str(boundary), "hello")