Пример #1
0
    def test_create(self):
        testers = Room.create(self.unicef, "Testers", 'G-007')
        jan = Contact.create(self.unicef, self.admin, "Jan", "janet", 'tel:1234', testers, 'C-007')
        bob = User.create(self.unicef, "Bob", "bobby", "*****@*****.**", "pass", False, [testers], [])
        ken = User.create(self.unicef, "Ken", "kenny", "*****@*****.**", "pass", False, [], [testers])

        self.assertEqual(testers.org, self.unicef)
        self.assertEqual(testers.name, "Testers")
        self.assertEqual(testers.uuid, 'G-007')
        self.assertEqual(list(testers.get_contacts()), [jan])
        self.assertEqual(list(testers.get_users().order_by('profile__full_name')), [bob, ken])
        self.assertEqual(list(testers.get_managers()), [ken])
Пример #2
0
    def _get_or_create_contact(org, room, contact_uuid):
        """
        Gets a contact by UUID, or creates it by fetching from Temba instance
        """
        contact = Contact.objects.filter(org=org, uuid=contact_uuid).first()
        if contact:
            if not contact.is_active or contact.room_id != room.pk:
                contact.is_active = True
                contact.room = room
                contact.save(update_fields=('is_active', 'room'))

            return contact
        else:
            temba_contact = org.get_temba_client().get_contact(contact_uuid)
            return Contact.objects.create(**Contact.kwargs_from_temba(org, temba_contact))
Пример #3
0
    def _get_or_create_contact(org, room, contact_uuid):
        """
        Gets a contact by UUID, or creates it by fetching from Temba instance
        """
        contact = Contact.objects.filter(org=org, uuid=contact_uuid).first()
        if contact:
            if not contact.is_active or contact.room_id != room.pk:
                contact.is_active = True
                contact.room = room
                contact.save(update_fields=('is_active', 'room'))

            return contact
        else:
            temba_contact = org.get_temba_client().get_contact(contact_uuid)
            return Contact.objects.create(
                **Contact.kwargs_from_temba(org, temba_contact))
Пример #4
0
    def test_create(self):
        testers = Room.create(self.unicef, "Testers", 'G-007')
        jan = Contact.create(self.unicef, self.admin, "Jan", "janet",
                             'tel:1234', testers, 'C-007')
        bob = User.create(self.unicef, "Bob", "bobby", "*****@*****.**",
                          "pass", False, [testers], [])
        ken = User.create(self.unicef, "Ken", "kenny", "*****@*****.**",
                          "pass", False, [], [testers])

        self.assertEqual(testers.org, self.unicef)
        self.assertEqual(testers.name, "Testers")
        self.assertEqual(testers.uuid, 'G-007')
        self.assertEqual(list(testers.get_contacts()), [jan])
        self.assertEqual(
            list(testers.get_users().order_by('profile__full_name')),
            [bob, ken])
        self.assertEqual(list(testers.get_managers()), [ken])
Пример #5
0
 def create_contact(self, org, full_name, chat_name, urn, room, uuid):
     user = org.administrators.first()
     return Contact.create(org, user, full_name, chat_name, urn, room, uuid)
Пример #6
0
 def create_contact(self, org, full_name, chat_name, urn, room, uuid):
     user = org.administrators.first()
     return Contact.create(org, user, full_name, chat_name, urn, room, uuid)