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, dummy_properties), "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, dummy_properties), "Invalid connector was marked as valid")
def test_connector_fields_property(self): # Check that we correctly populate the connection fields property expected_connection_fields = [ 'server', 'port', 'v-custom', 'authentication', 'username', 'password', 'v-custom2', 'vendor1', 'vendor2', 'vendor3' ] 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.assertEqual( expected_connection_fields, properties.connection_fields, "Actual properties.connection_fields did not match expected")
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")
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_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_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")