Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    def setUpClass(cls):
        # Create domain
        cls.domain = create_domain(TEST_DOMAIN)
        cls.domain.call_center_config = cls.get_call_center_config()
        cls.domain.save()

        # Create user
        cls.user = CommCareUser.create(TEST_DOMAIN, 'user1', '***', None, None)

        # Create locations
        LocationType.objects.get_or_create(
            domain=cls.domain.name,
            name=LOCATION_TYPE,
        )
        cls.root_location = make_loc('root_loc',
                                     type=LOCATION_TYPE,
                                     domain=TEST_DOMAIN)
        cls.child_location = make_loc('child_loc',
                                      type=LOCATION_TYPE,
                                      domain=TEST_DOMAIN,
                                      parent=cls.root_location)
        cls.grandchild_location = make_loc('grandchild_loc',
                                           type=LOCATION_TYPE,
                                           domain=TEST_DOMAIN,
                                           parent=cls.child_location)
Ejemplo n.º 3
0
    def setUp(self):
        super(LocationGroupTest, self).setUp()
        self.test_state = make_loc("teststate", type="state", domain=self.domain.name)
        self.test_village = make_loc("testvillage", type="village", parent=self.test_state, domain=self.domain.name)
        self.test_outlet = make_loc("testoutlet", type="outlet", parent=self.test_village, domain=self.domain.name)

        toggles.MULTIPLE_LOCATIONS_PER_USER.set("domain:{}".format(self.domain.name), True)
Ejemplo n.º 4
0
 def test_archived_locations_are_not_included(self):
     parent_type = make_loc_type('parent',
                                 domain=self.domain,
                                 shares_cases=True,
                                 view_descendants=True)
     child_type = make_loc_type('child',
                                domain=self.domain,
                                shares_cases=False)
     grandchild_type = make_loc_type('grandchild',
                                     domain=self.domain,
                                     shares_cases=True)
     parent_loc = make_loc('parent',
                           type=parent_type.name,
                           domain=self.domain)
     child_loc = make_loc('child',
                          type=child_type.name,
                          domain=self.domain,
                          parent=parent_loc)
     grandchild_loc = make_loc('grandchild',
                               type=grandchild_type.name,
                               domain=self.domain,
                               parent=child_loc)
     make_loc('archived_grandchild',
              type=grandchild_type.name,
              domain=self.domain,
              parent=child_loc,
              is_archived=True)
     self.user.set_location(parent_loc)
     self.assertEqual(
         set([parent_loc._id, grandchild_loc._id]),
         set([g._id for g in self.user.get_case_sharing_groups()]))
    def setUpClass(cls):
        super(CustomRecipientTest, cls).setUpClass()
        cls.create_basic_related_cases()

        cls.location_types = setup_location_types(cls.domain,
            [SUPERVISOR_LOCATION_TYPE_CODE, AWC_LOCATION_TYPE_CODE])

        cls.ls1 = make_loc('ls1', domain=cls.domain, type=SUPERVISOR_LOCATION_TYPE_CODE)
        cls.awc1 = make_loc('awc1', domain=cls.domain, type=AWC_LOCATION_TYPE_CODE, parent=cls.ls1)
        cls.awc2 = make_loc('awc2', domain=cls.domain, type=AWC_LOCATION_TYPE_CODE, parent=None)
Ejemplo n.º 6
0
    def setUpClass(cls):
        super(CustomRecipientTest, cls).setUpClass()
        cls.create_basic_related_cases()

        cls.location_types = setup_location_types(cls.domain,
            [SUPERVISOR_LOCATION_TYPE_CODE, AWC_LOCATION_TYPE_CODE])

        cls.ls1 = make_loc('ls1', domain=cls.domain, type=SUPERVISOR_LOCATION_TYPE_CODE)
        cls.awc1 = make_loc('awc1', domain=cls.domain, type=AWC_LOCATION_TYPE_CODE, parent=cls.ls1)
        cls.awc2 = make_loc('awc2', domain=cls.domain, type=AWC_LOCATION_TYPE_CODE, parent=None)
Ejemplo n.º 7
0
 def test_assigned_loc_included_with_descendants(self):
     parent_type = make_loc_type('parent', domain=self.domain, shares_cases=True, view_descendants=True)
     child_type = make_loc_type('child', domain=self.domain, shares_cases=True)
     parent_loc = make_loc('parent', type=parent_type.name, domain=self.domain)
     child_loc = make_loc('child', type=child_type.name, domain=self.domain, parent=parent_loc)
     self.user.set_location(parent_loc)
     self.assertEqual(
         set([parent_loc._id, child_loc._id]),
         set([g._id for g in self.user.get_case_sharing_groups()])
     )
Ejemplo n.º 8
0
 def test_assigned_loc_included_with_descendants(self):
     parent_type = make_loc_type('parent', domain=self.domain, shares_cases=True, view_descendants=True)
     child_type = make_loc_type('child', domain=self.domain, shares_cases=True)
     parent_loc = make_loc('parent', type=parent_type.name, domain=self.domain)
     child_loc = make_loc('child', type=child_type.name, domain=self.domain, parent=parent_loc)
     self.user.set_location(parent_loc)
     self.assertEqual(
         set([parent_loc._id, child_loc._id]),
         set([g._id for g in self.user.get_case_sharing_groups()])
     )
Ejemplo n.º 9
0
    def test_location_queries(self):
        test_state1 = make_loc("teststate1", type="state", parent=self.user.location, domain=self.domain.name)
        test_state2 = make_loc("teststate2", type="state", parent=self.user.location, domain=self.domain.name)
        test_village1 = make_loc("testvillage1", type="village", parent=test_state1, domain=self.domain.name)
        test_village1.site_code = "tv1"
        test_village1.save()
        test_village2 = make_loc("testvillage2", type="village", parent=test_state2, domain=self.domain.name)

        def compare(list1, list2):
            self.assertEqual(set([l._id for l in list1]), set([l._id for l in list2]))

        # descendants
        compare([test_state1, test_state2, test_village1, test_village2], self.user.location.descendants)

        # children
        compare([test_state1, test_state2], self.user.location.children)

        # siblings
        compare([test_state2], test_state1.siblings())

        # parent and parent_id
        self.assertEqual(self.user.location._id, test_state1.parent_id)
        self.assertEqual(self.user.location._id, test_state1.parent._id)

        # is_root
        self.assertTrue(self.user.location.is_root)
        self.assertFalse(test_state1.is_root)

        # Location.root_locations
        compare([self.user.location], Location.root_locations(self.domain.name))

        # Location.filter_by_type
        compare([test_village1, test_village2], Location.filter_by_type(self.domain.name, "village"))
        compare([test_village1], Location.filter_by_type(self.domain.name, "village", test_state1))

        # Location.get_in_domain
        test_village2.domain = "rejected"
        bootstrap_location_types("rejected")
        test_village2.save()
        self.assertEqual(Location.get_in_domain(self.domain.name, test_village1._id)._id, test_village1._id)
        self.assertIsNone(Location.get_in_domain(self.domain.name, test_village2._id))
        self.assertIsNone(Location.get_in_domain(self.domain.name, "not-a-real-id"))

        self.assertEqual(
            {loc._id for loc in [self.user.location, test_state1, test_state2, test_village1]},
            set(SQLLocation.objects.filter(domain=self.domain.name).location_ids()),
        )

        # Location.by_site_code
        self.assertEqual(test_village1._id, Location.by_site_code(self.domain.name, "tv1")._id)
        self.assertIsNone(None, Location.by_site_code(self.domain.name, "notreal"))

        # Location.by_domain
        compare([self.user.location, test_state1, test_state2, test_village1], Location.by_domain(self.domain.name))
Ejemplo n.º 10
0
 def test_only_case_sharing_descendents_included(self):
     parent_type = make_loc_type('parent', domain=self.domain, shares_cases=True, view_descendants=True)
     child_type = make_loc_type('child', domain=self.domain, shares_cases=False)
     grandchild_type = make_loc_type('grandchild', domain=self.domain, shares_cases=True)
     parent_loc = make_loc('parent', type=parent_type.name, domain=self.domain)
     child_loc = make_loc('child', type=child_type.name, domain=self.domain, parent=parent_loc)
     grandchild_loc = make_loc('grandchild', type=grandchild_type.name, domain=self.domain, parent=child_loc)
     self.user.set_location(parent_loc)
     self.assertEqual(
         set(map(_group_id, [parent_loc._id, grandchild_loc._id])),
         set(self.user.location_group_ids())
     )
