예제 #1
0
    def test_get_sqlddl_with_ini(self):
        """
        test if a ddl sql file can be created with the parameters
        of the ini file
        """
        spec = {'name': "table1", 'table_prefix': "STG", 'schema': "STAGING"}
        connection = self._get_engine()

        c = FileInspector(
            cfg_path=get_inipath(),
            file=os.path.join(FILEPATH,
                              (f"{FileInspectorCsvTest.testfile['name']}."
                               f"{FileInspectorCsvTest.testfile['type']}")),
            seperator="|",
            type="csv",
            con=connection)

        c.save_staging_ddl(path=FILEPATH, table_name=spec['name'])

        nfname = f"{spec['schema']}_{spec['table_prefix']}_{spec['name']}"
        modelname = nfname.split('_')[-1]
        modelname = os.path.join(modelname, 'DDL')
        full_path = f"{os.path.join(FILEPATH, modelname, nfname)}.sql"

        self.assertEqual(os.path.exists(full_path), True)
        self._rm(full_path)
예제 #2
0
    def test_get_sqldll_specific_types(self):
        """
        test if ddl can customized with specific types
        """
        spec = {
            'name': "table2",
            'schema': "STAGING",
            'table_prefix': "STG",
        }
        cust_types = {
            "Lat": VARCHAR(length=1000),
            "Lon": VARCHAR(length=1000),
            "Txt": VARCHAR(length=1000),
            "Nam": VARCHAR(length=1000),
            "Add": VARCHAR(length=1000),
            "Job": VARCHAR(length=1000),
        }
        connection = self._get_engine()

        c = FileInspector(
            cfg_path=get_inipath(),
            file=os.path.join(FILEPATH,
                              (f"{FileInspectorCsvTest.testfile['name']}."
                               f"{FileInspectorCsvTest.testfile['type']}")),
            seperator="|",
            type="csv",
            con=connection)

        c.save_staging_ddl(path=FILEPATH,
                           table_name=spec['name'],
                           schema=spec['schema'],
                           dtype=cust_types)

        nfname = f"{spec['schema']}_{spec['table_prefix']}_{spec['name']}"
        modelname = nfname.split('_')[-1]
        modelname = os.path.join(modelname, 'DDL')
        full_path = f"{os.path.join(FILEPATH, modelname, nfname)}.sql"

        self.assertEqual(os.path.exists(full_path), True)
        self._rm(full_path)