Skip to content

Commit

Permalink
Fixed contact syncer so that stub contacts are always updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Feb 29, 2016
1 parent 0c83999 commit 074326a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions casepro/backend/rapidpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def local_kwargs(self, org, remote):
}

def update_required(self, local, remote):
if local.is_stub:
return True

if local.name != remote.name:
return True

Expand Down
26 changes: 23 additions & 3 deletions casepro/backend/tests/test_rapidpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,25 @@ def test_local_kwargs(self):
})

def test_update_required(self):
local = self.create_contact(self.unicef, 'C-001', "Ann", [self.reporters], {'chat_name': "ann"})
# create stub contact
local = Contact.get_or_create(self.unicef, 'C-001', "Ann")

# a stub contact should always be updated
self.assertTrue(self.syncer.update_required(local, TembaContact.create(
uuid='000-001',
name="Ann",
urns=['tel:1234'],
groups=[],
fields={},
language=None,
modified_on=now()
)))

local.groups.add(self.reporters)
local.language = "eng"
local.is_stub = False
local.fields = {'chat_name': "ann"}
local.save()

# no differences (besides null field value which is ignored)
self.assertFalse(self.syncer.update_required(local, TembaContact.create(
Expand All @@ -52,7 +70,8 @@ def test_update_required(self):
urns=['tel:1234'],
groups=[ObjectRef.create(uuid='G-003', name="Reporters")],
fields={'chat_name': "ann", 'age': None},
language='eng', modified_on=now()
language='eng',
modified_on=now()
)))

# name change
Expand All @@ -62,7 +81,8 @@ def test_update_required(self):
urns=['tel:1234'],
groups=[ObjectRef.create(uuid='G-003', name="Reporters")],
fields={'chat_name': "ann"},
language='eng', modified_on=now()
language='eng',
modified_on=now()
)))

# group change
Expand Down

0 comments on commit 074326a

Please sign in to comment.