コード例 #1
0
    def setUpClass(cls):
        cls.domain = 'my-domain'
        cls.domain_obj = create_domain(cls.domain)

        cls.loc1 = make_loc('1', 'loc1', cls.domain)
        cls.loc2 = make_loc('2', 'loc2', cls.domain)
        cls.loc_ids = [l.location_id for l in [cls.loc1, cls.loc2]]
コード例 #2
0
ファイル: tests.py プロジェクト: johan--/commcare-hq
    def testLocationOwner(self):
        # This is actually testing several different things, but I figure it's
        # worth it, as each of these tests takes a non-trivial amount of time.
        non_case_sharing = LocationType.objects.create(
            domain=self.domain, name='lt1', shares_cases=False
        )
        case_sharing = LocationType.objects.create(
            domain=self.domain, name='lt2', shares_cases=True
        )
        location = make_loc('loc-1', 'Loc 1', self.domain, case_sharing)
        make_loc('loc-2', 'Loc 2', self.domain, case_sharing)
        duplicate_loc = make_loc('loc-3', 'Loc 2', self.domain, case_sharing)
        improper_loc = make_loc('loc-4', 'Loc 4', self.domain, non_case_sharing)

        res = self.import_mock_file([
            ['case_id', 'name', 'owner_id', 'owner_name'],
            ['', 'location-owner-id', location.group_id, ''],
            ['', 'location-owner-code', '', location.site_code],
            ['', 'location-owner-name', '', location.name],
            ['', 'duplicate-location-name', '', duplicate_loc.name],
            ['', 'non-case-owning-name', '', improper_loc.name],
        ])
        cases = {c.name: c for c in list(get_cases_in_domain(self.domain))}

        self.assertEqual(cases['location-owner-id'].owner_id, location.group_id)
        self.assertEqual(cases['location-owner-code'].owner_id, location.group_id)
        self.assertEqual(cases['location-owner-name'].owner_id, location.group_id)

        error_message = ImportErrors.DuplicateLocationName
        self.assertIn(error_message, res['errors'])
        self.assertEqual(res['errors'][error_message]['rows'], [4])

        error_message = ImportErrors.InvalidOwnerId
        self.assertIn(error_message, res['errors'])
        self.assertEqual(res['errors'][error_message]['rows'], [5])
コード例 #3
0
ファイル: utils.py プロジェクト: aristide/commcare-hq
    def setUpClass(cls):
        domain = prepare_domain(TEST_DOMAIN)
        mohsw = make_loc(code="moh1", name="Test MOHSW 1", type="MOHSW", domain=domain.name)

        region = make_loc(code="reg1", name="Test Region 1", type="REGION",
                          domain=domain.name, parent=mohsw)

        district = make_loc(code="dis1", name="Test District 1", type="DISTRICT",
                            domain=domain.name, parent=region)
        facility = make_loc(code="loc1", name="Test Facility 1", type="FACILITY",
                            domain=domain.name, parent=district)
        facility2 = make_loc(code="loc2", name="Test Facility 2", type="FACILITY",
                             domain=domain.name, parent=district)
        test.bootstrap(TEST_BACKEND, to_console=True)
        bootstrap_user(facility, username='******', domain=domain.name, home_loc='loc1', phone_number='5551234',
                       first_name='stella', last_name='Test')
        bootstrap_user(facility2, username='******', domain=domain.name, home_loc='loc2', phone_number='5555678',
                       first_name='bella', last_name='Test')
        bootstrap_user(district, username='******', domain=domain.name, home_loc='dis1', phone_number='555',
                       first_name='trella', last_name='Test')
        bootstrap_user(district, username='******', domain=domain.name, phone_number='111',
                       first_name='MSD', last_name='Person', user_data={'role': 'MSD'})

        p = Product(domain=domain.name, name='Jadelle', code='jd', unit='each')
        p.save()
        p2 = Product(domain=domain.name, name='Mc', code='mc', unit='each')
        p2.save()
コード例 #4
0
    def test_should_still_save_if_name_changes(self):
        # name isn't a dynamic property so should test these still
        # get updated alone
        parent = make_loc('sillyparents')
        parent.location_type = 'village'
        parent.save()
        existing = make_loc('existingloc', parent=parent)
        existing.location_type = 'outlet'
        existing.site_code = 'wat'
        existing.outlet_type = 'SHG'
        existing.save()

        data = {
            'id': existing._id,
            'name': 'newname',
            'site_code': 'wat',
            'outlet_type': 'SHG',
        }

        with patch('corehq.apps.locations.forms.LocationForm.save') as save:
            result = import_location(self.domain.name, 'outlet', data)
            self.assertEqual(save.call_count, 1)
            # id isn't accurate because of the mock, but want to make
            # sure we didn't actually return with None
            self.assertTrue(result['id'] is not None)
コード例 #5
0
    def setUp(self):
        self.domain = 'supply-point-dbaccessors'
        self.project = bootstrap_domain(self.domain)

        self.locations = [
            make_loc('1234', name='ben', domain=self.domain),
            make_loc('1235', name='ben', domain=self.domain),
            make_loc('1236', name='ben', domain=self.domain),
        ]
