def test_all_case_forms_deleted(self): from corehq.apps.callcenter.sync_user_case import sync_usercase sync_usercase(self.commcare_user) user_case_id = self.commcare_user.get_usercase_id() # other user submits form against the case (should get deleted) caseblock = CaseBlock.deprecated_init( create=False, case_id=user_case_id, ) submit_case_blocks(caseblock.as_text(), self.domain, user_id=self.other_user._id) case_ids = CaseAccessors(self.domain).get_case_ids_by_owners( [self.commcare_user._id]) self.assertEqual(1, len(case_ids)) form_ids = FormAccessors(self.domain).get_form_ids_for_user( self.commcare_user._id) self.assertEqual(0, len(form_ids)) user_case = self.commcare_user.get_usercase() self.assertEqual(2, len(user_case.xform_ids)) self.commcare_user.retire(deleted_by=None) for form_id in user_case.xform_ids: self.assertTrue( FormAccessors(self.domain).get_form(form_id).is_deleted) self.assertTrue( CaseAccessors(self.domain).get_case(user_case_id).is_deleted)
def test_all_case_forms_deleted(self): from corehq.apps.callcenter.sync_user_case import sync_usercase sync_usercase(self.commcare_user) user_case_id = self.commcare_user.get_usercase_id() # other user submits form against the case (should get deleted) caseblock = CaseBlock( create=False, case_id=user_case_id, ) submit_case_blocks(caseblock.as_string().decode('utf-8'), self.domain, user_id=self.other_user._id) case_ids = CaseAccessors(self.domain).get_case_ids_by_owners([self.commcare_user._id]) self.assertEqual(1, len(case_ids)) form_ids = FormAccessors(self.domain).get_form_ids_for_user(self.commcare_user._id) self.assertEqual(0, len(form_ids)) user_case = self.commcare_user.get_usercase() self.assertEqual(2, len(user_case.xform_ids)) self.commcare_user.retire() for form_id in user_case.xform_ids: self.assertTrue(FormAccessors(self.domain).get_form(form_id).is_deleted) self.assertTrue(CaseAccessors(self.domain).get_case(user_case_id).is_deleted)
def test_sync_usercase_custom_user_data_on_update(self): """ Custom user data should be synced when the user is updated """ self.user.user_data = { 'completed_training': 'no', } self.user.save() self.user.user_data = { 'completed_training': 'yes', } sync_usercase(self.user) case = CaseAccessors(TEST_DOMAIN).get_case_by_domain_hq_user_id(self.user._id, USERCASE_TYPE) self.assertEqual(case.dynamic_case_properties()['completed_training'], 'yes') self._check_update_matches(case, {'completed_training': 'yes'})
def test_sync_usercase_custom_user_data_on_update(self): """ Custom user data should be synced when the user is updated """ self.user.user_data = { 'completed_training': 'no', } self.user.save() self.user.user_data = { 'completed_training': 'yes', } sync_usercase(self.user) case = CaseAccessors(TEST_DOMAIN).get_case_by_domain_hq_user_id(self.user._id, USERCASE_TYPE) self.assertEqual(case.dynamic_case_properties()['completed_training'], 'yes') self._check_update_matches(case, {'completed_training': 'yes'})
def sync_user_cases_task(user_id): user = CommCareUser.get_by_user_id(user_id) sync_call_center_user_case(user) sync_usercase(user)
def sync_user_cases_task(user_id): user = CommCareUser.get_by_user_id(user_id) sync_call_center_user_case(user) sync_usercase(user)
def create_user_cases(domain_name): from corehq.apps.callcenter.sync_user_case import sync_usercase for user in CommCareUser.by_domain(domain_name): sync_usercase(user)