def setUpClass(cls): cls.domain = 'skbanskdjoasdkng' cls.cases = [ CommCareCase(name='A', domain=cls.domain), CommCareCase(name='B', domain=cls.domain), CommCareCase(name='C', domain=cls.domain), CommCareCase(name='D', domain=cls.domain), CommCareCase(name='X', domain='bunny'), ] CommCareCase.get_db().bulk_save(cls.cases) cls.case_groups = [ CommCareCaseGroup(name='alpha', domain=cls.domain, cases=[cls.cases[0]._id, cls.cases[1]._id]), CommCareCaseGroup(name='beta', domain=cls.domain, cases=[cls.cases[2]._id, cls.cases[3]._id]), CommCareCaseGroup(name='gamma', domain=cls.domain, cases=[cls.cases[0]._id, cls.cases[3]._id]), CommCareCaseGroup(name='delta', domain=cls.domain, cases=[cls.cases[1]._id, cls.cases[2]._id]), ] CommCareCaseGroup.get_db().bulk_save(cls.case_groups)
def setUpClass(cls): super(DBAccessorsTest, cls).setUpClass() cls.domain = 'case-group-test' cls.case_groups = [ CommCareCaseGroup(name='A', domain=cls.domain, cases=['A', 'B']), CommCareCaseGroup(name='b', domain=cls.domain, cases=['B', 'C']), CommCareCaseGroup(name='C', domain=cls.domain, cases=['A', 'D']), CommCareCaseGroup(name='D', domain=cls.domain, cases=['B', 'C']), CommCareCaseGroup(name='E', domain=cls.domain + 'x', cases=['B', 'C']), ] for group in cls.case_groups: # Clear cache and save group.save()
def create_group(self, domain): group = CommCareCaseGroup( name=self.cleaned_data['name'], domain=domain ) group.save() return group
def test_case_group_recipient_with_user_data_filter(self): # The user data filter should have no effect here because all # the recipients are cases. schedule = TimedSchedule.create_simple_daily_schedule( self.domain, TimedEvent(time=time(9, 0)), SMSContent(message={'en': 'Hello'}) ) schedule.user_data_filter = {'role': ['nurse']} schedule.save() with create_case(self.domain, 'person') as case: case_group = CommCareCaseGroup(domain=self.domain, cases=[case.case_id]) case_group.save() self.addCleanup(case_group.delete) instance = CaseTimedScheduleInstance( domain=self.domain, timed_schedule_id=schedule.schedule_id, recipient_type=ScheduleInstance.RECIPIENT_TYPE_CASE_GROUP, recipient_id=case_group.get_id, ) recipients = list(instance.expand_recipients()) self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0].case_id, case.case_id)
def test_case_group(self): group = CommCareCaseGroup(name='A', domain=self.domain, cases=['A', 'B']) group.save() self.addCleanup(group.delete) self._test_doc(group.get_id, "CommCareCaseGroup")
def setUpClass(cls): super(SchedulingRecipientTest, cls).setUpClass() cls.domain_obj = create_domain(cls.domain) cls.location_types = setup_location_types(cls.domain, ['country', 'state', 'city']) cls.country_location = make_loc('usa', domain=cls.domain, type='country') cls.state_location = make_loc('ma', domain=cls.domain, type='state', parent=cls.country_location) cls.city_location = make_loc('boston', domain=cls.domain, type='city', parent=cls.state_location) cls.mobile_user = CommCareUser.create(cls.domain, 'mobile', 'abc') cls.mobile_user.set_location(cls.city_location) cls.mobile_user2 = CommCareUser.create(cls.domain, 'mobile2', 'abc') cls.mobile_user2.set_location(cls.state_location) cls.web_user = WebUser.create(cls.domain, 'web', 'abc') cls.group = Group(domain=cls.domain, users=[cls.mobile_user.get_id]) cls.group.save() cls.case_group = CommCareCaseGroup(domain=cls.domain) cls.case_group.save()
def test_get_docs_in_domain_by_class(self): group = Group(domain=self.domain) case_group = CommCareCaseGroup(name='a group', domain=self.domain) group.save() case_group.save() self.addCleanup(group.delete) self.addCleanup(case_group.delete) [group2] = get_docs_in_domain_by_class(self.domain, Group) self.assertEqual(group2.to_json(), group.to_json()) [case_group2] = get_docs_in_domain_by_class(self.domain, CommCareCaseGroup) self.assertEqual(case_group.to_json(), case_group2.to_json())
def setUpClass(cls): super(SchedulingRecipientTest, cls).setUpClass() cls.domain_obj = create_domain(cls.domain) cls.location_types = setup_location_types(cls.domain, ['country', 'state', 'city']) cls.country_location = make_loc('usa', domain=cls.domain, type='country') cls.state_location = make_loc('ma', domain=cls.domain, type='state', parent=cls.country_location) cls.city_location = make_loc('boston', domain=cls.domain, type='city', parent=cls.state_location) cls.mobile_user = CommCareUser.create(cls.domain, 'mobile', 'abc') cls.mobile_user.set_location(cls.city_location) cls.mobile_user2 = CommCareUser.create(cls.domain, 'mobile2', 'abc') cls.mobile_user2.set_location(cls.state_location) cls.mobile_user3 = CommCareUser.create(cls.domain, 'mobile3', 'abc') cls.mobile_user3.user_data['role'] = 'pharmacist' cls.mobile_user3.save() cls.mobile_user4 = CommCareUser.create(cls.domain, 'mobile4', 'abc') cls.mobile_user4.user_data['role'] = 'nurse' cls.mobile_user4.save() cls.mobile_user5 = CommCareUser.create(cls.domain, 'mobile5', 'abc') cls.mobile_user5.user_data['role'] = ['nurse', 'pharmacist'] cls.mobile_user5.save() cls.web_user = WebUser.create(cls.domain, 'web', 'abc') cls.web_user2 = WebUser.create(cls.domain, 'web2', 'abc') cls.web_user2.user_data['role'] = 'nurse' cls.web_user2.save() cls.group = Group(domain=cls.domain, users=[cls.mobile_user.get_id]) cls.group.save() cls.group2 = Group( domain=cls.domain, users=[ cls.mobile_user.get_id, cls.mobile_user3.get_id, cls.mobile_user4.get_id, cls.mobile_user5.get_id, ] ) cls.group2.save() cls.case_group = CommCareCaseGroup(domain=cls.domain) cls.case_group.save() cls.process_pillow_changes = process_pillow_changes('DefaultChangeFeedPillow') cls.process_pillow_changes.add_pillow(get_case_messaging_sync_pillow())
def setUpClass(cls): super(SchedulingRecipientTest, cls).setUpClass() cls.domain_obj = create_domain(cls.domain) cls.location_types = setup_location_types(cls.domain, ['country', 'state', 'city']) cls.country_location = make_loc('usa', domain=cls.domain, type='country') cls.state_location = make_loc('ma', domain=cls.domain, type='state', parent=cls.country_location) cls.city_location = make_loc('boston', domain=cls.domain, type='city', parent=cls.state_location) cls.mobile_user = CommCareUser.create(cls.domain, 'mobile', 'abc', None, None) cls.mobile_user.set_location(cls.city_location) cls.mobile_user2 = CommCareUser.create(cls.domain, 'mobile2', 'abc', None, None) cls.mobile_user2.set_location(cls.state_location) cls.mobile_user3 = CommCareUser.create(cls.domain, 'mobile3', 'abc', None, None, metadata={ 'role': 'pharmacist', }) cls.mobile_user3.save() cls.mobile_user4 = CommCareUser.create(cls.domain, 'mobile4', 'abc', None, None, metadata={ 'role': 'nurse', }) cls.mobile_user4.save() cls.mobile_user5 = CommCareUser.create(cls.domain, 'mobile5', 'abc', None, None, metadata={ 'role': ['nurse', 'pharmacist'], }) cls.mobile_user5.save() full_username = normalize_username('mobile', cls.domain) cls.full_mobile_user = CommCareUser.create(cls.domain, full_username, 'abc', None, None) cls.definition = CustomDataFieldsDefinition( domain=cls.domain, field_type=UserFieldsView.field_type) cls.definition.save() cls.definition.set_fields([ Field( slug='role', label='Role', ), ]) cls.definition.save() cls.profile = CustomDataFieldsProfile( name='nurse_profile', fields={'role': ['nurse']}, definition=cls.definition, ) cls.profile.save() cls.mobile_user6 = CommCareUser.create(cls.domain, 'mobile6', 'abc', None, None, metadata={ PROFILE_SLUG: cls.profile.id, }) cls.mobile_user5.save() cls.web_user = WebUser.create(cls.domain, 'web', 'abc', None, None) cls.web_user2 = WebUser.create(cls.domain, 'web2', 'abc', None, None, metadata={ 'role': 'nurse', }) cls.web_user2.save() cls.group = Group(domain=cls.domain, users=[cls.mobile_user.get_id]) cls.group.save() cls.group2 = Group(domain=cls.domain, users=[ cls.mobile_user.get_id, cls.mobile_user3.get_id, cls.mobile_user4.get_id, cls.mobile_user5.get_id, cls.mobile_user6.get_id, ]) cls.group2.save() cls.case_group = CommCareCaseGroup(domain=cls.domain) cls.case_group.save() cls.process_pillow_changes = process_pillow_changes( 'DefaultChangeFeedPillow') cls.process_pillow_changes.add_pillow(get_case_messaging_sync_pillow())