Ejemplo n.º 11
0
    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())
Ejemplo n.º 12
0
 def test_only_case_sharing_descendents_included(self):
     parent_type = make_loc_type('parent', domain=self.domain, shares_cases=True, view_descendants=True)
     child_type = make_loc_type('child', domain=self.domain, shares_cases=False)
     grandchild_type = make_loc_type('grandchild', domain=self.domain, shares_cases=True)
     parent_loc = make_loc('parent', type=parent_type.name, domain=self.domain)
     child_loc = make_loc('child', type=child_type.name, domain=self.domain, parent=parent_loc)
     grandchild_loc = make_loc('grandchild', type=grandchild_type.name, domain=self.domain, parent=child_loc)
     self.user.set_location(parent_loc)
     self.assertEqual(
         set([parent_loc._id, grandchild_loc._id]),
         set([g._id for g in self.user.get_case_sharing_groups()])
     )
Ejemplo n.º 13
0
    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()
Ejemplo n.º 14
0
 def test_sharing_no_descendants(self):
     case_sharing_type = make_loc_type('case-sharing', domain=self.domain, shares_cases=True)
     location = make_loc('loc', type=case_sharing_type.name, domain=self.domain)
     self.user.set_location(location)
     location_groups = self.user.get_case_sharing_groups()
     self.assertEqual(1, len(location_groups))
     self.assertEqual(location.location_id, location_groups[0]._id)
Ejemplo n.º 15
0
 def test_sharing_no_descendants(self):
     case_sharing_type = make_loc_type('case-sharing', domain=self.domain, shares_cases=True)
     location = make_loc('loc', type=case_sharing_type.name, domain=self.domain)
     self.user.set_location(location)
     location_groups = self.user.get_case_sharing_groups()
     self.assertEqual(1, len(location_groups))
     self.assertEqual(location.location_id, location_groups[0]._id)
Ejemplo n.º 16
0
    def setUp(self):
        self.domain = create_domain('locations-test')
        self.domain.locations_enabled = True
        self.domain.location_types = [
            LocationType(
                name='state',
                allowed_parents=[''],
                administrative=True
            ),
            LocationType(
                name='village',
                allowed_parents=['state'],
                administrative=True
            ),
            LocationType(
                name='outlet',
                allowed_parents=['village']
            ),
        ]
        self.domain.save()

        self.loc = make_loc('loc', type='outlet', domain=self.domain.name)
        self.sp = make_supply_point(self.domain.name, self.loc)

        self.user = CommCareUser.create(
            self.domain.name,
            'username',
            'password',
            first_name='Bob',
            last_name='Builder',
        )
        self.user.set_location(self.loc)
Ejemplo n.º 17
0
    def setUp(self):
        super(LocationGroupTest, self).setUp()
        self.test_state = make_loc('teststate',
                                   type='state',
                                   domain=self.domain.name)
        self.test_village = make_loc('testvillage',
                                     type='village',
                                     parent=self.test_state,
                                     domain=self.domain.name)
        self.test_outlet = make_loc('testoutlet',
                                    type='outlet',
                                    parent=self.test_village,
                                    domain=self.domain.name)

        toggles.MULTIPLE_LOCATIONS_PER_USER.set(
            "domain:{}".format(self.domain.name), True)
Ejemplo n.º 18
0
 def test_no_case_sharing(self):
     no_case_sharing_type = make_loc_type('no-case-sharing',
                                          domain=self.domain)
     location = make_loc('loc',
                         type=no_case_sharing_type.name,
                         domain=self.domain)
     self.user.set_location(location)
     self.assertEqual([], self.user.get_case_sharing_groups())
Ejemplo n.º 19
0
    def test_location_fixture_generator(self):
        """
        This tests the location XML fixture generator. It specifically ensures that no duplicate XML
        nodes are generated when all locations have a parent and multiple locations are enabled.
        """
        self.domain.commtrack_enabled = True
        self.domain.save()
        self.loc.delete()

        state = make_loc("teststate1", type="state", domain=self.domain.name)
        district = make_loc("testdistrict1", type="district", domain=self.domain.name, parent=state)
        block = make_loc("testblock1", type="block", domain=self.domain.name, parent=district)
        village = make_loc("testvillage1", type="village", domain=self.domain.name, parent=block)
        outlet1 = make_loc("testoutlet1", type="outlet", domain=self.domain.name, parent=village)
        outlet2 = make_loc("testoutlet2", type="outlet", domain=self.domain.name, parent=village)
        outlet3 = make_loc("testoutlet3", type="outlet", domain=self.domain.name, parent=village)
        self.user.set_location(outlet2)
        self.user.add_location_delegate(outlet1)
        self.user.add_location_delegate(outlet2)
        self.user.add_location_delegate(outlet3)
        self.user.add_location_delegate(state)
        self.user.save()
        fixture = location_fixture_generator(self.user, "2.0")
        self.assertEquals(len(fixture[0].findall(".//state")), 1)
        self.assertEquals(len(fixture[0].findall(".//outlet")), 3)
Ejemplo n.º 20
0
    def setUpClass(cls):
        super(CallCenterLocationOwnerOptionsViewTest, cls).setUpClass()

        with trap_extra_setup(ConnectionError,
                              msg="cannot connect to elasicsearch"):
            es = get_es_new()
            ensure_index_deleted(USER_INDEX_INFO.index)
            ensure_index_deleted(GROUP_INDEX_INFO.index)
            initialize_index_and_mapping(es, USER_INDEX_INFO)
            initialize_index_and_mapping(es, GROUP_INDEX_INFO)

        # Create domain
        cls.domain = create_domain(TEST_DOMAIN)
        cls.domain.save()

        CALL_CENTER_LOCATION_OWNERS.set(cls.domain.name, True,
                                        NAMESPACE_DOMAIN)

        cls.username = "******"
        cls.password = "******"
        cls.web_user = WebUser.create(cls.domain.name, cls.username,
                                      cls.password)
        cls.web_user.save()

        # Create case sharing groups
        cls.groups = []
        for i in range(2):
            group = Group(domain=TEST_DOMAIN,
                          name="group{}".format(i),
                          case_sharing=True)
            group.save()
            send_to_elasticsearch('groups', group.to_json())
            cls.groups.append(group)
        es.indices.refresh(GROUP_INDEX_INFO.index)
        cls.group_ids = {g._id for g in cls.groups}

        # Create locations
        LocationType.objects.get_or_create(
            domain=cls.domain.name,
            name=LOCATION_TYPE,
            shares_cases=True,
        )
        cls.locations = [
            make_loc('loc{}'.format(i), type=LOCATION_TYPE, domain=TEST_DOMAIN)
            for i in range(4)
        ]
        cls.location_ids = {l._id for l in cls.locations}

        # Create users
        cls.users = [
            CommCareUser.create(TEST_DOMAIN, 'user{}'.format(i), '***')
            for i in range(3)
        ]
        for user in cls.users:
            send_to_elasticsearch('users', user.to_json())
        es.indices.refresh(USER_INDEX_INFO.index)
        cls.user_ids = {u._id for u in cls.users}
Ejemplo n.º 21
0
    def test_location_fixture_generator(self):
        """
        This tests the location XML fixture generator. It specifically ensures that no duplicate XML
        nodes are generated when all locations have a parent and multiple locations are enabled.
        """
        self.domain.commtrack_enabled = True
        self.domain.save()
        self.loc.delete()

        state = make_loc(
            'teststate1',
            type='state',
            domain=self.domain.name
        )
        district = make_loc(
            'testdistrict1',
            type='district',
            domain=self.domain.name,
            parent=state
        )
        block = make_loc(
            'testblock1',
            type='block',
            domain=self.domain.name,
            parent=district
        )
        village = make_loc(
            'testvillage1',
            type='village',
            domain=self.domain.name,
            parent=block
        )
        outlet1 = make_loc(
            'testoutlet1',
            type='outlet',
            domain=self.domain.name,
            parent=village
        )
        outlet2 = make_loc(
            'testoutlet2',
            type='outlet',
            domain=self.domain.name,
            parent=village
        )
        outlet3 = make_loc(
            'testoutlet3',
            type='outlet',
            domain=self.domain.name,
            parent=village
        )
        self.user.set_location(outlet2)
        self.user.add_location_delegate(outlet1)
        self.user.add_location_delegate(outlet2)
        self.user.add_location_delegate(outlet3)
        self.user.add_location_delegate(state)
        self.user.save()
        fixture = location_fixture_generator(self.user.to_ota_restore_user(), '2.0')
        self.assertEquals(len(fixture[0].findall('.//state')), 1)
        self.assertEquals(len(fixture[0].findall('.//outlet')), 3)
