-
-
Notifications
You must be signed in to change notification settings - Fork 219
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 #33807 from dimagi/mjr/add-change-meta-context
- Loading branch information
Showing
13 changed files
with
200 additions
and
29 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
82 changes: 82 additions & 0 deletions
82
corehq/ex-submodules/casexml/apps/case/tests/test_xform.py
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from django.test import SimpleTestCase | ||
from casexml.apps.case.xml import V2 | ||
from casexml.apps.case.xform import get_case_updates | ||
from casexml.apps.case.xml.parser import CaseUpdate | ||
|
||
|
||
class TestGetCaseUpdates(SimpleTestCase): | ||
default_case_id = '1111' | ||
default_user_id = '2222' | ||
default_modified_time = '2023-11-28T15:26:55.859000Z' | ||
|
||
def test_processes_single_case(self): | ||
case_block = self._create_case_block( | ||
case_id='case1', | ||
user_id='abc', | ||
modified_on='2023-11-28T15:26:55.859000Z', | ||
create_block={'case_name': 'test', 'case_type': 'test_type'} | ||
) | ||
xform = { | ||
'case': case_block | ||
} | ||
|
||
updates = get_case_updates(xform) | ||
expected_case = self._create_case_update( | ||
case_id='case1', | ||
user_id='abc', | ||
modified_on='2023-11-28T15:26:55.859000Z', | ||
create_block={'case_name': 'test', 'case_type': 'test_type'} | ||
) | ||
self.assertEqual(expected_case, updates[0]) | ||
|
||
def test_processes_sub_case(self): | ||
case1 = self._create_case_block(case_id='1') | ||
case2 = self._create_case_block(case_id='2') | ||
xform = { | ||
'case': case1, | ||
'sub_case': { | ||
'case': case2 | ||
} | ||
} | ||
|
||
updates = get_case_updates(xform) | ||
self.assertEqual(updates, [self._create_case_update(case_id='1'), self._create_case_update(case_id='2')]) | ||
|
||
def test_can_restrict_by_id(self): | ||
case1 = self._create_case_block(case_id='1') | ||
case2 = self._create_case_block(case_id='2') | ||
xform = { | ||
'case': case1, | ||
'sub_case': { | ||
'case': case2 | ||
} | ||
} | ||
|
||
updates = get_case_updates(xform, for_case='1') | ||
self.assertEqual(updates, [self._create_case_update(case_id='1')]) | ||
|
||
def _create_case_block( | ||
self, case_id=None, user_id=None, modified_on=None, create_block=None, update_block=None): | ||
block = { | ||
'@case_id': case_id or self.default_case_id, | ||
'@date_modified': modified_on or self.default_modified_time, | ||
'@user_id': user_id or self.default_user_id, | ||
'@xmlns': 'http://commcarehq.org/case/transaction/v2', | ||
} | ||
|
||
if create_block: | ||
block['create'] = create_block | ||
|
||
if update_block: | ||
block['update'] = update_block | ||
|
||
return block | ||
|
||
def _create_case_update( | ||
self, case_id=None, user_id=None, modified_on=None, create_block=None, update_block=None): | ||
block = self._create_case_block(case_id, user_id, modified_on, create_block, update_block) | ||
|
||
return CaseUpdate( | ||
case_id or self.default_case_id, V2, block, | ||
user_id=(user_id or self.default_user_id), | ||
modified_on_str=modified_on or self.default_modified_time) |
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
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.