コード例 #6
0
    def setUp(self):
        super(SupplyPointDBAccessorsTest, self).setUp()
        self.domain = 'supply-point-dbaccessors'
        self.project = bootstrap_domain(self.domain)
        self.interface = SupplyInterface(self.domain)

        self.locations = [
            make_loc('1234', name='ben', domain=self.domain),
            make_loc('1235', name='ben', domain=self.domain),
            make_loc('1236', name='ben', domain=self.domain),
        ]
コード例 #7
0
    def test_setting_existing_list_does_not_submit(self):
        user = self.user
        user.clear_location_delegates()
        loc1 = make_loc('secondloc')
        loc2 = make_loc('thirdloc')

        user.add_location_delegate(loc1)
        user.add_location_delegate(loc2)

        with patch('corehq.apps.users.models.CommCareUser.submit_location_block') as submit_blocks:
            user.create_location_delegates([loc1, loc2])
            self.assertEqual(submit_blocks.call_count, 0)
コード例 #8
0
    def setUpClass(cls):

        cls.domain = create_domain(TEST_DOMAIN)
        cls.couch_user = WebUser.create(None, "report_test", "foobar")
        cls.couch_user.add_domain_membership(TEST_DOMAIN, is_admin=True)
        cls.couch_user.save()

        cls.products = {
            'pA': make_product(TEST_DOMAIN, 'prod A', 'pA'),
            'pB': make_product(TEST_DOMAIN, 'prod B', 'pB')
        }

        test_setup = {
            'A': {
                'A-a': {
                    'A-a-1': {'pA': 4, 'pB': 0},
                    'A-a-2': {'pB': 3},
                },
                'A-b': {
                    'A-b-1': {'pA': 2}
                }
            },
            'B': {
                'B-a': {
                    'B-a-1': {'pA': 1, 'pB': 1}
                }
            }
        }

        cls.sites = {}
        cls.regions = {}
        cls.districts = {}
        for region_name, districts in test_setup.items():
            region = make_loc(region_name, type='region')
            cls.regions[region_name] = region
            for district_name, sites in districts.items():
                district = make_loc(district_name, type='district', parent=region)
                cls.districts[district_name] = district
                for site_name, products in sites.items():
                    site = make_loc(site_name, type='site', parent=district, domain=TEST_DOMAIN)
                    cls.sites[site_name] = (site, products)
                    supply_point = make_supply_point(TEST_DOMAIN, site)
                    for p_code, stock in products.items():
                        prod = cls.products[p_code]
                        StockState.objects.create(
                            section_id='stock',
                            case_id=supply_point._id,
                            product_id=prod._id,
                            stock_on_hand=stock,
                            last_modified_date=datetime.utcnow(),
                        )
コード例 #9
0
ファイル: test_locations.py プロジェクト: dimagi/commcare-hq
    def test_full_delete(self):
        test_loc = make_loc(
            'abernathy_ranch',
            type='state',
            parent=self.user.location,
            domain=self.domain,
        )
        test_loc.save()

        original_count = _count_locations(self.domain)

        loc = self.user.sql_location
        loc.full_delete()

        # it should also delete children
        self.assertEqual(
            _count_locations(self.domain),
            original_count - 2
        )
        self.assertEqual(
            _count_root_locations(self.domain),
            0
        )
        # permanently gone from sql db
        self.assertEqual(
            len(SQLLocation.objects.all()),
            0
        )
コード例 #10
0
    def test_full_delete(self):
        test_loc = make_loc(
            'test_loc',
            type='state',
            parent=self.user.location
        )
        test_loc.save()

        original_count = len(list(Location.by_domain(self.domain.name)))

        loc = self.user.location
        loc.full_delete()

        # it should also delete children
        self.assertEqual(
            len(list(Location.by_domain(self.domain.name))),
            original_count - 2
        )
        self.assertEqual(
            len(Location.root_locations(self.domain.name)),
            0
        )
        # permanently gone from sql db
        self.assertEqual(
            len(SQLLocation.objects.all()),
            0
        )
コード例 #11
0
ファイル: test_locations.py プロジェクト: dimagi/commcare-hq
    def test_archive(self):
        test_state = make_loc(
            'pariah',
            type='state',
            parent=self.user.location,
            domain=self.domain,
        )
        test_state.save()

        original_count = _count_locations(self.domain)

        loc = self.user.sql_location
        loc.archive()

        # it should also archive children
        self.assertEqual(
            _count_locations(self.domain),
            original_count - 2
        )
        self.assertEqual(
            _count_root_locations(self.domain),
            0
        )

        loc.unarchive()

        # and unarchive children
        self.assertEqual(
            _count_locations(self.domain),
            original_count
        )
        self.assertEqual(
            _count_root_locations(self.domain),
            1
        )
コード例 #12
0
    def test_shouldnt_save_if_no_changes(self):
        parent = make_loc("sillyparents")
        parent.location_type = "village"
        parent.save()
        existing = make_loc("existingloc", parent=parent)
        existing.location_type = "outlet"
        existing.site_code = "wat"
        existing.outlet_type = "SHG"
        existing.save()

        data = {"id": existing._id, "name": existing.name, "site_code": "wat", "outlet_type": "SHG"}

        with patch("corehq.apps.locations.forms.LocationForm.save") as save:
            result = import_location(self.domain.name, "outlet", data)
            self.assertEqual(save.call_count, 0)
            self.assertEqual(result["id"], existing._id)