Ejemplo n.º 22
0
    def test_location_fixture_generator(self):
        """
        This tests the location XML fixture generator. It specifically ensures that no duplicate XML
        nodes are generated when all locations have a parent and multiple locations are enabled.
        """
        self.domain.commtrack_enabled = True
        self.domain.save()
        self.loc.delete()

        state = make_loc(
            'teststate1',
            type='state',
            domain=self.domain.name
        )
        district = make_loc(
            'testdistrict1',
            type='district',
            domain=self.domain.name,
            parent=state
        )
        block = make_loc(
            'testblock1',
            type='block',
            domain=self.domain.name,
            parent=district
        )
        village = make_loc(
            'testvillage1',
            type='village',
            domain=self.domain.name,
            parent=block
        )
        outlet1 = make_loc(
            'testoutlet1',
            type='outlet',
            domain=self.domain.name,
            parent=village
        )
        outlet2 = make_loc(
            'testoutlet2',
            type='outlet',
            domain=self.domain.name,
            parent=village
        )
        outlet3 = make_loc(
            'testoutlet3',
            type='outlet',
            domain=self.domain.name,
            parent=village
        )
        self.user.set_location(outlet2)
        self.user.add_location_delegate(outlet1)
        self.user.add_location_delegate(outlet2)
        self.user.add_location_delegate(outlet3)
        self.user.add_location_delegate(state)
        self.user.save()
        fixture = location_fixture_generator(self.user, '2.0')
        self.assertEquals(len(fixture[0].findall('.//state')), 1)
        self.assertEquals(len(fixture[0].findall('.//outlet')), 3)
Ejemplo n.º 23
0
    def setUp(self):
        self.domain = create_domain("locations-test")
        self.domain.convert_to_commtrack()
        bootstrap_location_types(self.domain.name)

        self.loc = make_loc("loc", type="outlet", domain=self.domain.name)
        self.sp = make_supply_point(self.domain.name, self.loc)

        self.user = CommCareUser.create(self.domain.name, "username", "password", first_name="Bob", last_name="Builder")
        self.user.set_location(self.loc)
Ejemplo n.º 24
0
 def setUp(self):
     self.domain = Domain(name='test', is_active=True)
     self.domain.save()
     self.location_type = LocationType.objects.create(domain=self.domain.name, name='testtype')
     self.user_assigned_locations = [
         make_loc('root', domain=self.domain.name, type=self.location_type).sql_location
     ]
     self.request = RequestFactory()
     self.request.couch_user = WebUser()
     self.request.domain = self.domain
    def setUpClass(cls):
        super(TestAWWSubmissionPerformanceIndicator, cls).setUpClass()
        cls.domain_obj = create_domain(cls.domain)

        def make_user(name, location):
            user = CommCareUser.create(cls.domain, name, 'password')
            user.set_location(location)
            return user

        cls.loc_types = setup_location_types(cls.domain, ['awc'])
        cls.loc = make_loc('awc', type='awc', domain=cls.domain)
        cls.loc2 = make_loc('awc2', type='awc', domain=cls.domain)
        cls.user = make_user('user', cls.loc)
        cls.user_sans_aggregation = make_user('user_sans_aggregation',
                                              cls.loc2)
        cls.agg_inactive_aww = AggregateInactiveAWW.objects.create(
            awc_site_code=cls.user.raw_username,
            awc_id=cls.loc._id,
            last_submission=None,
        )
Ejemplo n.º 26
0
    def setUp(self):
        super(LocationGroupTest, self).setUp()

        self.test_state = make_loc(
            'teststate',
            type='state',
            domain=self.domain.name
        )
        self.test_village = make_loc(
            'testvillage',
            type='village',
            parent=self.test_state,
            domain=self.domain.name
        )
        self.test_outlet = make_loc(
            'testoutlet',
            type='outlet',
            parent=self.test_village,
            domain=self.domain.name
        )
Ejemplo n.º 27
0
    def setUp(self):
        super(LocationGroupTest, self).setUp()
        self.test_state = make_loc(
            'teststate',
            type='state',
            domain=self.domain.name
        )
        self.test_village = make_loc(
            'testvillage',
            type='village',
            parent=self.test_state,
            domain=self.domain.name
        )
        self.test_outlet = make_loc(
            'testoutlet',
            type='outlet',
            parent=self.test_village,
            domain=self.domain.name
        )

        toggles.MULTIPLE_LOCATIONS_PER_USER.set(self.domain.name, True, NAMESPACE_DOMAIN)
Ejemplo n.º 28
0
 def setUp(self):
     self.domain = Domain(name='test', is_active=True)
     self.domain.save()
     self.location_type = LocationType.objects.create(
         domain=self.domain.name, name='testtype')
     self.user_assigned_locations = [
         make_loc('root', domain=self.domain.name,
                  type=self.location_type).sql_location
     ]
     self.request = RequestFactory()
     self.request.couch_user = WebUser()
     self.request.domain = self.domain
Ejemplo n.º 29
0
    def setUpClass(cls):
        super(TestAWWSubmissionPerformanceIndicator, cls).setUpClass()
        cls.domain_obj = create_domain(cls.domain)

        def make_user(name, location):
            user = CommCareUser.create(cls.domain, name, 'password')
            user.set_location(location)
            return user

        cls.loc_types = setup_location_types(cls.domain, ['awc'])
        cls.loc = make_loc('awc', type='awc', domain=cls.domain)
        cls.user = make_user('user', cls.loc)
    def setUpClass(cls):
        super(CustomContentTest, cls).setUpClass()

        cls.location_types = setup_location_types(cls.domain, [
            STATE_TYPE_CODE,
            DISTRICT_LOCATION_TYPE_CODE,
            BLOCK_LOCATION_TYPE_CODE,
            SUPERVISOR_LOCATION_TYPE_CODE,
            AWC_LOCATION_TYPE_CODE,
        ])

        cls.state1 = make_loc('state1', domain=cls.domain, type=STATE_TYPE_CODE)
        cls.district1 = make_loc('district1', domain=cls.domain, type=DISTRICT_LOCATION_TYPE_CODE,
            parent=cls.state1)
        cls.block1 = make_loc('block1', domain=cls.domain, type=BLOCK_LOCATION_TYPE_CODE, parent=cls.district1)
        cls.ls1 = make_loc('ls1', domain=cls.domain, type=SUPERVISOR_LOCATION_TYPE_CODE, parent=cls.block1)
        cls.awc1 = make_loc('awc1', domain=cls.domain, type=AWC_LOCATION_TYPE_CODE, parent=cls.ls1)
        cls.awc2 = make_loc('awc2', domain=cls.domain, type=AWC_LOCATION_TYPE_CODE, parent=None)

        cls.user1 = CommCareUser.create(cls.domain, 'mobile-1', 'abc', location=cls.awc1)
        cls.user2 = CommCareUser.create(cls.domain, 'mobile-2', 'abc', location=cls.awc2)
        cls.user3 = CommCareUser.create(cls.domain, 'mobile-3', 'abc', location=cls.ls1)

        cls.create_basic_related_cases(cls.awc1.location_id)
        cls.red_child_health_case = cls.create_case(
            'child_health',
            parent_case_id=cls.child_person_case.case_id,
            parent_identifier='parent',
            parent_relationship='extension',
            update={'zscore_grading_wfa': 'red'},
            owner_id=cls.awc1.location_id,
        )

        cls.migrated_case = cls.create_case('person', update={'migration_status': 'migrated'})
        cls.opted_out_case = cls.create_case('person', update={'registered_status': 'not_registered'})
Ejemplo n.º 31
0
    def setUp(self):
        self.domain = create_domain("locations-test")
        self.domain.save()

        LocationType.objects.get_or_create(domain=self.domain.name, name="outlet")

        make_product(self.domain.name, "apple", "apple")
        make_product(self.domain.name, "orange", "orange")
        make_product(self.domain.name, "banana", "banana")
        make_product(self.domain.name, "pear", "pear")

        couch_loc = make_loc("loc", type="outlet", domain=self.domain.name)
        self.loc = couch_loc.sql_location
