Пример #1
0
    def pull_labels(self, org):
        client = self._get_client(org)
        incoming_objects = client.get_labels().all(retry_on_rate_exceed=True)

        return self._counts(
            sync_local_to_set(org, LabelSyncer(backend=self.backend),
                              incoming_objects))
Пример #2
0
    def pull_boundaries(self, org):

        if org.get_config('is_global'):
            incoming_objects = Boundary.build_global_boundaries()
        else:
            client = self._get_client(org, 1)
            incoming_objects = client.get_boundaries()

        return sync_local_to_set(org, BoundarySyncer(), incoming_objects)
Пример #3
0
    def pull_boundaries(self, org):

        if org.get_config('is_global'):
            incoming_objects = Boundary.build_global_boundaries()
        else:
            client = self._get_client(org, 1)
            incoming_objects = client.get_boundaries()

        return sync_local_to_set(org, BoundarySyncer(), incoming_objects)
Пример #4
0
    def pull_boundaries(self, org):

        if org.get_config("common.is_global"):
            incoming_objects = Boundary.build_global_boundaries()
        else:
            client = self._get_client(org, 2)
            incoming_objects = client.get_boundaries(geometry=True).all()

        return sync_local_to_set(org, BoundarySyncer(backend=self.backend), incoming_objects)
Пример #5
0
    def pull_boundaries(self, org):

        if org.get_config('common.is_global'):
            incoming_objects = Boundary.build_global_boundaries()
        else:
            client = self._get_client(org, 2)
            incoming_objects = client.get_boundaries(geometry=True).all()

        return sync_local_to_set(org, BoundarySyncer(backend=self.backend), incoming_objects)
Пример #6
0
    def test_sync_local_to_set(self):
        Contact.objects.all().delete()  # start with no contacts...

        remote_set = [
            TembaContact.create(uuid="C-001", name="Anne", blocked=False),
            TembaContact.create(uuid="C-002", name="Bob", blocked=False),
            TembaContact.create(uuid="C-003", name="Colin", blocked=False),
            TembaContact.create(uuid="C-004", name="Donald", blocked=True)
        ]

        self.assertEqual(sync_local_to_set(self.unicef, self.syncer, remote_set), (3, 0, 0, 1))
        self.assertEqual(Contact.objects.count(), 3)

        remote_set = [
            # first contact removed
            TembaContact.create(uuid="C-002", name="Bob", blocked=False),    # no change
            TembaContact.create(uuid="C-003", name="Colm", blocked=False),   # changed name
            TembaContact.create(uuid="C-005", name="Edward", blocked=False)  # new contact
        ]

        self.assertEqual(sync_local_to_set(self.unicef, self.syncer, remote_set), (1, 1, 1, 1))

        self.assertEqual(Contact.objects.count(), 4)
        Contact.objects.get(org=self.unicef, uuid="C-001", name="Anne", is_active=False)
        Contact.objects.get(org=self.unicef, uuid="C-002", name="Bob", is_active=True)
        Contact.objects.get(org=self.unicef, uuid="C-003", name="Colm", is_active=True)
        Contact.objects.get(org=self.unicef, uuid="C-005", name="Edward", is_active=True)

        remote_set = [
            # first contact removed
            TembaContact.create(uuid="CF-002", name="Bob", blocked=False),    # no change
            TembaContact.create(uuid="CF-003", name="Colm", blocked=False),   # changed name
            TembaContact.create(uuid="CF-005", name="Edward", blocked=False)  # new contact
        ]
        self.assertEqual(sync_local_to_set(self.unicef, self.syncer2, remote_set), (3, 0, 0, 0))
        self.assertEqual(Contact.objects.count(), 7)
        Contact.objects.get(org=self.unicef, uuid="CF-002", name="Bob", backend=self.floip_backend, is_active=True)
        Contact.objects.get(org=self.unicef, uuid="CF-003", name="Colm", backend=self.floip_backend, is_active=True)
        Contact.objects.get(org=self.unicef, uuid="CF-005", name="Edward", backend=self.floip_backend, is_active=True)
Пример #7
0
    def pull_groups(self, org):
        client = self._get_client(org)
        incoming_objects = client.get_groups().all(retry_on_rate_exceed=True)

        return sync_local_to_set(org, GroupSyncer(), incoming_objects)
Пример #8
0
    def pull_fields(self, org):
        client = self._get_client(org)
        incoming_objects = client.get_fields().all(retry_on_rate_exceed=True)

        return sync_local_to_set(org, FieldSyncer(backend=self.backend), incoming_objects)
Пример #9
0
    def pull_fields(self, org):
        client = self._get_client(org, 2)
        incoming_objects = client.get_fields().all(retry_on_rate_exceed=True)

        return sync_local_to_set(org, FieldSyncer(), incoming_objects)