forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into topic_filtering_pt1
- Loading branch information
Showing
28 changed files
with
402 additions
and
606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "temba" | ||
version = "9.3.79" | ||
version = "9.3.81" | ||
description = "Hosted service for visually building interactive messaging applications" | ||
authors = ["Nyaruka <[email protected]>"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,65 @@ | ||
from temba.contacts.models import ContactField | ||
from temba.tests import TembaTest | ||
|
||
from .contacts import format_urn, name_or_urn, urn_icon, urn_or_anon | ||
from . import contacts as tags | ||
|
||
|
||
class ContactsTest(TembaTest): | ||
def test_contact_field(self): | ||
gender = self.create_field("gender", "Gender", ContactField.TYPE_TEXT) | ||
age = self.create_field("age", "Age", ContactField.TYPE_NUMBER) | ||
joined = self.create_field("joined", "Joined", ContactField.TYPE_DATETIME) | ||
last_seen_on = self.org.fields.get(key="last_seen_on") | ||
contact = self.create_contact("Bob", fields={"age": 30, "gender": "M", "joined": "2024-01-01T00:00:00Z"}) | ||
|
||
self.assertEqual("M", tags.contact_field(contact, gender)) | ||
self.assertEqual("30", tags.contact_field(contact, age)) | ||
self.assertEqual( | ||
"<temba-date value='2024-01-01T02:00:00+02:00' display='date'></temba-date>", | ||
tags.contact_field(contact, joined), | ||
) | ||
self.assertEqual("--", tags.contact_field(contact, last_seen_on)) | ||
|
||
def test_name_or_urn(self): | ||
contact1 = self.create_contact("", urns=[]) | ||
contact2 = self.create_contact("Ann", urns=[]) | ||
contact3 = self.create_contact("Bob", urns=["tel:+12024561111", "telegram:098761111"]) | ||
contact4 = self.create_contact("", urns=["tel:+12024562222", "telegram:098762222"]) | ||
|
||
self.assertEqual("", name_or_urn(contact1, self.org)) | ||
self.assertEqual("Ann", name_or_urn(contact2, self.org)) | ||
self.assertEqual("Bob", name_or_urn(contact3, self.org)) | ||
self.assertEqual("(202) 456-2222", name_or_urn(contact4, self.org)) | ||
self.assertEqual("", tags.name_or_urn(contact1, self.org)) | ||
self.assertEqual("Ann", tags.name_or_urn(contact2, self.org)) | ||
self.assertEqual("Bob", tags.name_or_urn(contact3, self.org)) | ||
self.assertEqual("(202) 456-2222", tags.name_or_urn(contact4, self.org)) | ||
|
||
with self.anonymous(self.org): | ||
self.assertEqual(f"{contact1.id:010}", name_or_urn(contact1, self.org)) | ||
self.assertEqual("Ann", name_or_urn(contact2, self.org)) | ||
self.assertEqual("Bob", name_or_urn(contact3, self.org)) | ||
self.assertEqual(f"{contact4.id:010}", name_or_urn(contact4, self.org)) | ||
self.assertEqual(f"{contact1.id:010}", tags.name_or_urn(contact1, self.org)) | ||
self.assertEqual("Ann", tags.name_or_urn(contact2, self.org)) | ||
self.assertEqual("Bob", tags.name_or_urn(contact3, self.org)) | ||
self.assertEqual(f"{contact4.id:010}", tags.name_or_urn(contact4, self.org)) | ||
|
||
def test_urn_or_anon(self): | ||
contact1 = self.create_contact("Bob", urns=[]) | ||
contact2 = self.create_contact("Uri", urns=["tel:+12024561414", "telegram:098765432"]) | ||
|
||
self.assertEqual("--", urn_or_anon(contact1, self.org)) | ||
self.assertEqual("+1 202-456-1414", urn_or_anon(contact2, self.org)) | ||
self.assertEqual("--", tags.urn_or_anon(contact1, self.org)) | ||
self.assertEqual("+1 202-456-1414", tags.urn_or_anon(contact2, self.org)) | ||
|
||
with self.anonymous(self.org): | ||
self.assertEqual(f"{contact1.id:010}", urn_or_anon(contact1, self.org)) | ||
self.assertEqual(f"{contact2.id:010}", urn_or_anon(contact2, self.org)) | ||
self.assertEqual(f"{contact1.id:010}", tags.urn_or_anon(contact1, self.org)) | ||
self.assertEqual(f"{contact2.id:010}", tags.urn_or_anon(contact2, self.org)) | ||
|
||
def test_urn_icon(self): | ||
contact = self.create_contact("Uri", urns=["tel:+1234567890", "telegram:098765432", "viber:346376373"]) | ||
tel_urn, tg_urn, viber_urn = contact.urns.order_by("-priority") | ||
|
||
self.assertEqual("icon-phone", urn_icon(tel_urn)) | ||
self.assertEqual("icon-telegram", urn_icon(tg_urn)) | ||
self.assertEqual("", urn_icon(viber_urn)) | ||
self.assertEqual("icon-phone", tags.urn_icon(tel_urn)) | ||
self.assertEqual("icon-telegram", tags.urn_icon(tg_urn)) | ||
self.assertEqual("", tags.urn_icon(viber_urn)) | ||
|
||
def test_format_urn(self): | ||
contact = self.create_contact("Uri", urns=["tel:+12024561414"]) | ||
|
||
self.assertEqual("+1 202-456-1414", format_urn(contact.get_urn(), self.org)) | ||
self.assertEqual("+1 202-456-1414", tags.format_urn(contact.get_urn(), self.org)) | ||
|
||
with self.anonymous(self.org): | ||
self.assertEqual("••••••••", format_urn(contact.get_urn(), self.org)) | ||
self.assertEqual("••••••••", tags.format_urn(contact.get_urn(), self.org)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.