Ejemplo n.º 32
0
    def setUpClass(cls):
        # Create domain
        cls.domain = create_domain(TEST_DOMAIN)
        cls.domain.call_center_config = cls.get_call_center_config()
        cls.domain.save()

        # Create user
        cls.user = CommCareUser.create(TEST_DOMAIN, 'user1', '***')

        # Create locations
        LocationType.objects.get_or_create(
            domain=cls.domain.name,
            name=LOCATION_TYPE,
        )
        cls.root_location = make_loc(
            'root_loc', type=LOCATION_TYPE, domain=TEST_DOMAIN
        )
        cls.child_location = make_loc(
            'child_loc', type=LOCATION_TYPE, domain=TEST_DOMAIN, parent=cls.root_location
        )
        cls.grandchild_location = make_loc(
            'grandchild_loc', type=LOCATION_TYPE, domain=TEST_DOMAIN, parent=cls.child_location
        )
Ejemplo n.º 33
0
    def setUpClass(cls):
        super().setUpClass()

        cls.domain = 'test'
        cls.domain_obj = create_domain(cls.domain)

        set_toggle(FILTERED_BULK_USER_DOWNLOAD.slug,
                   cls.domain,
                   True,
                   namespace=NAMESPACE_DOMAIN)

        location_type = LocationType(domain=cls.domain, name='phony')
        location_type.save()

        cls.some_location = make_loc('1',
                                     'some_location',
                                     type=location_type,
                                     domain=cls.domain_obj.name)

        cls.admin_user = WebUser.create(
            cls.domain_obj.name,
            '*****@*****.**',
            'badpassword',
            None,
            None,
            email='*****@*****.**',
            first_name='Edith',
            last_name='Wharton',
            is_admin=True,
        )

        cls.admin_user_with_location = WebUser.create(
            cls.domain_obj.name,
            '*****@*****.**',
            'badpassword',
            None,
            None,
            email='*****@*****.**',
            first_name='Edith',
            last_name='Wharton',
            is_admin=True,
        )
        cls.admin_user_with_location.set_location(cls.domain,
                                                  cls.some_location)

        populate_user_index([
            cls.admin_user_with_location,
            cls.admin_user,
        ])
Ejemplo n.º 34
0
    def setUp(self):
        self.domain = create_domain('locations-test')
        bootstrap_location_types(self.domain.name)

        self.loc = make_loc('loc', type='outlet', domain=self.domain.name)
        self.sp = make_supply_point(self.domain.name, self.loc)

        self.user = CommCareUser.create(
            self.domain.name,
            'username',
            'password',
            first_name='Bob',
            last_name='Builder',
        )
        self.user.set_location(self.loc)
Ejemplo n.º 35
0
    def setUp(self):
        self.domain = create_domain('locations-test')
        self.loc = make_loc('loc')
        self.sp = make_supply_point(self.domain.name, self.loc)

        self.user = CommCareUser.create(
            self.domain.name,
            'username',
            'password',
            first_name='Bob',
            last_name='Builder'
        )
        self.user.save()

        self.user.add_location(self.loc)
Ejemplo n.º 36
0
 def setUp(self):
     self.subject = ExpandedMobileWorkerFilter
     clear_domain_names('test')
     self.domain = Domain(name='test', is_active=True)
     self.domain.save()
     self.location_type = LocationType.objects.create(
         domain=self.domain.name, name='testtype')
     self.user_assigned_locations = [
         make_loc('root',
                  domain=self.domain.name,
                  type=self.location_type.code).sql_location
     ]
     self.request = RequestFactory()
     self.request.couch_user = WebUser()
     self.request.domain = self.domain
Ejemplo n.º 37
0
    def setUpClass(cls):
        super(CallCenterLocationOwnerOptionsViewTest, cls).setUpClass()

        with trap_extra_setup(ConnectionError, msg="cannot connect to elasicsearch"):
            es = get_es_new()
            ensure_index_deleted(USER_INDEX_INFO.index)
            ensure_index_deleted(GROUP_INDEX_INFO.index)
            initialize_index_and_mapping(es, USER_INDEX_INFO)
            initialize_index_and_mapping(es, GROUP_INDEX_INFO)

        # Create domain
        cls.domain = create_domain(TEST_DOMAIN)
        cls.domain.save()

        CALL_CENTER_LOCATION_OWNERS.set(cls.domain.name, True, NAMESPACE_DOMAIN)

        cls.username = "******"
        cls.password = "******"
        cls.web_user = WebUser.create(cls.domain.name, cls.username, cls.password)
        cls.web_user.save()

        # Create case sharing groups
        cls.groups = []
        for i in range(2):
            group = Group(domain=TEST_DOMAIN, name="group{}".format(i), case_sharing=True)
            group.save()
            send_to_elasticsearch('groups', group.to_json())
            cls.groups.append(group)
        es.indices.refresh(GROUP_INDEX_INFO.index)
        cls.group_ids = {g._id for g in cls.groups}

        # Create locations
        LocationType.objects.get_or_create(
            domain=cls.domain.name,
            name=LOCATION_TYPE,
            shares_cases=True,
        )
        cls.locations = [
            make_loc('loc{}'.format(i), type=LOCATION_TYPE, domain=TEST_DOMAIN) for i in range(4)
        ]
        cls.location_ids = {l._id for l in cls.locations}

        # Create users
        cls.users = [CommCareUser.create(TEST_DOMAIN, 'user{}'.format(i), '***') for i in range(3)]
        for user in cls.users:
            send_to_elasticsearch('users', user.to_json())
        es.indices.refresh(USER_INDEX_INFO.index)
        cls.user_ids = {u._id for u in cls.users}
Ejemplo n.º 38
0
    def setUp(self):
        self.domain = create_domain('locations-test')
        self.domain.save()

        LocationType.objects.get_or_create(
            domain=self.domain.name,
            name='outlet',
        )

        make_product(self.domain.name, 'apple', 'apple')
        make_product(self.domain.name, 'orange', 'orange')
        make_product(self.domain.name, 'banana', 'banana')
        make_product(self.domain.name, 'pear', 'pear')

        couch_loc = make_loc('loc', type='outlet', domain=self.domain.name)
        self.loc = couch_loc.sql_location
Ejemplo n.º 39
0
    def setUp(self):
        self.domain = create_domain('locations-test')
        self.domain.convert_to_commtrack()
        bootstrap_location_types(self.domain.name)

        self.loc = make_loc('loc', type='outlet', domain=self.domain.name)
        self.sp = make_supply_point(self.domain.name, self.loc)

        self.user = CommCareUser.create(
            self.domain.name,
            'username',
            'password',
            first_name='Bob',
            last_name='Builder',
        )
        self.user.set_location(self.loc)
Ejemplo n.º 40
0
    def setUp(self):
        self.domain = create_domain('locations-test')
        self.domain.save()

        LocationType.objects.get_or_create(
            domain=self.domain.name,
            name='outlet',
        )

        make_product(self.domain.name, 'apple', 'apple')
        make_product(self.domain.name, 'orange', 'orange')
        make_product(self.domain.name, 'banana', 'banana')
        make_product(self.domain.name, 'pear', 'pear')

        couch_loc = make_loc('loc', type='outlet', domain=self.domain.name)
        self.loc = couch_loc.sql_location
Ejemplo n.º 41
0
    def setUp(self):
        self.domain = create_domain('locations-test')
        self.domain.locations_enabled = True
        self.domain.location_types = [
            LocationType(
                name='outlet',
                allowed_parents=[]
            ),
        ]
        self.domain.save()

        make_product(self.domain.name, 'apple', 'apple')
        make_product(self.domain.name, 'orange', 'orange')
        make_product(self.domain.name, 'banana', 'banana')
        make_product(self.domain.name, 'pear', 'pear')

        couch_loc = make_loc('loc', type='outlet', domain=self.domain.name)
        self.loc = couch_loc.sql_location
Ejemplo n.º 42
0
    def setUpClass(cls):
        super(TestAWWSubmissionPerformanceIndicator, cls).setUpClass()
        cls.domain_obj = create_domain(cls.domain)

        def make_user(name, location):
            user = CommCareUser.create(cls.domain, name, 'password')
            user.set_location(location)
            return user

        cls.loc_types = setup_location_types(cls.domain, ['awc'])
        cls.loc = make_loc('awc', type='awc', domain=cls.domain)
        cls.user = make_user('user', cls.loc)
        cls.user_sans_app_status = make_user('user_sans_app_status', cls.loc)
        cls.batch = Batch.objects.create(
            start_datetime=datetime.now(),
            end_datetime=datetime.now(),
            completed_on=datetime.now(),
            dag_slug='batch',
        )
        cls.app_dim = ApplicationDim.objects.create(
            batch=cls.batch,
            domain=cls.domain,
            application_id=100007,
            name='icds-cas',
            deleted=False,
        )
        cls.user_dim = UserDim.objects.create(
            batch=cls.batch,
            user_id=cls.user.get_id,
            username=cls.user.username,
            user_type=cls.user._get_user_type(),
            doc_type=cls.user.doc_type,
            date_joined=datetime.utcnow() - timedelta(days=5000),
            deleted=False,
        )
        cls.app_fact = ApplicationStatusFact.objects.create(
            batch=cls.batch,
            app_dim=cls.app_dim,
            user_dim=cls.user_dim,
            domain=cls.domain,
            last_form_submission_date=None,
        )