コード例 #13
0
ファイル: test_locations.py プロジェクト: nnestle/commcare-hq
    def test_archive(self):
        test_state = make_loc(
            'teststate',
            type='state',
            parent=self.user.location
        )
        test_state.save()

        original_count = len(list(Location.by_domain(self.domain.name)))

        loc = self.user.location
        loc.archive()

        # it should also archive children
        self.assertEqual(
            len(list(Location.by_domain(self.domain.name))),
            original_count - 2
        )
        self.assertEqual(
            len(Location.root_locations(self.domain.name)),
            0
        )

        loc.unarchive()

        # and unarchive children
        self.assertEqual(
            len(list(Location.by_domain(self.domain.name))),
            original_count
        )
        self.assertEqual(
            len(Location.root_locations(self.domain.name)),
            1
        )
コード例 #14
0
    def test_change_parent(self):
        parent = make_loc('originalparent', type='village')
        existing = make_loc('existingloc', type='outlet', parent=parent)

        new_parent = make_loc('new parent', type='village')
        self.assertNotEqual(parent._id, new_parent._id)
        data = {
            'site_code': existing.site_code,
            'name': existing.name,
            'outlet_type': 'SHG',
            'parent_site_code': new_parent.site_code,
        }

        result = import_location(self.domain.name, 'outlet', data)
        new_loc = Location.get(result['id'])
        self.assertEqual(existing._id, new_loc._id)
        self.assertEqual(new_loc.parent_id, new_parent._id)
コード例 #15
0
    def test_delete_closes_sp_cases(self):
        loc = make_loc('test_loc').sql_location
        sp = loc.linked_supply_point()

        self.assertFalse(sp.closed)
        loc.full_delete()
        sp = self.accessor.get_supply_point(sp.case_id)
        self.assertTrue(sp.closed)
コード例 #16
0
 def test_delete_closes_sp_cases(self):
     accessor = SupplyInterface(self.domain)
     loc = make_loc('ghost_nation', domain=self.domain).sql_location
     sp = loc.linked_supply_point()
     self.assertFalse(sp.closed)
     loc.full_delete()
     sp = accessor.get_supply_point(sp.case_id)
     self.assertTrue(sp.closed)
コード例 #17
0
    def test_can_set_locations(self):
        user = self.user

        loc1 = make_loc('secondloc')
        sp1 = make_supply_point(self.domain.name, loc1)

        loc2 = make_loc('thirdloc')
        sp2 = make_supply_point(self.domain.name, loc2)

        user.set_locations([loc1, loc2])

        # should only have the two new cases
        self.assertEqual(len(user.locations), 2)

        # and will have access to these two
        self.check_supply_point(user, sp1._id)
        self.check_supply_point(user, sp2._id)
コード例 #18
0
    def test_can_set_sql_locations(self):
        user = self.user

        loc1 = make_loc('secondloc').sql_location
        sp1 = loc1.linked_supply_point()

        loc2 = make_loc('thirdloc').sql_location
        sp2 = loc2.linked_supply_point()

        user.create_location_delegates([loc1, loc2])

        # should only have the two new cases
        self.assertEqual(len(user.locations), 2)

        # and will have access to these two
        self.check_supply_point(user, sp1.case_id)
        self.check_supply_point(user, sp2.case_id)
コード例 #19
0
    def test_can_set_locations(self):
        user = self.user

        loc1 = make_loc('secondloc')
        sp1 = loc1.linked_supply_point()

        loc2 = make_loc('thirdloc')
        sp2 = loc2.linked_supply_point()

        user.create_location_delegates([loc1, loc2])

        # should only have the two new cases
        self.assertEqual(len(user.locations), 2)

        # and will have access to these two
        self.check_supply_point(user, sp1.case_id)
        self.check_supply_point(user, sp2.case_id)
コード例 #20
0
    def test_setting_existing_list_does_not_submit(self):
        user = self.user

        user.clear_locations()

        loc1 = make_loc('secondloc')
        make_supply_point(self.domain.name, loc1)

        loc2 = make_loc('thirdloc')
        make_supply_point(self.domain.name, loc2)

        user.add_location(loc1)
        user.add_location(loc2)

        with patch('corehq.apps.commtrack.models.CommTrackUser.submit_location_block') as submit_blocks:
            user.set_locations([loc1, loc2])
            self.assertEqual(submit_blocks.call_count, 0)
コード例 #21
0
    def test_updating_existing_location_properties(self):
        parent = make_loc("sillyparents")
        parent.location_type = "village"
        parent.save()
        existing = make_loc("existingloc", parent=parent)
        existing.location_type = "outlet"
        existing.save()

        data = {"id": existing._id, "name": existing.name, "site_code": "wat", "outlet_type": "SHG"}

        self.assertNotEqual(existing.site_code, data["site_code"])

        loc_id = import_location(self.domain.name, "outlet", data).get("id", None)
        new_loc = Location.get(loc_id)

        self.assertEqual(existing._id, loc_id)
        self.assertEqual(new_loc.site_code, data["site_code"])
