示例#1
0
    def test_v3migration_003_generate_lookup_files(self):
        """Test the generation of node lookup files."""

        with open(os.path.join(self.pkg, 'v3data', 'rm_configs.json'),
                  "rb") as conf:
            data = json.loads(conf.read())

        data["Activity"]["v3_entitytypeid"] = "ACTIVITY.E7"
        data["Actor"]["v3_entitytypeid"] = "ACTOR.E39"
        data["Historic District"][
            "v3_entitytypeid"] = "HERITAGE_RESOURCE_GROUP.E27"
        data["Historic Event"]["v3_entitytypeid"] = "HISTORICAL_EVENT.E5"
        data["Historic Resource"]["v3_entitytypeid"] = "HERITAGE_RESOURCE.E18"
        data["Information Resource"][
            "v3_entitytypeid"] = "INFORMATION_RESOURCE.E73"

        with open(os.path.join(self.pkg, 'v3data', 'rm_configs.json'),
                  "wb") as conf:
            json.dump(data, conf, indent=4, sort_keys=True)

        # copy the v3 graph data into the dummy package, then delete the
        # existing node lookups. this mimics a user action of manually adding
        # the CSV files.
        shutil.rmtree(os.path.join(self.pkg, 'v3data', 'graph_data'))
        shutil.copytree(os.path.join(self.pkg_fixture, 'v3data', 'graph_data'),
                        os.path.join(self.pkg, 'v3data', 'graph_data'))
        node_lookups = glob(
            os.path.join(self.pkg, 'v3data', 'graph_data', '*_v4_lookup.csv'))
        for f in node_lookups:
            os.remove(f)

        # generate the lookup files. the fact that the are created is tested here,
        # not their content.
        management.call_command('v3',
                                'generate-lookups',
                                target=self.pkg,
                                overwrite=True)

        for f in node_lookups:
            self.assertTrue(os.path.isfile(f))

        # copy the filled out fixture lookup files into the package. This
        # mimics a user manually filling out all of the node name matches
        # between v3 resource graphs and v4 resource models.
        shutil.rmtree(os.path.join(self.pkg, 'v3data', 'graph_data'))
        shutil.copytree(os.path.join(self.pkg_fixture, 'v3data', 'graph_data'),
                        os.path.join(self.pkg, 'v3data', 'graph_data'))

        # run the test-lookups cli command. this tests the command, but NOT
        # the actual configs. that is done in the next section.
        management.call_command(
            'v3',
            'test-lookups',
            target=self.pkg,
        )

        # now run the function that is used to test the filled out resource
        # configs. This actually tests the configs.
        errors = v3utils.test_rm_configs(os.path.join(self.pkg, 'v3data'))
        self.assertEqual(len(errors), 0)
示例#2
0
    def test_lookups(self, package_dir):

        v3_data_dir = os.path.join(package_dir, "v3data")
        errors = v3utils.test_rm_configs(v3_data_dir)
        if len(errors) > 0:
            print "FAIL"
            for e in errors:
                print e
            exit()

        print "PASS"