Ejemplo n.º 43
0
    def setUpClass(cls):
        super(CustomContentTest, cls).setUpClass()

        cls.location_types = setup_location_types(cls.domain, [
            STATE_TYPE_CODE,
            DISTRICT_LOCATION_TYPE_CODE,
            BLOCK_LOCATION_TYPE_CODE,
            SUPERVISOR_LOCATION_TYPE_CODE,
            AWC_LOCATION_TYPE_CODE,
        ])

        cls.state1 = make_loc('state1', domain=cls.domain, type=STATE_TYPE_CODE)
        cls.district1 = make_loc('district1', domain=cls.domain, type=DISTRICT_LOCATION_TYPE_CODE,
            parent=cls.state1)
        cls.block1 = make_loc('block1', domain=cls.domain, type=BLOCK_LOCATION_TYPE_CODE, parent=cls.district1)
        cls.ls1 = make_loc('ls1', domain=cls.domain, type=SUPERVISOR_LOCATION_TYPE_CODE, parent=cls.block1)
        cls.awc1 = make_loc('awc1', domain=cls.domain, type=AWC_LOCATION_TYPE_CODE, parent=cls.ls1)
        cls.awc2 = make_loc('awc2', domain=cls.domain, type=AWC_LOCATION_TYPE_CODE, parent=None)

        cls.user1 = CommCareUser.create(cls.domain, 'mobile-1', 'abc', location=cls.awc1)
        cls.user2 = CommCareUser.create(cls.domain, 'mobile-2', 'abc', location=cls.awc2)
        cls.user3 = CommCareUser.create(cls.domain, 'mobile-3', 'abc', location=cls.ls1)

        cls.create_user_case(cls.user1)
        cls.create_user_case(cls.user2)
        cls.create_user_case(cls.user3)

        cls.create_basic_related_cases(cls.awc1.location_id)
        cls.red_child_health_case = cls.create_case(
            'child_health',
            parent_case_id=cls.child_person_case.case_id,
            parent_identifier='parent',
            parent_relationship='extension',
            update={'zscore_grading_wfa': 'red'},
            owner_id=cls.awc1.location_id,
        )

        cls.migrated_case = cls.create_case('person', update={'migration_status': 'migrated'})
        cls.opted_out_case = cls.create_case('person', update={'registered_status': 'not_registered'})
Ejemplo n.º 44
0
    def test_location_queries(self):
        test_state1 = make_loc(
            'teststate1',
            type='state',
            parent=self.user.location,
            domain=self.domain.name
        )
        test_state2 = make_loc(
            'teststate2',
            type='state',
            parent=self.user.location,
            domain=self.domain.name
        )
        test_village1 = make_loc(
            'testvillage1',
            type='village',
            parent=test_state1,
            domain=self.domain.name
        )
        test_village1.site_code = 'tv1'
        test_village1.save()
        test_village2 = make_loc(
            'testvillage2',
            type='village',
            parent=test_state2,
            domain=self.domain.name
        )

        def compare(list1, list2):
            self.assertEqual(
                set([l._id for l in list1]),
                set([l._id for l in list2])
            )

        # descendants
        compare(
            [test_state1, test_state2, test_village1, test_village2],
            self.user.location.descendants
        )

        # children
        compare(
            [test_state1, test_state2],
            self.user.location.children
        )

        # siblings
        compare(
            [test_state2],
            test_state1.siblings()
        )

        # parent and parent_id
        self.assertEqual(
            self.user.location._id,
            test_state1.parent_id
        )
        self.assertEqual(
            self.user.location._id,
            test_state1.parent._id
        )


        # is_root
        self.assertTrue(self.user.location.is_root)
        self.assertFalse(test_state1.is_root)

        # Location.root_locations
        compare(
            [self.user.location],
            Location.root_locations(self.domain.name)
        )

        # Location.filter_by_type
        compare(
            [test_village1, test_village2],
            Location.filter_by_type(self.domain.name, 'village')
        )
        compare(
            [test_village1],
            Location.filter_by_type(self.domain.name, 'village', test_state1)
        )

        # Location.get_in_domain
        test_village2.domain = 'rejected'
        bootstrap_location_types('rejected')
        test_village2.save()
        self.assertEqual(
            Location.get_in_domain(self.domain.name, test_village1._id)._id,
            test_village1._id
        )
        self.assertIsNone(
            Location.get_in_domain(self.domain.name, test_village2._id),
        )
        self.assertIsNone(
            Location.get_in_domain(self.domain.name, 'not-a-real-id'),
        )

        def _all_locations(domain):
            return Location.view(
                'locations/hierarchy',
                startkey=[domain],
                endkey=[domain, {}],
                reduce=False,
                include_docs=True
            ).all()
        compare(
            [self.user.location, test_state1, test_state2, test_village1],
            _all_locations(self.domain.name)
        )

        # Location.by_site_code
        self.assertEqual(
            test_village1._id,
            Location.by_site_code(self.domain.name, 'tv1')._id
        )
        self.assertIsNone(
            None,
            Location.by_site_code(self.domain.name, 'notreal')
        )

        # Location.by_domain
        compare(
            [self.user.location, test_state1, test_state2, test_village1],
            Location.by_domain(self.domain.name)
        )
Ejemplo n.º 45
0
    def setUpClass(cls):
        super(AllCommCareUsersTest, cls).setUpClass()
        delete_all_users()
        hard_delete_deleted_users()
        cls.ccdomain = Domain(name='cc_user_domain')
        cls.ccdomain.save()
        cls.other_domain = Domain(name='other_domain')
        cls.other_domain.save()
        bootstrap_location_types(cls.ccdomain.name)

        initialize_domain_with_default_roles(cls.ccdomain.name)
        cls.user_roles = UserRole.objects.get_by_domain(cls.ccdomain.name)
        cls.custom_role = UserRole.create(cls.ccdomain.name, "Custom Role")

        cls.loc1 = make_loc('spain', domain=cls.ccdomain.name, type="district")
        cls.loc2 = make_loc('madagascar',
                            domain=cls.ccdomain.name,
                            type="district")

        cls.ccuser_1 = CommCareUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            created_by=None,
            created_via=None,
            email='*****@*****.**',
        )
        cls.ccuser_1.set_location(cls.loc1)
        cls.ccuser_1.save()
        cls.ccuser_2 = CommCareUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            created_by=None,
            created_via=None,
            email='*****@*****.**',
        )
        cls.ccuser_2.set_role(cls.ccdomain.name,
                              cls.custom_role.get_qualified_id())
        cls.ccuser_2.set_location(cls.loc2)
        cls.ccuser_2.save()

        cls.web_user = WebUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            created_by=None,
            created_via=None,
            email='*****@*****.**',
        )
        cls.location_restricted_web_user = WebUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            created_by=None,
            created_via=None,
            email='*****@*****.**',
        )
        cls.location_restricted_web_user.add_to_assigned_locations(
            domain=cls.ccdomain.name, location=cls.loc2)

        cls.ccuser_other_domain = CommCareUser.create(
            domain=cls.other_domain.name,
            username='******',
            password='******',
            created_by=None,
            created_via=None,
            email='*****@*****.**',
        )
        cls.retired_user = CommCareUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            created_by=None,
            created_via=None,
            email='*****@*****.**',
        )
        cls.retired_user.retire(cls.ccdomain.name, deleted_by=None)

        cls.ccuser_inactive = CommCareUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            created_by=None,
            created_via=None,
            email='*****@*****.**',
        )
        cls.ccuser_inactive.is_active = False
        cls.ccuser_inactive.save()
        cls.ccuser_inactive.set_location(cls.loc2)