コード例 #22
0
    def test_delete_closes_sp_cases(self):
        loc = make_loc('test_loc').sql_location
        sp = loc.linked_supply_point()

        self.assertFalse(sp.closed)
        loc.full_delete()
        sp = self.accessor.get_supply_point(sp.case_id)
        self.assertTrue(sp.closed)
コード例 #23
0
    def test_setting_existing_list_does_not_submit(self):
        user = self.user

        user.clear_locations()

        loc1 = make_loc('secondloc')
        make_supply_point(self.domain.name, loc1)

        loc2 = make_loc('thirdloc')
        make_supply_point(self.domain.name, loc2)

        user.add_location(loc1)
        user.add_location(loc2)

        with patch('corehq.apps.commtrack.models.CommTrackUser.submit_location_block') as submit_blocks:
            user.set_locations([loc1, loc2])
            self.assertEqual(submit_blocks.call_count, 0)
コード例 #24
0
    def test_change_parent(self):
        parent = make_loc('originalparent', type='village')
        existing = make_loc('existingloc', type='outlet', parent=parent)

        new_parent = make_loc('new parent', type='village')
        self.assertNotEqual(parent._id, new_parent._id)
        data = {
            'site_code': existing.site_code,
            'name': existing.name,
            'outlet_type': 'SHG',
            'parent_site_code': new_parent.site_code,
        }

        result = import_location(self.domain.name, 'outlet', data)
        new_loc = Location.get(result['id'])
        self.assertEqual(existing._id, new_loc._id)
        self.assertEqual(new_loc.parent_id, new_parent._id)
コード例 #25
0
    def setUpClass(cls):

        cls.domain = create_domain(TEST_DOMAIN)
        cls.couch_user = WebUser.create(None, "report_test", "foobar")
        cls.couch_user.add_domain_membership(TEST_DOMAIN, is_admin=True)
        cls.couch_user.save()

        cls.products = {
            'pA': make_product(TEST_DOMAIN, 'prod A', 'pA'),
            'pB': make_product(TEST_DOMAIN, 'prod B', 'pB')
        }

        test_setup = {
            'A': {
                'A-a': {
                    'A-a-1': {'pA': 4, 'pB': 0},
                    'A-a-2': {'pB': 3},
                },
                'A-b': {
                    'A-b-1': {'pA': 2}
                }
            },
            'B': {
                'B-a': {
                    'B-a-1': {'pA': 1, 'pB': 1}
                }
            }
        }

        cls.sites = {}
        cls.regions = {}
        cls.districts = {}
        for region_name, districts in test_setup.items():
            region = make_loc(region_name, type='region')
            cls.regions[region_name] = region
            for district_name, sites in districts.items():
                district = make_loc(district_name, type='district', parent=region)
                cls.districts[district_name] = district
                for site_name, products in sites.items():
                    site = make_loc(site_name, type='site', parent=district)
                    cls.sites[site_name] = (site, products)
                    supply_point = make_supply_point(TEST_DOMAIN, site)
                    for p_code, stock in products.items():
                        prod = cls.products[p_code]
                        spp = make_supply_point_product(supply_point, prod._id)
                        update_supply_point_product_stock_level(spp, stock)
コード例 #26
0
ファイル: test_locations.py プロジェクト: nnestle/commcare-hq
    def test_can_set_locations(self):
        user = self.user

        loc1 = make_loc('secondloc')
        sp1 = make_supply_point(self.domain.name, loc1)

        loc2 = make_loc('thirdloc')
        sp2 = make_supply_point(self.domain.name, loc2)

        user.create_location_delegates([loc1, loc2])

        # should only have the two new cases
        self.assertEqual(len(user.locations), 2)

        # and will have access to these two
        self.check_supply_point(user, sp1._id)
        self.check_supply_point(user, sp2._id)
コード例 #27
0
ファイル: test_locations.py プロジェクト: dimagi/commcare-hq
 def test_delete_closes_sp_cases(self):
     accessor = SupplyInterface(self.domain)
     loc = make_loc('ghost_nation', domain=self.domain).sql_location
     sp = loc.linked_supply_point()
     self.assertFalse(sp.closed)
     loc.full_delete()
     sp = accessor.get_supply_point(sp.case_id)
     self.assertTrue(sp.closed)
コード例 #28
0
    def test_delete_closes_sp_cases(self):
        loc = make_loc('test_loc')
        sp = loc.linked_supply_point()

        self.assertFalse(sp.closed)
        loc.full_delete()
        sp = SupplyPointCase.get(sp.case_id)
        self.assertTrue(sp.closed)
