def test_validate_all_xml(self): test_folder = TEST_FOLDER / Path("valid_connector") files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.tdd", "dialect"), ConnectorFile("connectionResolver.tdr", "connection-resolver"), ConnectorFile("resources-en_US.xml", "resource") ] self.assertTrue(validate_all_xml(files_list, test_folder), "Valid connector not marked as valid") print("\nTest broken xml. Throws a XML validation error.") test_folder = TEST_FOLDER / Path("broken_xml") files_list = [ConnectorFile("manifest.xml", "manifest")] self.assertFalse(validate_all_xml(files_list, test_folder), "Invalid connector was marked as valid") test_folder = TEST_FOLDER / Path("broken_xml")
def test_warn_defaultSQLDialect_as_base(self): test_dialect_file = TEST_FOLDER / "defaultSQLDialect_as_base/dialect.tdd" file_to_test = ConnectorFile("dialect.tdd", "dialect") with self.assertLogs('packager_logger', level='WARNING') as cm: warn_file_specific_rules(file_to_test, test_dialect_file) self.assertEqual(len(cm.output), 1) self.assertIn('DefaultSQLDialect', cm.output[0], "DefaultSQLDialect not found in warning message")
def test_all_fields_in_normalizer(self): properties = ConnectorProperties() properties.uses_tcd = False properties.connection_fields = [ 'server', 'port', 'v-custom', 'username', 'password', 'v-custom2', 'vendor1', 'vendor2', 'vendor3' ] properties.connection_metadata_database = True xml_violations_buffer = [] print( "Test that normalizer not containing 'dbname' if connection-metadata database field is used is validated" ) file_to_test = ConnectorFile("connectionResolver.xml", "connection-resolver") test_file = TEST_FOLDER / "database_field_not_in_normalizer/connectionResolver.xml" self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "Dbname is optional if unused so connection resolver is valid") print( "Test that normalizer not containing all the fields in connection-fields is invalidated" ) file_to_test = ConnectorFile("connectionResolver.xml", "connection-resolver") test_file = TEST_FOLDER / "mcd_field_not_in_normalizer/connectionResolver.xml" self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "Inferred connection resolver validated when tcd was used") print( "Test that normalizer containing all the fields in connection-fields is validated" ) file_to_test = ConnectorFile("connectionResolver.xml", "connection-resolver") test_file = TEST_FOLDER / "modular_dialog_connector/connectionResolver.xml" self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "Valid connector marked as invalid")
def test_vendor_defined_fields_mcd(self): # This connector uses connection-fields file and does not have vendor-defined fields test_folder = TEST_FOLDER / Path( "mcd_no_vendor_defined_fields") # This connector uses a .tcd file files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connectionFields.xml", "connection-fields"), ConnectorFile("connectionMetadata.xml", "connection-metadata") ] properties_no_vendor_defined_fields = ConnectorProperties() self.assertTrue( validate_all_xml(files_list, test_folder, properties_no_vendor_defined_fields), "Valid connector not marked as valid") self.assertFalse( properties_no_vendor_defined_fields.vendor_defined_fields, "Found vendor-defined fields when none were defined") # This connector uses a connection-fields file and has vendor-defined fields test_folder = TEST_FOLDER / Path("modular_dialog_connector") files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connectionFields.xml", "connection-fields"), ConnectorFile("connectionMetadata.xml", "connection-metadata"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.xml", "dialect"), ConnectorFile("connectionResolver.xml", "connection-resolver"), ConnectorFile("connectionProperties.js", "script") ] properties_has_vendor_defined_fields = ConnectorProperties() self.assertTrue( validate_all_xml(files_list, test_folder, properties_has_vendor_defined_fields), "Valid connector not marked as valid") self.assertListEqual( properties_has_vendor_defined_fields.vendor_defined_fields, ['v-custom', 'v-custom2', 'vendor1', 'vendor2', 'vendor3'], "Vendor-defined attributes not detected")
def test_generate_file_list(self): # Test valid connector expected_class_name = "postgres_odbc" expected_file_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.tdd", "dialect"), ConnectorFile("connectionResolver.tdr", "connection-resolver") ] actual_file_list, actual_class_name = self.parser_test_case( TEST_FOLDER / Path("valid_connector"), expected_file_list, expected_class_name) self.assertTrue(actual_file_list, "Valid connector did not return a file list") self.assertTrue( sorted(actual_file_list) == sorted(expected_file_list), "Actual file list does not match expected for valid connector") self.assertTrue( actual_class_name == expected_class_name, "Actual class name does not match expected for valid connector") # Test invalid connector actual_file_list, actual_class_name = self.parser_test_case( TEST_FOLDER / Path("broken_xml"), expected_file_list, expected_class_name) self.assertFalse( actual_file_list, "Invalid connector returned a file list when it should not have") # Test connector with class name mismatch actual_file_list, actual_class_name = self.parser_test_case( TEST_FOLDER / Path("wrong_class"), expected_file_list, expected_class_name) self.assertFalse( actual_file_list, "Connector with class name mismatch returned a file list when it shouldn't" )
def test_jdk_create_jar(self): files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.tdd", "dialect"), ConnectorFile("connectionResolver.tdr", "connection-resolver"), ConnectorFile("resources-en_US.xml", "resource")] source_dir = TEST_FOLDER / Path("valid_connector") dest_dir = TEST_FOLDER / Path("packaged-connector-by-jdk/") package_name = "test.taco" jdk_create_jar(source_dir, files_list, package_name, dest_dir) path_to_test_file = dest_dir / Path(package_name) self.assertTrue(os.path.isfile(path_to_test_file), "taco file doesn't exist") # test min support tableau version is stamped args = ["jar", "xf", package_name, MANIFEST_FILE_NAME] p = subprocess.Popen(args, cwd=os.path.abspath(dest_dir)) self.assertEqual(p.wait(), 0, "can not extract manfifest file from taco") path_to_extracted_manifest = dest_dir / MANIFEST_FILE_NAME self.assertTrue(os.path.isfile(path_to_extracted_manifest), "extracted manifest file doesn't exist") manifest = ET.parse(path_to_extracted_manifest) self.assertEqual(manifest.getroot().get("min-version-tableau"), __default_min_version_tableau__, "wrong min-version-tableau attr or doesn't exist") if dest_dir.exists(): shutil.rmtree(dest_dir)
def test_validate_single_file(self): test_file = TEST_FOLDER / Path("valid_connector/manifest.xml") file_to_test = ConnectorFile("manifest.xml", "manifest") xml_violations_buffer = [] self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, dummy_properties), "Valid XML file not marked as valid") test_file = TEST_FOLDER / Path("big_manifest/manifest.xml") self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, dummy_properties), "Big XML file marked as valid") print("\nTest broken xml. Throws XML validation error.") test_file = TEST_FOLDER / Path("broken_xml/manifest.xml") self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, dummy_properties), "XML file that doesn't follow schema marked as valid") print("\nTest malformed xml. Throws XML validation error.") test_file = TEST_FOLDER / Path("broken_xml/connectionResolver.tdr") file_to_test = ConnectorFile("connectionResolver.tdr", "connection-resolver") self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, dummy_properties), "Malformed XML file marked as valid") logging.debug("test_validate_single_file xml violations:") for violation in xml_violations_buffer: logging.debug(violation)
def test_warn_authentication_attribute(self): file_to_test = ConnectorFile("connectionResolver.tdr", "connection-resolver") print( "\nTest no warning when authentication attribute is in required attributes list." ) test_tdr_file = TEST_FOLDER / "authentication_attribute/with_authentication.tdr" with self.assertLogs('packager_logger', level='WARNING') as cm: # Log a dummy message so that the log will exist. logging.getLogger('packager_logger').warning('dummy message') warn_file_specific_rules(file_to_test, test_tdr_file) self.assertEqual(len(cm.output), 1) self.assertNotIn( "'authentication' attribute is missing", cm.output[0], "\"'authentication' attribute is missing\" found in warning message" ) print( "Test no warning when required attributes list is not specified.") test_tdr_file = TEST_FOLDER / "authentication_attribute/no_required_attributes_list.tdr" with self.assertLogs('packager_logger', level='WARNING') as cm: # Log a dummy message so that the log will exist. logging.getLogger('packager_logger').warning('dummy message') warn_file_specific_rules(file_to_test, test_tdr_file) self.assertEqual(len(cm.output), 1) self.assertNotIn( "'authentication' attribute is missing", cm.output[0], "\"'authentication' attribute is missing\" found in warning message" ) print( "Test warning when authentication attribute is not in required attributes list." ) test_tdr_file = TEST_FOLDER / "authentication_attribute/without_authentication.tdr" with self.assertLogs('packager_logger', level='WARNING') as cm: warn_file_specific_rules(file_to_test, test_tdr_file) self.assertEqual(len(cm.output), 1) self.assertIn( "'authentication' attribute is missing", cm.output[0], "\"'authentication' attribute is missing\" not found in warning message" )
def test_validate_required_advanced_field_has_default_value(self): test_file = TEST_FOLDER / "modular_dialog_connector/connectionFields.xml" file_to_test = ConnectorFile("connectionFields.xml", "connection-fields") xml_violations_buffer = [] self.assertTrue(validate_single_file(file_to_test, test_file, xml_violations_buffer), "Valid XML file not marked as valid") print("\nTest missing default-value for non-optional advanced field. Throws XML validation error.") test_file = TEST_FOLDER / "advanced_required_missing_default/connectionFields.xml" self.assertFalse(validate_single_file(file_to_test, test_file, xml_violations_buffer), "XML file containing required field in 'advanced' category with no default value marked as valid") logging.debug("test_validate_required_advanced_field_has_default_value xml violations:") for violation in xml_violations_buffer: logging.debug(violation)
def test_validate_duplicate_fields_absent(self): test_file = TEST_FOLDER / "modular_dialog_connector/connectionFields.xml" file_to_test = ConnectorFile("connectionFields.xml", "connection-fields") xml_violations_buffer = [] self.assertTrue(validate_single_file(file_to_test, test_file, xml_violations_buffer), "Valid XML file not marked as valid") print("\nTest duplicate fields not allowed. Throws XML validation error.") test_file = TEST_FOLDER / "duplicate_fields/connectionFields.xml" self.assertFalse(validate_single_file(file_to_test, test_file, xml_violations_buffer), "A field with the field name = server already exists. Cannot have multiple fields with the same name.") logging.debug("test_validate_duplicate_fields_absent xml violations:") for violation in xml_violations_buffer: logging.debug(violation)
def test_validate_vendor_prefix(self): test_file = TEST_FOLDER / "modular_dialog_connector/connectionFields.xml" file_to_test = ConnectorFile("connectionFields.xml", "connection-fields") xml_violations_buffer = [] self.assertTrue(validate_single_file(file_to_test, test_file, xml_violations_buffer), "Valid XML file not marked as valid") print("\nTest malformed xml. Throws XML validation error.") test_file = TEST_FOLDER / "broken_xml/connectionFields.xml" self.assertFalse(validate_single_file(file_to_test, test_file, xml_violations_buffer), "XML file with invalid name values marked as valid") logging.debug("test_validate_vendor_prefix xml violations:") for violation in xml_violations_buffer: logging.debug(violation)
def test_validate_jdbc_properties_builder(self): properties = ConnectorProperties() xml_violations_buffer = [] file_to_test = ConnectorFile("connectionResolver.xml", "connection-resolver") test_file = TEST_FOLDER / "properties_builder/odbc/connectionResolver.xml" print( "Test that a connection resolver without <connection-properties> and non-jdbc superclass is valid" ) properties.is_jdbc = False self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "optional connection-properties not found and marked invalid") print( "Test that a connection resolver without <connection-properties> and jdbc superclass is invalid" ) properties.is_jdbc = True self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "required connection-properties not found and marked valid") test_file = TEST_FOLDER / "properties_builder/jdbc/connectionResolver.xml" print( "Test that a connection resolver with <connection-properties> and non-jdbc superclass is valid" ) properties.is_jdbc = False self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "optional connection-properties found and marked as invalid") print( "Test that a connection resolver with <connection-properties> and jdbc superclass is valid" ) properties.is_jdbc = True self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "required connection-properties found and marked as invalid")
def test_validate_company_name_length(self): xml_violations_buffer = [] file_to_test = ConnectorFile("manifest.xml", "manifest") print("Test that company name with length less than 1 is invalidated") test_file = TEST_FOLDER / "company_name_length_validation/min/manifest.xml" self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, dummy_properties), "Empty company name marked as valid") print( "Test that company name with length greater than 24 is invalidated" ) test_file = TEST_FOLDER / "company_name_length_validation/max/manifest.xml" self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, dummy_properties), "Company name with length greater than 24 marked as valid")
def test_validate_auth_attr_in_connection_fields(self): test_file = TEST_FOLDER / "authentication_attribute/connection_fields_with_authentication.xml" file_to_test = ConnectorFile("connectionFields.xml", "connection-fields") properties = ConnectorProperties() xml_violations_buffer = [] self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "XML Validation failed for valid connection fields file") test_file = TEST_FOLDER / "authentication_attribute/connection_fields_no_authentication.xml" properties = ConnectorProperties() self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "XML Validation passed for connection fields file without authentication field" )
def test_vendor_defined_fields_tcd(self): # This connector uses a .tcd file and does not have vendor-defined fields test_folder = TEST_FOLDER / Path( "valid_connector") # This connector uses a .tcd file files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.tdd", "dialect"), ConnectorFile("connectionResolver.tdr", "connection-resolver"), ConnectorFile("resources-en_US.xml", "resource") ] properties_no_vendor_defined_fields = ConnectorProperties() self.assertTrue( validate_all_xml(files_list, test_folder, properties_no_vendor_defined_fields), "Valid connector not marked as valid") self.assertFalse( properties_no_vendor_defined_fields.vendor_defined_fields, "Found vendor-defined fields when none were defined") # This connector uses a .tcd file and has vendor-defined fields test_folder = TEST_FOLDER / Path("tcd_vendor_defined_fields") files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog") ] properties_has_vendor_defined_fields = ConnectorProperties() self.assertTrue( validate_all_xml(files_list, test_folder, properties_has_vendor_defined_fields), "Valid connector not marked as valid") self.assertListEqual( properties_has_vendor_defined_fields.vendor_defined_fields, ['vendor1', 'vendor2', 'vendor3'], "Vendor-defined attributes not detected")
def test_validate_instanceurl(self): test_file = TEST_FOLDER / "oauth_connector/connectionFields.xml" file_to_test = ConnectorFile("connectionFields.xml", "connection-fields") xml_violations_buffer = [] self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, dummy_properties), "Valid XML file not marked as valid") test_file = TEST_FOLDER / "instanceurl/connectionFields.xml" file_to_test = ConnectorFile("connectionFields.xml", "connection-fields") xml_violations_buffer = [] self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, dummy_properties), "An instanceurl field must be conditional to authentication field with value=oauth" ) # instanceURL should not be required in required-attributes since it's automatically added test_folder = TEST_FOLDER / Path( "oauth_connector" ) # This connector uses a connection-fields.xml file files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connectionFields.xml", "connection-fields"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.xml", "dialect"), ConnectorFile("connectionResolver.xml", "connection-resolver"), ConnectorFile("connectionProperties.js", "script") ] properties_uses_tcd = ConnectorProperties() self.assertTrue( validate_all_xml(files_list, test_folder, properties_uses_tcd), "InstanceURL not in required-attributes is valid")
def test_jdk_create_jar_oauth(self): files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connectionFields.xml", "connection-fields"), ConnectorFile("connectionMetadata.xml", "connection-metadata"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.xml", "dialect"), ConnectorFile("connectionResolver.xml", "connection-resolver"), ConnectorFile("connectionProperties.js", "script"), ConnectorFile("oauth-config.xml", "oauth-config") ] source_dir = TEST_FOLDER / Path("oauth_connector") dest_dir = TEST_FOLDER / Path("packaged-connector-by-jdk/") package_name = "test_oauth.taco" jdk_create_jar(source_dir, files_list, package_name, dest_dir) path_to_test_file = dest_dir / Path(package_name) self.assertTrue(os.path.isfile(path_to_test_file), "taco file doesn't exist") # test min support tableau version is stamped args = ["jar", "xf", package_name, MANIFEST_FILE_NAME] p = subprocess.Popen(args, cwd=os.path.abspath(dest_dir)) self.assertEqual(p.wait(), 0, "can not extract manfifest file from taco") path_to_extracted_manifest = dest_dir / MANIFEST_FILE_NAME self.assertTrue(os.path.isfile(path_to_extracted_manifest), "extracted manifest file doesn't exist") manifest = ET.parse(path_to_extracted_manifest) self.assertEqual(manifest.getroot().get("min-version-tableau"), VERSION_2021_1, "wrong min-version-tableau attr or doesn't exist") if dest_dir.exists(): shutil.rmtree(dest_dir)
def test_inferred_connection_resolver_validation(self): properties = ConnectorProperties() xml_violations_buffer = [] file_to_test = ConnectorFile("connectionResolver.xml", "connection-resolver") test_file = TEST_FOLDER / "inferred_connection_resolver/connectionResolver.xml" print( "Test that connection resolver without connection-normalizer for a connector that uses a .tcd file is invalidated" ) properties.uses_tcd = True self.assertFalse( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "Inferred connection resolver validated when tcd was used") print( "Test that connection resolver with connection-normalizer for a connector that uses a .tcd file is validated" ) properties.uses_tcd = False self.assertTrue( validate_single_file(file_to_test, test_file, xml_violations_buffer, properties), "Valid connector marked as invalid")
def test_create_jar(self): files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.tdd", "dialect"), ConnectorFile("connectionResolver.tdr", "connection-resolver"), ConnectorFile("resources-en_US.xml", "resource")] source_dir = TEST_FOLDER / Path("valid_connector") dest_dir = TEST_FOLDER / Path("packaged-connector/") package_name = "test.taco" create_jar(source_dir, files_list, package_name, dest_dir) path_to_test_file = dest_dir / Path(package_name) self.assertTrue(os.path.isfile(path_to_test_file), "taco file doesn't exist") if dest_dir.exists(): shutil.rmtree(dest_dir)
def test_uses_tcd_property(self): # Check that validate_all_xml properly sets uses_tcd to True if using .tcd file test_folder = TEST_FOLDER / Path( "valid_connector") # This connector uses a .tcd file files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.tdd", "dialect"), ConnectorFile("connectionResolver.tdr", "connection-resolver"), ConnectorFile("resources-en_US.xml", "resource") ] properties_uses_tcd = ConnectorProperties() self.assertTrue( validate_all_xml(files_list, test_folder, properties_uses_tcd), "Valid connector not marked as valid") self.assertTrue( properties_uses_tcd.uses_tcd, "uses_tcd not set to True for connector using .tcd file") # Check that validate_all_xml properly sets uses_tcd to False if not using .tcd file test_folder = TEST_FOLDER / Path( "modular_dialog_connector" ) # This connector uses a connection-fields.xml file files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connectionFields.xml", "connection-fields"), ConnectorFile("connectionMetadata.xml", "connection-metadata"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.xml", "dialect"), ConnectorFile("connectionResolver.xml", "connection-resolver"), ConnectorFile("connectionProperties.js", "script") ] properties_does_not_use_tcd = ConnectorProperties() self.assertTrue( validate_all_xml(files_list, test_folder, properties_does_not_use_tcd), "Valid connector not marked as valid") self.assertFalse( properties_does_not_use_tcd.uses_tcd, "uses_tcd not set to False for connector using .tcd file")
if not dest_dir.exists(): dest_dir.mkdir() logging.debug("Creating destination directory " + str(dest_dir)) with ZipFile(dest_dir / jar_filename, "w") as jar: jar.writestr("META-INF/", "") jar.writestr("META-INF/MANIFEST.MF", Manifest().get_data()) for file in files: logging.debug("Adding " + file.file_name + " to package.") jar.write(os.path.join(abs_source_path, file.file_name), file.file_name) logging.info(jar_filename + " was created in " + str(os.path.abspath(dest_dir))) if __name__ == "__main__": # TODO: Replace all hard coded below input when ready. path_from_args = Path("../../samples/plugins/postgres_odbc") files_to_package = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.tdd", "dialect"), ConnectorFile("connectionResolver.tdr", "connection-resolver") ] jar_dest_path = Path("../jar") jar_name = "postgres_odbc.jar" create_jar(path_from_args, files_to_package, jar_name, jar_dest_path)
def test_connection_metadata_property(self): test_folder = TEST_FOLDER / Path( "modular_dialog_connector" ) # This connector uses a connection-fields.xml file files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connectionFields.xml", "connection-fields"), ConnectorFile("connectionMetadata.xml", "connection-metadata"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.xml", "dialect"), ConnectorFile("connectionResolver.xml", "connection-resolver"), ConnectorFile("connectionProperties.js", "script") ] properties = ConnectorProperties() self.assertTrue(validate_all_xml(files_list, test_folder, properties), "Valid connector not marked as valid") self.assertTrue(properties.connection_metadata_database, "Database metadata not detected") test_folder = TEST_FOLDER / Path( "database_field_not_in_normalizer" ) # This connector uses a connection-fields.xml file files_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connectionFields.xml", "connection-fields"), ConnectorFile("connectionMetadata.xml", "connection-metadata"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.xml", "dialect"), ConnectorFile("connectionResolver.xml", "connection-resolver"), ConnectorFile("connectionProperties.js", "script") ] properties = ConnectorProperties() self.assertTrue(validate_all_xml(files_list, test_folder, properties), "Valid connector not marked as valid") self.assertFalse(properties.connection_metadata_database, "Database metadata detected incorrectly")
def test_generate_file_list(self): # Test valid connector expected_class_name = "postgres_odbc" expected_file_list = [ ConnectorFile("manifest.xml", "manifest"), ConnectorFile("connection-dialog.tcd", "connection-dialog"), ConnectorFile("connectionBuilder.js", "script"), ConnectorFile("dialect.tdd", "dialect"), ConnectorFile("connectionResolver.tdr", "connection-resolver"), ConnectorFile("resources-en_US.xml", "resource") ] actual_file_list, actual_class_name = self.parser_test_case( TEST_FOLDER / Path("valid_connector"), expected_file_list, expected_class_name) self.assertTrue(actual_file_list, "Valid connector did not return a file list") self.assertTrue( sorted(actual_file_list) == sorted(expected_file_list), "Actual file list does not match expected for valid connector") self.assertTrue( actual_class_name == expected_class_name, "Actual class name does not match expected for valid connector") print("\nTest invalid connector. Throws XML validation error.") actual_file_list, actual_class_name = self.parser_test_case( TEST_FOLDER / Path("broken_xml"), expected_file_list, expected_class_name) self.assertFalse( actual_file_list, "Invalid connector returned a file list when it should not have") print( "\nTest connector with class name mismatch. Throws XML validation error." ) actual_file_list, actual_class_name = self.parser_test_case( TEST_FOLDER / Path("wrong_class"), expected_file_list, expected_class_name) self.assertFalse( actual_file_list, "Connector with class name mismatch returned a file list when it shouldn't" ) # Test connector with non-https url actual_file_list, actual_class_name = self.parser_test_case( TEST_FOLDER / Path("non_https"), expected_file_list, expected_class_name) self.assertFalse( actual_file_list, "Connector with non-https urls returned a file list when it shouldn't" ) # Test connector with missing English transaltion actual_file_list, actual_class_name = self.parser_test_case( TEST_FOLDER / Path("missing_english_translation"), expected_file_list, expected_class_name) self.assertFalse( actual_file_list, "Connector with localized strings but without a resources-en_US.xml file returned a file list when it shouldn't" )