forked from rapidpro/casepro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rapidpro#148 from praekelt/feature/upstream-merge
Update staging with upstream changes
- Loading branch information
Showing
22 changed files
with
141 additions
and
68 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
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 |
---|---|---|
|
@@ -118,16 +118,21 @@ def test_save(self): | |
|
||
self.assertEqual(set(contact.groups.all()), {spammers, boffins}) | ||
|
||
def test_get_display_name(self): | ||
self.assertEqual(self.ann.get_display_name(), "Ann") | ||
|
||
# if site uses anon contacts then obscure this | ||
with override_settings(SITE_ANON_CONTACTS=True): | ||
self.assertEqual(self.ann.get_display_name(), "7B7DD8") | ||
|
||
# likewise if name if empty | ||
self.ann.name = "" | ||
self.assertEqual(self.ann.get_display_name(), "7B7DD8") | ||
def test_get_display(self): | ||
# if the site uses 'uuid' for the display | ||
with override_settings(SITE_CONTACT_DISPLAY="uuid"): | ||
self.assertEqual(self.ann.get_display(), "7B7DD8") | ||
|
||
# if the site uses 'urns' for the display | ||
self.ann.urns = ['tel:+2345'] | ||
with override_settings(SITE_CONTACT_DISPLAY="urns"): | ||
self.assertEqual(self.ann.get_display(), "+2345") | ||
self.ann.refresh_from_db() | ||
|
||
# if the site uses 'name' or something unrecognised for the display | ||
self.assertEqual(self.ann.get_display(), "Ann") | ||
self.ann.name = None | ||
self.assertEqual(self.ann.get_display(), "---") | ||
|
||
def test_get_fields(self): | ||
self.assertEqual(self.ann.get_fields(), {'age': "32", 'state': "WA"}) # what is stored on the contact | ||
|
@@ -144,12 +149,14 @@ def test_release(self): | |
self.assertEqual(self.ann.incoming_messages.filter(is_active=False, is_handled=True).count(), 2) | ||
|
||
def test_as_json(self): | ||
self.assertEqual(self.ann.as_json(full=False), {'id': self.ann.pk, 'name': "Ann"}) | ||
self.assertEqual(self.ann.as_json(full=False), {'id': self.ann.pk, 'display': "Ann"}) | ||
|
||
# full=True means include visible contact fields and laanguage etc | ||
self.assertEqual(self.ann.as_json(full=True), { | ||
'id': self.ann.pk, | ||
'display': "Ann", | ||
'name': "Ann", | ||
'urns': [], | ||
'language': {'code': 'eng', 'name': "English"}, | ||
'groups': [{'id': self.reporters.pk, 'name': "Reporters"}], | ||
'fields': {'nickname': None, 'age': "32"}, | ||
|
@@ -158,21 +165,35 @@ def test_as_json(self): | |
}) | ||
|
||
self.ann.language = None | ||
self.ann.urns = ["tel:+2345678", "mailto:[email protected]"] | ||
self.ann.save() | ||
|
||
self.assertEqual(self.ann.as_json(full=True), { | ||
'id': self.ann.pk, | ||
'display': "Ann", | ||
'name': "Ann", | ||
'urns': ["tel:+2345678", "mailto:[email protected]"], | ||
'language': None, | ||
'groups': [{'id': self.reporters.pk, 'name': "Reporters"}], | ||
'fields': {'nickname': None, 'age': "32"}, | ||
'blocked': False, | ||
'stopped': False | ||
}) | ||
|
||
# if site uses anon contacts then name is obscured | ||
with override_settings(SITE_ANON_CONTACTS=True): | ||
self.assertEqual(self.ann.as_json(full=False), {'id': self.ann.pk, 'name': "7B7DD8"}) | ||
# If the urns and name fields are hidden they should not be returned | ||
# SITE_CONTACT_DISPLAY overrules this for the 'display' attr | ||
with override_settings(SITE_HIDE_CONTACT_FIELDS=["urns", "name"], SITE_CONTACT_DISPLAY="uuid"): | ||
self.assertEqual(self.ann.as_json(full=True), { | ||
'id': self.ann.pk, | ||
'display': "7B7DD8", | ||
'urns': [], | ||
'name': None, | ||
'language': None, | ||
'groups': [{'id': self.reporters.pk, 'name': "Reporters"}], | ||
'fields': {'nickname': None, 'age': "32"}, | ||
'blocked': False, | ||
'stopped': False | ||
}) | ||
|
||
@patch('casepro.test.TestBackend.push_contact') | ||
def test_get_or_create_from_urn(self, mock_push_contact): | ||
|
@@ -260,7 +281,9 @@ def test_fetch(self): | |
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json, { | ||
'id': self.ann.pk, | ||
'display': "Ann", | ||
'name': "Ann", | ||
'urns': [], | ||
'language': {'code': 'eng', 'name': "English"}, | ||
'fields': {'age': '32', 'nickname': None}, | ||
'groups': [{'id': self.reporters.pk, 'name': "Reporters"}], | ||
|
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,6 +1,7 @@ | ||
from __future__ import unicode_literals | ||
|
||
import json | ||
import pytz | ||
|
||
from dash.test import DashTest | ||
from datetime import datetime, date, time | ||
|
@@ -37,8 +38,8 @@ def setUp(self): | |
settings.SITE_ORGS_STORAGE_ROOT = 'test_orgs' | ||
|
||
# some orgs | ||
self.unicef = self.create_org("UNICEF", timezone="Africa/Kampala", subdomain="unicef") | ||
self.nyaruka = self.create_org("Nyaruka", timezone="Africa/Kigali", subdomain="nyaruka") | ||
self.unicef = self.create_org("UNICEF", timezone=pytz.timezone("Africa/Kampala"), subdomain="unicef") | ||
self.nyaruka = self.create_org("Nyaruka", timezone=pytz.timezone("Africa/Kigali"), subdomain="nyaruka") | ||
|
||
# some admins for those orgs | ||
self.admin = self.create_admin(self.unicef, "Kidus", "[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
Oops, something went wrong.