コード例 #29
0
    def testLocationOwner(self):
        # This is actually testing several different things, but I figure it's
        # worth it, as each of these tests takes a non-trivial amount of time.
        non_case_sharing = LocationType.objects.create(domain=self.domain,
                                                       name='lt1',
                                                       shares_cases=False)
        case_sharing = LocationType.objects.create(domain=self.domain,
                                                   name='lt2',
                                                   shares_cases=True)
        location = make_loc('loc-1', 'Loc 1', self.domain, case_sharing.code)
        make_loc('loc-2', 'Loc 2', self.domain, case_sharing.code)
        duplicate_loc = make_loc('loc-3', 'Loc 2', self.domain,
                                 case_sharing.code)
        improper_loc = make_loc('loc-4', 'Loc 4', self.domain,
                                non_case_sharing.code)

        res = self.import_mock_file([
            ['case_id', 'name', 'owner_id', 'owner_name'],
            ['', 'location-owner-id', location.group_id, ''],
            ['', 'location-owner-code', '', location.site_code],
            ['', 'location-owner-name', '', location.name],
            ['', 'duplicate-location-name', '', duplicate_loc.name],
            ['', 'non-case-owning-name', '', improper_loc.name],
        ])
        case_ids = self.accessor.get_case_ids_in_domain()
        cases = {c.name: c for c in list(self.accessor.get_cases(case_ids))}

        self.assertEqual(cases['location-owner-id'].owner_id,
                         location.group_id)
        self.assertEqual(cases['location-owner-code'].owner_id,
                         location.group_id)
        self.assertEqual(cases['location-owner-name'].owner_id,
                         location.group_id)

        error_message = exceptions.DuplicateLocationName.title
        error_column_name = None
        self.assertIn(error_message, res['errors'])
        self.assertEqual(
            res['errors'][error_message][error_column_name]['rows'], [5])

        error_message = exceptions.InvalidOwner.title
        self.assertIn(error_message, res['errors'])
        error_column_name = 'owner_name'
        self.assertEqual(
            res['errors'][error_message][error_column_name]['rows'], [6])
コード例 #30
0
    def test_shouldnt_save_if_no_changes(self):
        parent = make_loc('sillyparents', type='village')
        existing = make_loc('existingloc', type='outlet', parent=parent)
        existing.site_code = 'wat'
        existing.outlet_type = 'SHG'
        existing.save()

        data = {
            'id': existing._id,
            'name': existing.name,
            'site_code': 'wat',
            'outlet_type': 'SHG',
        }

        with patch('corehq.apps.locations.forms.LocationForm.save') as save:
            result = import_location(self.domain.name, 'outlet', data)
            self.assertEqual(save.call_count, 0)
            self.assertEqual(result['id'], existing._id)
コード例 #31
0
    def test_sync(self):
        test_state = make_loc('teststate',
                              type='state',
                              parent=self.user.location)
        test_village = make_loc('testvillage',
                                type='village',
                                parent=test_state)

        try:
            sql_village = SQLLocation.objects.get(
                name='testvillage',
                domain=self.domain.name,
            )

            self.assertEqual(sql_village.name, test_village.name)
            self.assertEqual(sql_village.domain, test_village.domain)
        except SQLLocation.DoesNotExist:
            self.fail("Synced SQL object does not exist")
コード例 #32
0
    def test_change_to_invalid_parent(self):
        parent = make_loc('original parent', type='village')
        existing = make_loc('existingloc1', type='outlet', parent=parent)

        new_parent = make_loc('new parent', type='state')
        data = {
            'site_code': existing.site_code,
            'name': existing.name,
            'outlet_type': 'SHG',
            'parent_site_code': new_parent.site_code,
        }

        result = import_location(self.domain.name, 'outlet', data)
        self.assertEqual(None, result['id'])
        self.assertTrue('Invalid parent type' in result['message'])
        new_loc = Location.get(existing._id)
        self.assertEqual(existing._id, new_loc._id)
        self.assertEqual(new_loc.parent_id, parent._id)
コード例 #33
0
    def test_location_removal_only_submits_if_it_existed(self):
        user = self.user

        # can't test with the original since the user already owns it
        loc = make_loc('secondloc')

        with patch('corehq.apps.users.models.CommCareUser.submit_location_block') as submit_blocks:
            user.remove_location_delegate(loc)
            self.assertEqual(submit_blocks.call_count, 0)
コード例 #34
0
    def test_change_to_invalid_parent(self):
        parent = make_loc('original parent', type='village')
        existing = make_loc('existingloc1', type='outlet', parent=parent)

        new_parent = make_loc('new parent', type='state')
        data = {
            'site_code': existing.site_code,
            'name': existing.name,
            'outlet_type': 'SHG',
            'parent_site_code': new_parent.site_code,
        }

        result = import_location(self.domain.name, 'outlet', data)
        self.assertEqual(None, result['id'])
        self.assertTrue('Invalid parent type' in result['message'])
        new_loc = Location.get(existing._id)
        self.assertEqual(existing._id, new_loc._id)
        self.assertEqual(new_loc.parent_id, parent._id)
コード例 #35
0
ファイル: handler.py プロジェクト: kkrampa/commcare-hq
 def setUpClass(cls):
     super(HandlerTest, cls).setUpClass()
     cls.domain = 'ews-handler-test'
     bootstrap_domain(cls.domain)
     cls.create_account_and_subscription(cls.domain)
     cls.domain_obj = Domain.get_by_name(cls.domain)
     cls.loc = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=cls.domain)
     cls.user = bootstrap_user(username='******', phone_number='323232', domain=cls.domain,
                                home_loc=cls.loc)
