def _validate_customization_arg_specs(self, customization_args): """Validates the customization arg specs for the interaction. Args: customization_args: list(CustomizationArgSpec). The customization args for the interaction. """ for ca_spec in customization_args: self.assertTrue( all( hasattr(ca_spec, attr) for attr in ['name', 'description', 'schema', 'default_value'])) self.assertIsInstance(ca_spec.name, str) self.assertTrue(self._is_alphanumeric_string(ca_spec.name)) self.assertIsInstance(ca_spec.description, str) self.assertGreater(len(ca_spec.description), 0) schema_utils_test.validate_schema(ca_spec.schema) self.assertEqual( ca_spec.default_value, schema_utils.normalize_against_schema(ca_spec.default_value, ca_spec.schema)) if ca_spec.schema['type'] == 'custom': obj_class = object_registry.Registry.get_object_class_by_type( ca_spec.schema['obj_type']) self.assertEqual(ca_spec.default_value, obj_class.normalize(ca_spec.default_value))
def test_config_property_schemas_are_valid(self) -> None: for property_name in ( config_domain.Registry.get_all_config_property_names()): config_property = config_domain.Registry.get_config_property( property_name) # Ruling out the possibility of None for mypy type checking. assert config_property is not None schema_utils_test.validate_schema(config_property.schema) schemas = config_domain.Registry.get_config_property_schemas() for property_name in ( config_domain.Registry.get_all_config_property_names()): schema_utils_test.validate_schema(schemas[property_name]['schema'])
def test_schemas_used_to_define_objects_are_valid(self): count = 0 for name, member in inspect.getmembers(objects): if inspect.isclass(member): # Since BaseTranslatableObject acts as an interface, it will # throw an NotImplementedError exception on get_schema(). if name == 'BaseTranslatableObject': continue if hasattr(member, 'get_schema'): schema_utils_test.validate_schema(member.get_schema()) count += 1 self.assertEqual(count, 53)
def _validate_customization_arg_specs( self, customization_arg_specs: List[ rte_component_registry.CustomizationArgSpecDict ] ) -> None: """Validates the given customization arg specs.""" for ca_spec in customization_arg_specs: self.assertEqual(set(ca_spec.keys()), set([ 'name', 'description', 'schema', 'default_value'])) self.assertTrue( isinstance(ca_spec['name'], str)) self.assertTrue(self._is_alphanumeric_string(ca_spec['name'])) self.assertTrue( isinstance(ca_spec['description'], str)) self.assertGreater(len(ca_spec['description']), 0) # The default value might not pass validation checks (e.g. the # Image component has a required field whose default value is # empty). Thus, when checking the default value schema, we don't # apply the custom validators. schema_utils_test.validate_schema(ca_spec['schema']) self.assertEqual( ca_spec['default_value'], schema_utils.normalize_against_schema( ca_spec['default_value'], ca_spec['schema'], apply_custom_validators=False)) if ca_spec['schema']['type'] == 'custom': # Default value of SanitizedUrl obj_type may be empty. The empty # string is not considered valid for this object, so we don't # attempt to normalize it. if ca_spec['schema']['obj_type'] == 'SanitizedUrl': self.assertEqual(ca_spec['default_value'], '') else: obj_class = ( object_registry.Registry.get_object_class_by_type( # type: ignore[no-untyped-call] ca_spec['schema']['obj_type'])) self.assertEqual( ca_spec['default_value'], obj_class.normalize(ca_spec['default_value']))
def test_config_property_schemas_are_valid(self): for property_name in ( config_domain.Registry.get_all_config_property_names()): schema = config_domain.Registry.get_config_property( property_name).schema schema_utils_test.validate_schema(schema)