def _testVolWithExistingLocations(self, site, address):

        db = current.db
        s3db = current.s3db
        gtable = s3db.gis_location

        # Create a Person
        ptable = s3db.pr_person
        record = Storage(first_name = "Test",
                         last_name = "Person",
                         )
        person_id = ptable.insert(**record)
        self.assertNotEqual(person_id, None)
        record["id"] = person_id
        s3db.update_super(ptable, record)
        s3db.onaccept(ptable, record, method="create")
        pe_id = record["pe_id"]

        if address:
            # Create an Address Location
            record = Storage(name = "Test Address Location",
                             )
            address_location_id = gtable.insert(**record)
            self.assertNotEqual(address_location_id, None)
            record["id"] = address_location_id
            #s3db.update_super(gtable, record)
            s3db.onaccept(gtable, record, method="create")

            # Give them a Home Address with that Location
            atable = s3db.pr_address
            record = Storage(pe_id = pe_id,
                             type = 1,
                             location_id = address_location_id,
                             )
            address_id = atable.insert(**record)
            self.assertNotEqual(address_id, None)
            record["id"] = address_id
            #s3db.update_super(atable, record)
            s3db.onaccept(atable, record, method="create")
        else:
            address_location_id = None

        if site:
            # Create a Site Location
            record = Storage(name = "Test Site Location",
                             )
            site_location_id = gtable.insert(**record)
            self.assertNotEqual(site_location_id, None)
            record["id"] = site_location_id
            #s3db.update_super(gtable, record)
            s3db.onaccept(gtable, record, method="create")

            # Create a Site with that Location
            otable = s3db.org_office
            record = Storage(name = "Test Office",
                             location_id = site_location_id,
                             )
            office_id = otable.insert(**record)
            self.assertNotEqual(office_id, None)
            record["id"] = office_id
            s3db.update_super(otable, record)
            s3db.onaccept(otable, record, method="create")
            site_id = record["site_id"]
        else:
            site_location_id = site_id = None

        # Make them a Volunteer
        htable = s3db.hrm_human_resource
        record = Storage(person_id = person_id,
                         type = 2,
                         site_id = site_id
                         )
        human_resource_id = htable.insert(**record)
        self.assertNotEqual(human_resource_id, None)
        record["id"] = human_resource_id
        s3db.update_super(htable, record)
        s3db.onaccept(htable, record, method="create")

        # Test that the HR location is set correctly
        row = db(htable.id == human_resource_id).select(htable.location_id,
                                                        limitby=(0, 1)).first()

        self.assertNotEqual(row, None)
        return row, address_location_id, site_location_id

    # -------------------------------------------------------------------------
Test a New Volunteer with existing Site &/or Home Address
dataset/ETHPy150Open sahana/eden/modules/unit_tests/s3db/hrm.py/LocationSettingTests._testVolWithExistingLocations