コード例 #36
0
 def setUp(self):
     super(LocationsTest, self).setUp()
     self.user = CommCareUser.create(domain=self.domain,
                                     username='******',
                                     password='******',
                                     created_by=None,
                                     created_via=None)
     self.loc = make_loc('mariposa_saloon', domain=self.domain)
     self.user.set_location(self.loc)
コード例 #37
0
    def test_shouldnt_save_if_no_changes(self):
        parent = make_loc('sillyparents', type='village')
        existing = make_loc('existingloc', type='outlet', parent=parent)
        existing.site_code = 'wat'
        existing.outlet_type = 'SHG'
        existing.save()

        data = {
            'id': existing._id,
            'name': existing.name,
            'site_code': 'wat',
            'outlet_type': 'SHG',
        }

        with patch('corehq.apps.locations.forms.LocationForm.save') as save:
            result = import_location(self.domain.name, 'outlet', data)
            self.assertEqual(save.call_count, 0)
            self.assertEqual(result['id'], existing._id)
コード例 #38
0
    def test_updating_existing_location_properties(self):
        parent = make_loc('sillyparents', type='village')
        existing = make_loc('existingloc', type='outlet', parent=parent)

        data = {
            'id': existing._id,
            'name': existing.name,
            'site_code': 'wat',
            'outlet_type': 'SHG'
        }

        self.assertNotEqual(existing.site_code, data['site_code'])

        loc_id = import_location(self.domain.name, 'outlet', data).get('id', None)
        new_loc = Location.get(loc_id)

        self.assertEqual(existing._id, loc_id)
        self.assertEqual(new_loc.site_code, data['site_code'])
コード例 #39
0
    def test_commtrack_user_has_multiple_locations(self):
        user = self.user

        loc = make_loc('secondloc')
        sp = make_supply_point(self.domain.name, loc)
        user.add_location(loc)

        self.check_supply_point(user, sp._id)
        self.assertTrue(len(user.locations), 2)
        self.assertEqual(user.locations[1].name, 'secondloc')
コード例 #40
0
    def test_commtrack_user_has_multiple_locations(self):
        user = self.user

        loc = make_loc('secondloc')
        sp = loc.linked_supply_point()
        user.add_location_delegate(loc)

        self.check_supply_point(user, sp.case_id)
        self.assertTrue(len(user.locations), 2)
        self.assertEqual(user.locations[1].name, 'secondloc')
コード例 #41
0
    def test_location_removal_only_submits_if_it_existed(self):
        user = self.user

        # can't test with the original since the user already owns it
        loc = make_loc('secondloc')
        make_supply_point(self.domain.name, loc)

        with patch('corehq.apps.commtrack.models.CommTrackUser.submit_location_block') as submit_blocks:
            user.remove_location(loc)
            self.assertEqual(submit_blocks.call_count, 0)
コード例 #42
0
 def setUpClass(cls):
     super(SMSTests, cls).setUpClass()
     cls.backend, cls.backend_mapping = setup_default_sms_test_backend()
     cls.domain = util.bootstrap_domain(util.TEST_DOMAIN)
     util.bootstrap_location_types(cls.domain.name)
     util.bootstrap_products(cls.domain.name)
     cls.products = sorted(Product.by_domain(cls.domain.name), key=lambda p: p._id)
     cls.loc = util.make_loc('loc1')
     cls.sp = cls.loc.linked_supply_point()
     cls.users = [util.bootstrap_user(cls, **user_def) for user_def in cls.user_definitions]
コード例 #43
0
    def test_location_removal_only_submits_if_it_existed(self):
        user = self.user

        # can't test with the original since the user already owns it
        loc = make_loc('secondloc')
        make_supply_point(self.domain.name, loc)

        with patch('corehq.apps.commtrack.models.CommTrackUser.submit_location_block') as submit_blocks:
            user.remove_location(loc)
            self.assertEqual(submit_blocks.call_count, 0)
コード例 #44
0
 def setUpClass(cls):
     super(SMSTests, cls).setUpClass()
     cls.backend, cls.backend_mapping = setup_default_sms_test_backend()
     cls.domain = util.bootstrap_domain(util.TEST_DOMAIN)
     util.bootstrap_location_types(cls.domain.name)
     util.bootstrap_products(cls.domain.name)
     cls.products = sorted(Product.by_domain(cls.domain.name), key=lambda p: p._id)
     cls.loc = util.make_loc('loc1')
     cls.sp = cls.loc.linked_supply_point()
     cls.users = [util.bootstrap_user(cls, **user_def) for user_def in cls.user_definitions]
コード例 #45
0
    def test_updating_existing_location_properties(self):
        parent = make_loc('sillyparents', type='village')
        existing = make_loc('existingloc', type='outlet', parent=parent)

        data = {
            'id': existing._id,
            'name': existing.name,
            'site_code': 'wat',
            'outlet_type': 'SHG'
        }

        self.assertNotEqual(existing.site_code, data['site_code'])

        loc_id = import_location(self.domain.name, 'outlet',
                                 data).get('id', None)
        new_loc = Location.get(loc_id)

        self.assertEqual(existing._id, loc_id)
        self.assertEqual(new_loc.site_code, data['site_code'])