Ejemplo n.º 46
0
    def test_location_queries(self):
        test_state1 = make_loc(
            'teststate1',
            type='state',
            parent=self.user.location,
            domain=self.domain.name
        )
        test_state2 = make_loc(
            'teststate2',
            type='state',
            parent=self.user.location,
            domain=self.domain.name
        )
        test_village1 = make_loc(
            'testvillage1',
            type='village',
            parent=test_state1,
            domain=self.domain.name
        )
        test_village1.site_code = 'tv1'
        test_village1.save()
        test_village2 = make_loc(
            'testvillage2',
            type='village',
            parent=test_state2,
            domain=self.domain.name
        )

        def compare(list1, list2):
            self.assertEqual(
                set([l._id for l in list1]),
                set([l._id for l in list2])
            )

        # descendants
        compare(
            [test_state1, test_state2, test_village1, test_village2],
            self.user.location.descendants
        )

        # children
        compare(
            [test_state1, test_state2],
            self.user.location.get_children()
        )

        # parent and parent_location_id
        self.assertEqual(
            self.user.location.location_id,
            test_state1.parent_location_id
        )
        self.assertEqual(
            self.user.location.location_id,
            test_state1.parent._id
        )

        # Location.root_locations
        compare(
            [self.user.location],
            Location.root_locations(self.domain.name)
        )

        # Location.filter_by_type
        compare(
            [test_village1, test_village2],
            Location.filter_by_type(self.domain.name, 'village')
        )
        compare(
            [test_village1],
            Location.filter_by_type(self.domain.name, 'village', test_state1)
        )

        create_domain('rejected')
        bootstrap_location_types('rejected')
        test_village2.domain = 'rejected'
        test_village2.save()
        self.assertEqual(
            {loc.location_id for loc in [self.user.location, test_state1, test_state2,
                                 test_village1]},
            set(SQLLocation.objects.filter(domain=self.domain.name).location_ids()),
        )

        # Location.by_site_code
        self.assertEqual(
            test_village1._id,
            Location.by_site_code(self.domain.name, 'tv1')._id
        )
        self.assertIsNone(
            None,
            Location.by_site_code(self.domain.name, 'notreal')
        )

        # Location.by_domain
        compare(
            [self.user.location, test_state1, test_state2, test_village1],
            Location.by_domain(self.domain.name)
        )
Ejemplo n.º 47
0
    def setUpClass(cls):
        super(TestReminders, cls).setUpClass()
        cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend()
        cls.domain = prepare_domain(TEST_DOMAIN)
        cls.loc1 = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=TEST_DOMAIN)
        cls.loc2 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN)
        cls.region = make_loc(code="region", name="Test Region", type="region", domain=TEST_DOMAIN)

        cls.user1 = bootstrap_user(
            username='******', phone_number='1111', home_loc=cls.loc2, domain=TEST_DOMAIN,
            first_name='test', last_name='test1',
            user_data={
                'role': []
            }
        )
        cls.user2 = bootstrap_user(
            username='******', phone_number='2222', home_loc=cls.loc1, domain=TEST_DOMAIN,
            first_name='test', last_name='test2',
            user_data={
                'role': ['Other'],
                'needs_reminders': "False"
            }
        )

        cls.user3 = bootstrap_user(
            username='******', phone_number='3333', home_loc=cls.loc2, domain=TEST_DOMAIN,
            first_name='test', last_name='test3',
            user_data={
                'role': ['Nurse'],
                'needs_reminders': "True"
            }
        )

        cls.in_charge = bootstrap_user(
            username='******', phone_number='4444', home_loc=cls.loc2, domain=TEST_DOMAIN,
            first_name='test', last_name='test4',
            user_data={
                'role': ['In Charge']
            }
        )

        cls.web_user = bootstrap_web_user(
            domain=TEST_DOMAIN,
            username='******',
            password='******',
            email='*****@*****.**',
            location=cls.loc2,
            phone_number='5555'
        )

        EWSExtension.objects.create(
            domain=TEST_DOMAIN,
            user_id=cls.web_user.get_id,
            sms_notifications=True,
            location_id=cls.loc2.get_id
        )

        cls.web_user2 = bootstrap_web_user(
            domain=TEST_DOMAIN,
            username='******',
            password='******',
            email='*****@*****.**',
            location=cls.region,
            phone_number='6666'
        )

        set_sms_notifications(TEST_DOMAIN, cls.web_user2, True)

        FacilityInCharge.objects.create(
            user_id=cls.in_charge.get_id,
            location=cls.loc2.sql_location
        )

        cls.product = Product(
            domain=TEST_DOMAIN,
            name='Test Product',
            code_='tp',
            unit='each'
        )
        cls.product.save()

        cls.product2 = Product(
            domain=TEST_DOMAIN,
            name='Test Product2',
            code_='tp2',
            unit='each'
        )
        cls.product2.save()

        sql_product = SQLProduct.objects.get(product_id=cls.product.get_id)
        sql_product2 = SQLProduct.objects.get(product_id=cls.product2.get_id)

        sql_location1 = cls.loc1.sql_location
        sql_location2 = cls.loc2.sql_location

        sql_location1.products = [sql_product]
        sql_location2.products = [sql_product, sql_product2]
        sql_location1.save()
        sql_location2.save()
Ejemplo n.º 48
0
    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())
Ejemplo n.º 49
0
    def setUpClass(cls):
        super(GetICDSSmsUsageTest, cls).setUpClass()
        cls.domain_obj = create_domain(cls.domain)

        def make_user(name, location):
            user = CommCareUser.create(cls.domain, name, 'password')
            user.set_location(location)
            return user

        cls.loc_types = setup_location_types(cls.domain, ['state', 'district', 'block', 'supervisor', 'awc'])
        cls.states = (
            make_loc('state', type='state', domain=cls.domain),
            make_loc('state2', type='state', domain=cls.domain),
        )
        cls.districts = (
            make_loc('district', type='district', domain=cls.domain, parent=cls.states[0]),
            make_loc('district2', type='district', domain=cls.domain, parent=cls.states[1]),
        )
        cls.blocks = (
            make_loc('block', type='block', domain=cls.domain, parent=cls.districts[0]),
            make_loc('block2', type='block', domain=cls.domain, parent=cls.districts[1]),
        )
        cls.supervisors = (
            make_loc('supervisor', type='supervisor', domain=cls.domain, parent=cls.blocks[0]),
            make_loc('supervisor2', type='supervisor', domain=cls.domain, parent=cls.blocks[1]),
        )
        cls.awcs = (
            make_loc('awc', type='awc', domain=cls.domain, parent=cls.supervisors[0]),
            make_loc('awc2', type='awc', domain=cls.domain, parent=cls.supervisors[1]),
        )
        cls.users = (
            make_user('user', cls.awcs[0]),
            make_user('user2', cls.awcs[1]),
        )

        cls.sms_list.append(SMS.objects.create(
            domain=cls.domain,
            date=date(2017, 4, 10),
            backend_api=AirtelTCLBackend.get_api_id(),
            direction='O',
            processed=True,
            couch_recipient=cls.users[0]._id,
            custom_metadata={'icds_indicator': 'xxx'}
        ))
        cls.sms_list.append(SMS.objects.create(
            domain=cls.domain,
            date=date(2017, 4, 10),
            backend_api=AirtelTCLBackend.get_api_id(),
            direction='O',
            processed=True,
            couch_recipient=cls.users[0]._id,
            custom_metadata={'icds_indicator': 'xxx'}
        ))
        cls.sms_list.append(SMS.objects.create(
            domain=cls.domain,
            date=date(2017, 4, 10),
            backend_api=AirtelTCLBackend.get_api_id(),
            direction='O',
            processed=True,
            couch_recipient=cls.users[1]._id,
            custom_metadata={'icds_indicator': 'xxx'}
        ))
        cls.sms_list.append(SMS.objects.create(
            domain=cls.domain,
            date=date(2017, 4, 10),
            backend_api=AirtelTCLBackend.get_api_id(),
            direction='O',
            processed=True,
            couch_recipient=cls.users[1]._id,
            custom_metadata={'icds_indicator': 'aaa'}
        ))
        date_start = '2017-04-01'
        date_end = '2017-05-01'
        call_command("get_icds_sms_usage", cls.domain, date_start, date_end)
        cls.workbook_name = 'icds-sms-usage--{0}--{1}.xlsx'.format(date_start, date_end)
        cls.workbook = openpyxl.load_workbook(cls.workbook_name)
