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 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.º 3
0
    def test_sync_create_new(self):
        """Create a new group if the UUID hasn't been seen before."""
        self.temba_groups['6'] = TembaGroup.create(uuid='6', name="New")
        self.mock_temba_client.get_groups.return_value = self.temba_groups.values()
        uuids = ['1', '2', '3', '4', '6']
        models.Region.sync_with_temba(self.org, uuids)
        self.refresh_regions()

        new_region = models.Region.objects.get(uuid='6')
        self.assertEqual(set(models.Region.get_all(self.org)), set([
            self.uganda,
            self.kampala,
            self.makerere,
            self.entebbe,
            new_region,
        ]))
        self.assertEqual(new_region.name, "New")
        self.assertIsNone(new_region.parent, None)
        self.assertEqual(self.mock_temba_client.get_groups.call_count, 1)
        self.assertEqual(self.mock_temba_client.get_contacts.call_count, 2)
Exemplo n.º 4
0
    def test_sync_create_new(self):
        """Create a new group if the UUID hasn't been seen before."""
        self.temba_groups['6'] = TembaGroup.create(uuid='6', name="New")
        self.mock_temba_client.get_groups.return_value = self.temba_groups.values(
        )
        uuids = ['1', '2', '3', '4', '6']
        models.Region.sync_with_temba(self.org, uuids)
        self.refresh_regions()

        new_region = models.Region.objects.get(uuid='6')
        self.assertEqual(
            set(models.Region.get_all(self.org)),
            set([
                self.uganda,
                self.kampala,
                self.makerere,
                self.entebbe,
                new_region,
            ]))
        self.assertEqual(new_region.name, "New")
        self.assertIsNone(new_region.parent, None)
        self.assertEqual(self.mock_temba_client.get_groups.call_count, 1)
        self.assertEqual(self.mock_temba_client.get_contacts.call_count, 2)