コード例 #46
0
ファイル: test_locations.py プロジェクト: nnestle/commcare-hq
    def test_commtrack_user_has_multiple_locations(self):
        user = self.user

        loc = make_loc('secondloc')
        sp = make_supply_point(self.domain.name, loc)
        user.add_location_delegate(loc)

        self.check_supply_point(user, sp._id)
        self.assertTrue(len(user.locations), 2)
        self.assertEqual(user.locations[1].name, 'secondloc')
コード例 #47
0
ファイル: handler.py プロジェクト: ekush/commcare-hq
 def setUp(self):
     domain = bootstrap_domain(TEST_DOMAIN)
     loc = make_loc(code="garms",
                    name="Test RMS",
                    type="Regional Medical Store",
                    domain=domain.name)
     self.user = bootstrap_user(username='******',
                                phone_number='323232',
                                domain=domain.name,
                                home_loc=loc)
コード例 #48
0
    def test_location_removal_only_submits_if_it_existed(self):
        user = self.user

        # can't test with the original since the user already owns it
        loc = make_loc('secondloc')

        with patch(
                'corehq.apps.users.models.CommCareUser.submit_location_block'
        ) as submit_blocks:
            user.remove_location_delegate(loc)
            self.assertEqual(submit_blocks.call_count, 0)
コード例 #49
0
    def test_archive_flips_sp_cases(self):
        loc = make_loc('las_mudas', domain=self.domain).sql_location
        sp = loc.linked_supply_point()

        self.assertFalse(sp.closed)
        loc.archive()
        sp = loc.linked_supply_point()
        self.assertTrue(sp.closed)

        loc.unarchive()
        sp = loc.linked_supply_point()
        self.assertFalse(sp.closed)
コード例 #50
0
    def test_archive_flips_sp_cases(self):
        loc = make_loc('someloc').sql_location
        sp = loc.linked_supply_point()

        self.assertFalse(sp.closed)
        loc.archive()
        sp = loc.linked_supply_point()
        self.assertTrue(sp.closed)

        loc.unarchive()
        sp = loc.linked_supply_point()
        self.assertFalse(sp.closed)
コード例 #51
0
ファイル: test_locations.py プロジェクト: ekush/commcare-hq
    def test_archive_flips_sp_cases(self):
        loc = make_loc('someloc')
        sp = make_supply_point(self.domain.name, loc)

        self.assertFalse(sp.closed)
        loc.archive()
        sp = SupplyPointCase.get(sp._id)
        self.assertTrue(sp.closed)

        loc.unarchive()
        sp = SupplyPointCase.get(sp._id)
        self.assertFalse(sp.closed)
コード例 #52
0
    def setUpClass(cls):
        domain = prepare_domain(TEST_DOMAIN)
        p = Product(domain=domain.name, name='Jadelle', code='jd', unit='each')
        p.save()
        p2 = Product(domain=domain.name,
                     name='Male Condom',
                     code='mc',
                     unit='each')
        p2.save()
        p3 = Product(domain=domain.name, name='Lofem', code='lf', unit='each')
        p3.save()
        p4 = Product(domain=domain.name, name='Ng', code='ng', unit='each')
        p4.save()
        p5 = Product(domain=domain.name,
                     name='Micro-G',
                     code='mg',
                     unit='each')
        p5.save()
        loc = make_loc(code="garms",
                       name="Test RMS",
                       type="Regional Medical Store",
                       domain=domain.name)
        test.bootstrap(TEST_BACKEND, to_console=True)
        cls.user1 = bootstrap_user(username='******',
                                   first_name='test1',
                                   last_name='test1',
                                   domain=domain.name,
                                   home_loc=loc)
        cls.user2 = bootstrap_user(username='******',
                                   domain=domain.name,
                                   home_loc=loc,
                                   first_name='test2',
                                   last_name='test2',
                                   phone_number='222222',
                                   user_data={'role': 'In Charge'})

        try:
            XFormInstance.get(docid='test-xform')
        except ResourceNotFound:
            xform = XFormInstance(_id='test-xform')
            xform.save()
        sql_location = loc.sql_location
        sql_location.products = SQLProduct.objects.filter(product_id=p5.get_id)
        sql_location.save()
        config = CommtrackConfig.for_domain(domain.name)
        config.actions.append(
            CommtrackActionConfig(action='receipts',
                                  keyword='rec',
                                  caption='receipts'))
        config.consumption_config = ConsumptionConfig(min_transactions=0,
                                                      min_window=0,
                                                      optimal_window=60)
        config.save()
コード例 #53
0
    def test_given_id_matches_type(self):
        existing = make_loc('existingloc', type='state')

        data = {
            'site_code': existing.site_code,
            'name': 'new_name',
        }

        result = import_location(self.domain.name, 'outlet', data)

        self.assertEqual(result['id'], None)
        self.assertTrue('Existing location type error' in result['message'])