Ejemplo n.º 50
0
    def setUpClass(cls):
        super(TestReminders, cls).setUpClass()
        cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend()
        cls.domain = prepare_domain(TEST_DOMAIN)
        cls.loc1 = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=TEST_DOMAIN)
        cls.loc2 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN)
        cls.region = make_loc(code="region", name="Test Region", type="region", domain=TEST_DOMAIN)

        cls.user1 = bootstrap_user(
            username="******",
            phone_number="1111",
            home_loc=cls.loc2,
            domain=TEST_DOMAIN,
            first_name="test",
            last_name="test1",
            user_data={"role": []},
        )
        cls.user2 = bootstrap_user(
            username="******",
            phone_number="2222",
            home_loc=cls.loc1,
            domain=TEST_DOMAIN,
            first_name="test",
            last_name="test2",
            user_data={"role": ["Other"], "needs_reminders": "False"},
        )

        cls.user3 = bootstrap_user(
            username="******",
            phone_number="3333",
            home_loc=cls.loc2,
            domain=TEST_DOMAIN,
            first_name="test",
            last_name="test3",
            user_data={"role": ["Nurse"], "needs_reminders": "True"},
        )

        cls.in_charge = bootstrap_user(
            username="******",
            phone_number="4444",
            home_loc=cls.loc2,
            domain=TEST_DOMAIN,
            first_name="test",
            last_name="test4",
            user_data={"role": ["In Charge"]},
        )

        cls.web_user = bootstrap_web_user(
            domain=TEST_DOMAIN,
            username="******",
            password="******",
            email="*****@*****.**",
            location=cls.loc2,
            phone_number="5555",
        )

        EWSExtension.objects.create(
            domain=TEST_DOMAIN, user_id=cls.web_user.get_id, sms_notifications=True, location_id=cls.loc2.get_id
        )

        cls.web_user2 = bootstrap_web_user(
            domain=TEST_DOMAIN,
            username="******",
            password="******",
            email="*****@*****.**",
            location=cls.region,
            phone_number="6666",
        )

        set_sms_notifications(TEST_DOMAIN, cls.web_user2, True)

        FacilityInCharge.objects.create(user_id=cls.in_charge.get_id, location=cls.loc2.sql_location)

        cls.product = Product(domain=TEST_DOMAIN, name="Test Product", code_="tp", unit="each")
        cls.product.save()

        cls.product2 = Product(domain=TEST_DOMAIN, name="Test Product2", code_="tp2", unit="each")
        cls.product2.save()

        sql_product = SQLProduct.objects.get(product_id=cls.product.get_id)
        sql_product2 = SQLProduct.objects.get(product_id=cls.product2.get_id)

        sql_location1 = cls.loc1.sql_location
        sql_location2 = cls.loc2.sql_location

        sql_location1.products = [sql_product]
        sql_location2.products = [sql_product, sql_product2]
        sql_location1.save()
        sql_location2.save()
Ejemplo n.º 51
0
    def setUpClass(cls):
        super(AllCommCareUsersTest, cls).setUpClass()
        delete_all_users()
        hard_delete_deleted_users()
        cls.ccdomain = Domain(name='cc_user_domain')
        cls.ccdomain.save()
        cls.other_domain = Domain(name='other_domain')
        cls.other_domain.save()
        bootstrap_location_types(cls.ccdomain.name)

        UserRole.init_domain_with_presets(cls.ccdomain.name)
        cls.user_roles = UserRole.by_domain(cls.ccdomain.name)
        cls.custom_role = UserRole.get_or_create_with_permissions(
            cls.ccdomain.name,
            Permissions(
                edit_apps=True,
                edit_web_users=True,
                view_web_users=True,
                view_roles=True,
            ), "Custom Role")
        cls.custom_role.save()

        cls.loc1 = make_loc('spain', domain=cls.ccdomain.name, type="district")
        cls.loc2 = make_loc('madagascar',
                            domain=cls.ccdomain.name,
                            type="district")

        cls.ccuser_1 = CommCareUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            email='*****@*****.**',
        )
        cls.ccuser_1.set_location(cls.loc1)
        cls.ccuser_1.save()
        cls.ccuser_2 = CommCareUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            email='*****@*****.**',
        )
        cls.ccuser_2.set_role(cls.ccdomain.name,
                              cls.custom_role.get_qualified_id())
        cls.ccuser_2.set_location(cls.loc2)
        cls.ccuser_2.save()

        cls.web_user = WebUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            email='*****@*****.**',
        )
        cls.ccuser_other_domain = CommCareUser.create(
            domain=cls.other_domain.name,
            username='******',
            password='******',
            email='*****@*****.**',
        )
        cls.retired_user = CommCareUser.create(
            domain=cls.ccdomain.name,
            username='******',
            password='******',
            email='*****@*****.**',
        )
        cls.retired_user.retire()
Ejemplo n.º 52
0
    def setUpClass(cls):
        super(GetICDSSmsUsageTest, cls).setUpClass()
        cls.domain_obj = create_domain(cls.domain)

        def make_user(name, location):
            user = CommCareUser.create(cls.domain, name, 'password')
            user.set_location(location)
            return user

        cls.loc_types = setup_location_types(cls.domain, ['state', 'district', 'block', 'supervisor', 'awc'])
        cls.states = (
            make_loc('state', type='state', domain=cls.domain),
            make_loc('state2', type='state', domain=cls.domain),
        )
        cls.districts = (
            make_loc('district', type='district', domain=cls.domain, parent=cls.states[0]),
            make_loc('district2', type='district', domain=cls.domain, parent=cls.states[1]),
        )
        cls.blocks = (
            make_loc('block', type='block', domain=cls.domain, parent=cls.districts[0]),
            make_loc('block2', type='block', domain=cls.domain, parent=cls.districts[1]),
        )
        cls.supervisors = (
            make_loc('supervisor', type='supervisor', domain=cls.domain, parent=cls.blocks[0]),
            make_loc('supervisor2', type='supervisor', domain=cls.domain, parent=cls.blocks[1]),
        )
        cls.awcs = (
            make_loc('awc', type='awc', domain=cls.domain, parent=cls.supervisors[0]),
            make_loc('awc2', type='awc', domain=cls.domain, parent=cls.supervisors[1]),
        )
        cls.users = (
            make_user('user', cls.awcs[0]),
            make_user('user2', cls.awcs[1]),
        )

        cls.sms_list.append(SMS.objects.create(
            domain=cls.domain,
            date=date(2017, 4, 10),
            backend_api=AirtelTCLBackend.get_api_id(),
            direction='O',
            processed=True,
            couch_recipient=cls.users[0]._id,
            custom_metadata={'icds_indicator': 'xxx'}
        ))
        cls.sms_list.append(SMS.objects.create(
            domain=cls.domain,
            date=date(2017, 4, 10),
            backend_api=AirtelTCLBackend.get_api_id(),
            direction='O',
            processed=True,
            couch_recipient=cls.users[0]._id,
            custom_metadata={'icds_indicator': 'xxx'}
        ))
        cls.sms_list.append(SMS.objects.create(
            domain=cls.domain,
            date=date(2017, 4, 10),
            backend_api=AirtelTCLBackend.get_api_id(),
            direction='O',
            processed=True,
            couch_recipient=cls.users[1]._id,
            custom_metadata={'icds_indicator': 'xxx'}
        ))
        cls.sms_list.append(SMS.objects.create(
            domain=cls.domain,
            date=date(2017, 4, 10),
            backend_api=AirtelTCLBackend.get_api_id(),
            direction='O',
            processed=True,
            couch_recipient=cls.users[1]._id,
            custom_metadata={'icds_indicator': 'aaa'}
        ))
        date_start = '2017-04-01'
        date_end = '2017-05-01'
        call_command("get_icds_sms_usage", cls.domain, date_start, date_end)
        cls.workbook_name = 'icds-sms-usage--{0}--{1}.xlsx'.format(date_start, date_end)
        cls.workbook = openpyxl.load_workbook(cls.workbook_name)
Ejemplo n.º 53
0
    def setUpClass(cls):
        cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend()
        cls.domain = prepare_domain(TEST_DOMAIN)
        cls.loc1 = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=TEST_DOMAIN)
        cls.loc2 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN)
        cls.region = make_loc(code="region", name="Test Region", type="region", domain=TEST_DOMAIN)

        cls.user1 = bootstrap_user(
            username='******', phone_number='1111', home_loc=cls.loc2, domain=TEST_DOMAIN,
            first_name='test', last_name='test1',
            user_data={
                'role': []
            }
        )
        cls.user2 = bootstrap_user(
            username='******', phone_number='2222', home_loc=cls.loc1, domain=TEST_DOMAIN,
            first_name='test', last_name='test2',
            user_data={
                'role': ['Other'],
                'needs_reminders': "False"
            }
        )

        cls.user3 = bootstrap_user(
            username='******', phone_number='3333', home_loc=cls.loc2, domain=TEST_DOMAIN,
            first_name='test', last_name='test3',
            user_data={
                'role': ['Nurse'],
                'needs_reminders': "True"
            }
        )

        cls.in_charge = bootstrap_user(
            username='******', phone_number='4444', home_loc=cls.loc2, domain=TEST_DOMAIN,
            first_name='test', last_name='test4',
            user_data={
                'role': ['In Charge']
            }
        )

        cls.web_user = bootstrap_web_user(
            domain=TEST_DOMAIN,
            username='******',
            password='******',
            email='*****@*****.**',
            location=cls.loc2,
            phone_number='5555'
        )

        EWSExtension.objects.create(
            domain=TEST_DOMAIN,
            user_id=cls.web_user.get_id,
            sms_notifications=True,
            location_id=cls.loc2.get_id
        )

        cls.web_user2 = bootstrap_web_user(
            domain=TEST_DOMAIN,
            username='******',
            password='******',
            email='*****@*****.**',
            location=cls.region,
            phone_number='6666'
        )

        set_sms_notifications(TEST_DOMAIN, cls.web_user2, True)

        FacilityInCharge.objects.create(
            user_id=cls.in_charge.get_id,
            location=cls.loc2.sql_location
        )

        cls.product = Product(
            domain=TEST_DOMAIN,
            name='Test Product',
            code_='tp',
            unit='each'
        )
        cls.product.save()

        cls.product2 = Product(
            domain=TEST_DOMAIN,
            name='Test Product2',
            code_='tp2',
            unit='each'
        )
        cls.product2.save()

        sql_product = SQLProduct.objects.get(product_id=cls.product.get_id)
        sql_product2 = SQLProduct.objects.get(product_id=cls.product2.get_id)

        sql_location1 = cls.loc1.sql_location
        sql_location2 = cls.loc2.sql_location

        sql_location1.products = [sql_product]
        sql_location2.products = [sql_product, sql_product2]
        sql_location1.save()
        sql_location2.save()
Ejemplo n.º 54
0
    def test_location_queries(self):
        test_state1 = make_loc(
            'teststate1',
            type='state',
            parent=self.user.location,
            domain=self.domain.name
        )
        test_state2 = make_loc(
            'teststate2',
            type='state',
            parent=self.user.location,
            domain=self.domain.name
        )
        test_village1 = make_loc(
            'testvillage1',
            type='village',
            parent=test_state1,
            domain=self.domain.name
        )
        test_village1.site_code = 'tv1'
        test_village1.save()
        test_village2 = make_loc(
            'testvillage2',
            type='village',
            parent=test_state2,
            domain=self.domain.name
        )

        def compare(list1, list2):
            self.assertEqual(
                set([l._id for l in list1]),
                set([l._id for l in list2])
            )

        # descendants
        compare(
            [test_state1, test_state2, test_village1, test_village2],
            self.user.location.descendants
        )

        # children
        compare(
            [test_state1, test_state2],
            self.user.location.children
        )

        # siblings
        compare(
            [test_state2],
            test_state1.siblings()
        )

        # parent and parent_id
        self.assertEqual(
            self.user.location._id,
            test_state1.parent_id
        )
        self.assertEqual(
            self.user.location._id,
            test_state1.parent._id
        )


        # is_root
        self.assertTrue(self.user.location.is_root)
        self.assertFalse(test_state1.is_root)

        # Location.root_locations
        compare(
            [self.user.location],
            Location.root_locations(self.domain.name)
        )

        # Location.filter_by_type
        compare(
            [test_village1, test_village2],
            Location.filter_by_type(self.domain.name, 'village')
        )
        compare(
            [test_village1],
            Location.filter_by_type(self.domain.name, 'village', test_state1)
        )

        # Location.filter_by_type_count
        self.assertEqual(
            2,
            Location.filter_by_type_count(self.domain.name, 'village')
        )
        self.assertEqual(
            1,
            Location.filter_by_type_count(self.domain.name, 'village', test_state1)
        )

        # Location.get_in_domain
        test_village2.domain = 'rejected'
        test_village2.save()
        self.assertEqual(
            Location.get_in_domain(self.domain.name, test_village1._id)._id,
            test_village1._id
        )
        self.assertIsNone(
            Location.get_in_domain(self.domain.name, test_village2._id),
        )
        self.assertIsNone(
            Location.get_in_domain(self.domain.name, 'not-a-real-id'),
        )

        # Location.all_locations
        compare(
            [self.user.location, test_state1, test_state2, test_village1],
            Location.all_locations(self.domain.name)
        )

        # Location.by_site_code
        self.assertEqual(
            test_village1._id,
            Location.by_site_code(self.domain.name, 'tv1')._id
        )
        self.assertIsNone(
            None,
            Location.by_site_code(self.domain.name, 'notreal')
        )

        # Location.by_domain
        compare(
            [self.user.location, test_state1, test_state2, test_village1],
            Location.by_domain(self.domain.name)
        )
Ejemplo n.º 55
0
 def test_no_case_sharing(self):
     no_case_sharing_type = make_loc_type('no-case-sharing', domain=self.domain)
     location = make_loc('loc', type=no_case_sharing_type.name, domain=self.domain)
     self.user.set_location(location)
     self.assertEqual([], self.user.get_case_sharing_groups())
Ejemplo n.º 56
0
 def test_sharing_no_descendants(self):
     case_sharing_type = make_loc_type('case-sharing', domain=self.domain, shares_cases=True)
     location = make_loc('loc', type=case_sharing_type.name, domain=self.domain)
     self.user.set_location(location)
     self.assertEqual([_group_id(location._id)], self.user.location_group_ids())
Ejemplo n.º 57
0
    def test_location_queries(self):
        test_state1 = make_loc(
            'teststate1',
            type='state',
            parent=self.user.location,
            domain=self.domain.name
        )
        test_state2 = make_loc(
            'teststate2',
            type='state',
            parent=self.user.location,
            domain=self.domain.name
        )
        test_village1 = make_loc(
            'testvillage1',
            type='village',
            parent=test_state1,
            domain=self.domain.name
        )
        test_village1.site_code = 'tv1'
        test_village1.save()
        test_village2 = make_loc(
            'testvillage2',
            type='village',
            parent=test_state2,
            domain=self.domain.name
        )

        def compare(list1, list2):
            self.assertEqual(
                set([l._id for l in list1]),
                set([l._id for l in list2])
            )

        # descendants
        compare(
            [test_state1, test_state2, test_village1, test_village2],
            self.user.location.descendants
        )

        # children
        compare(
            [test_state1, test_state2],
            self.user.location.children
        )

        # siblings
        compare(
            [test_state2],
            test_state1.siblings()
        )

        # parent and parent_id
        self.assertEqual(
            self.user.location._id,
            test_state1.parent_id
        )
        self.assertEqual(
            self.user.location._id,
            test_state1.parent._id
        )


        # is_root
        self.assertTrue(self.user.location.is_root)
        self.assertFalse(test_state1.is_root)

        # Location.root_locations
        compare(
            [self.user.location],
            Location.root_locations(self.domain.name)
        )

        # Location.filter_by_type
        compare(
            [test_village1, test_village2],
            Location.filter_by_type(self.domain.name, 'village')
        )
        compare(
            [test_village1],
            Location.filter_by_type(self.domain.name, 'village', test_state1)
        )

        # Location.get_in_domain
        test_village2.domain = 'rejected'
        bootstrap_location_types('rejected')
        test_village2.save()
        self.assertEqual(
            Location.get_in_domain(self.domain.name, test_village1._id)._id,
            test_village1._id
        )
        self.assertIsNone(
            Location.get_in_domain(self.domain.name, test_village2._id),
        )
        self.assertIsNone(
            Location.get_in_domain(self.domain.name, 'not-a-real-id'),
        )

        self.assertEqual(
            {loc._id for loc in [self.user.location, test_state1, test_state2,
                                 test_village1]},
            set(SQLLocation.objects.filter(domain=self.domain.name).location_ids()),
        )

        # Location.by_site_code
        self.assertEqual(
            test_village1._id,
            Location.by_site_code(self.domain.name, 'tv1')._id
        )
        self.assertIsNone(
            None,
            Location.by_site_code(self.domain.name, 'notreal')
        )

        # Location.by_domain
        compare(
            [self.user.location, test_state1, test_state2, test_village1],
            Location.by_domain(self.domain.name)
        )