コード例 #54
0
ファイル: test_reminders.py プロジェクト: xbryanc/commcare-hq
    def setUpClass(cls):
        super(TestReminders, cls).setUpClass()
        cls.sms_backend, cls.sms_backend_mapping = setup_default_sms_test_backend()
        domain = prepare_domain(TEST_DOMAIN)
        mohsw = make_loc(code="moh1", name="Test MOHSW 1", type="MOHSW", domain=domain.name)

        msdzone = make_loc(code="msd1", name="MSD Zone 1", type="MSDZONE",
                           domain=domain.name, parent=mohsw)

        region = make_loc(code="reg1", name="Test Region 1", type="REGION",
                          domain=domain.name, parent=msdzone)
        cls.district = make_loc(code="dis1", name="Test District 1", type="DISTRICT",
                                domain=domain.name, parent=region)
        cls.facility = make_loc(code="loc1", name="Test Facility 1", type="FACILITY",
                                domain=domain.name, parent=cls.district)
        cls.facility.metadata['group'] = 'B'
        cls.facility2 = make_loc(code="loc2", name="Test Facility 2", type="FACILITY",
                                 domain=domain.name, parent=cls.district)
        cls.facility2.metadata['group'] = 'C'
        cls.facility.save()
        cls.facility2.save()

        cls.user1 = bootstrap_user(
            cls.facility, username='******', domain=domain.name, home_loc='loc1', phone_number='5551234',
            first_name='test', last_name='Test'
        )
        bootstrap_user(cls.facility2, username='******', domain=domain.name, home_loc='loc2',
                       phone_number='5555678', first_name='test1', last_name='Test')
        bootstrap_user(cls.district, username='******', domain=domain.name, home_loc='dis1', phone_number='555',
                       first_name='test1', last_name='Test')
        bootstrap_user(cls.district, username='******', domain=domain.name, phone_number='111',
                       first_name='MSD', last_name='Person', user_data={'role': 'MSD'})
コード例 #55
0
    def test_should_still_save_if_name_changes(self):
        # name isn't a dynamic property so should test these still
        # get updated alone
        parent = make_loc('sillyparents', type='village')
        existing = make_loc('existingloc', type='outlet', parent=parent)
        existing.site_code = 'wat'
        existing.outlet_type = 'SHG'
        existing.save()

        data = {
            'id': existing._id,
            'name': 'newname',
            'site_code': 'wat',
            'outlet_type': 'SHG',
        }

        with patch('corehq.apps.locations.forms.LocationForm.save') as save:
            result = import_location(self.domain.name, 'outlet', data)
            self.assertEqual(save.call_count, 1)
            # id isn't accurate because of the mock, but want to make
            # sure we didn't actually return with None
            self.assertTrue(result['id'] is not None)
コード例 #56
0
    def test_setting_new_list_causes_submit(self):
        """
        this test mostly exists to make sure the one
        testing no submits doesn't silently stop actually working
        """
        user = self.user

        loc1 = make_loc('secondloc')
        make_supply_point(self.domain.name, loc1)

        with patch('corehq.apps.commtrack.models.CommTrackUser.submit_location_block') as submit_blocks:
            user.set_locations([loc1])
            self.assertEqual(submit_blocks.call_count, 1)
コード例 #57
0
    def test_id_of_invalid_parent_type(self):
        # state can't have outlet as child
        parent = make_loc('sillyparents', type='state')
        data = {'name': 'oops', 'outlet_type': 'SHG', 'parent_id': parent._id}

        original_count = len(list(Location.by_domain(self.domain.name)))

        result = import_location(self.domain.name, 'outlet', data)

        self.assertEqual(result['id'], None)
        self.assertEqual(len(list(Location.by_domain(self.domain.name))),
                         original_count)
        self.assertTrue('Invalid parent type' in result['message'])
コード例 #58
0
 def setUpClass(cls):
     super(HandlerTest, cls).setUpClass()
     cls.domain = 'ews-handler-test'
     bootstrap_domain(cls.domain)
     cls.create_account_and_subscription(cls.domain)
     cls.domain_obj = Domain.get_by_name(cls.domain)
     cls.loc = make_loc(code="garms",
                        name="Test RMS",
                        type="Regional Medical Store",
                        domain=cls.domain)
     cls.user = bootstrap_user(username='******',
                               phone_number='323232',
                               domain=cls.domain,
                               home_loc=cls.loc)
コード例 #59
0
    def test_import_with_existing_parent_by_id(self):
        # state can't have outlet as child
        parent = make_loc('sillyparents', type='state')

        data = {'name': 'importedloc', 'parent_id': parent._id}

        result = import_location(self.domain.name, 'district', data)

        if result['id'] is None:
            self.fail('import failed with error: %s' % result['message'])

        self.assertTrue(data['name'] in self.names_of_locs())
        new_loc = Location.get(result['id'])
        self.assertEqual(new_loc.parent_id, parent._id)
コード例 #60
0
    def test_setting_new_list_causes_submit(self):
        """
        this test mostly exists to make sure the one
        testing no submits doesn't silently stop actually working
        """
        user = self.user

        loc1 = make_loc('secondloc')

        with patch(
                'corehq.apps.users.models.CommCareUser.submit_location_block'
        ) as submit_blocks:
            user.create_location_delegates([loc1])
            self.assertEqual(submit_blocks.call_count, 1)