예제 #1
0
    def _validate_customization_arg_specs(self, 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'], basestring))
            self.assertTrue(self._is_alphanumeric_string(ca_spec['name']))
            self.assertTrue(isinstance(ca_spec['description'], basestring))
            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':
                obj_class = obj_services.Registry.get_object_class_by_type(
                    ca_spec['schema']['obj_type'])
                self.assertEqual(ca_spec['default_value'],
                                 obj_class.normalize(ca_spec['default_value']))
예제 #2
0
    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.assertTrue(isinstance(ca_spec.name, python_utils.BASESTRING))
            self.assertTrue(self._is_alphanumeric_string(ca_spec.name))
            self.assertTrue(
                isinstance(ca_spec.description, python_utils.BASESTRING))
            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))
예제 #3
0
    def _validate_customization_arg_specs(self, 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'], basestring))
            self.assertTrue(self._is_alphanumeric_string(ca_spec['name']))
            self.assertTrue(isinstance(ca_spec['description'], basestring))
            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':
                obj_class = obj_services.Registry.get_object_class_by_type(
                    ca_spec['schema']['obj_type'])
                self.assertIsNotNone(obj_class.edit_html_filename)
                self.assertIsNotNone(obj_class.edit_js_filename)
                self.assertEqual(
                    ca_spec['default_value'],
                    obj_class.normalize(ca_spec['default_value']))
예제 #4
0
    def _validate_customization_arg_specs(self, customization_args):
        """Validates the customization arg specs for the interaction.

        Args:
            customization_args: list(dict(str, *)). The customization args for
                the interaction.
        """
        for ca_spec in customization_args:
            self.assertEqual(set(ca_spec.keys()), set([
                'name', 'description', 'schema', 'default_value']))

            self.assertTrue(
                isinstance(ca_spec['name'], python_utils.BASESTRING))
            self.assertTrue(self._is_alphanumeric_string(ca_spec['name']))
            self.assertTrue(
                isinstance(ca_spec['description'], python_utils.BASESTRING))
            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 = obj_services.Registry.get_object_class_by_type(
                    ca_spec['schema']['obj_type'])
                self.assertEqual(
                    ca_spec['default_value'],
                    obj_class.normalize(ca_spec['default_value']))
예제 #5
0
    def test_config_property_schemas_are_valid(self):
        # This is the total number of config and computed properties.
        self.assertEqual(len(config_domain.Registry._config_registry), 22)

        for property_name in config_domain.Registry._config_registry:
            schema = config_domain.Registry.get_config_property(
                property_name).schema
            schema_utils_test.validate_schema(schema)
예제 #6
0
    def test_config_property_schemas_are_valid(self):
        # This is the total number of config and computed properties.
        self.assertEqual(len(config_domain.Registry._config_registry), 16)

        for property_name in config_domain.Registry._config_registry:
            schema = config_domain.Registry.get_config_property(
                property_name).schema
            schema_utils_test.validate_schema(schema)
예제 #7
0
    def test_schemas_used_to_define_objects_are_valid(self):
        count = 0
        for _, member in inspect.getmembers(objects):
            if inspect.isclass(member):
                if hasattr(member, 'SCHEMA'):
                    schema_utils_test.validate_schema(member.SCHEMA)
                    count += 1

        self.assertEqual(count, 50)
예제 #8
0
    def test_schemas_used_to_define_objects_are_valid(self):
        count = 0
        for _, member in inspect.getmembers(objects):
            if inspect.isclass(member):
                if hasattr(member, 'SCHEMA'):
                    schema_utils_test.validate_schema(member.SCHEMA)
                    count += 1

        self.assertEquals(count, 28)
예제 #9
0
    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, 54)
예제 #10
0
    def _validate_customization_arg_specs(self, customization_arg_specs):
        """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'], python_utils.BASESTRING))
            self.assertTrue(self._is_alphanumeric_string(ca_spec['name']))
            self.assertTrue(
                isinstance(ca_spec['description'], python_utils.BASESTRING))
            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(
                            ca_spec['schema']['obj_type']))
                    self.assertEqual(
                        ca_spec['default_value'],
                        obj_class.normalize(ca_spec['default_value']))
예제 #11
0
    def _validate_customization_arg_specs(self, customization_args):
        for ca_spec in customization_args:
            self.assertEqual(
                set(ca_spec.keys()),
                set(['name', 'description', 'schema', 'default_value']))

            self.assertTrue(isinstance(ca_spec['name'], basestring))
            self.assertTrue(self._is_alphanumeric_string(ca_spec['name']))
            self.assertTrue(isinstance(ca_spec['description'], basestring))
            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 = obj_services.Registry.get_object_class_by_type(
                    ca_spec['schema']['obj_type'])
                self.assertEqual(ca_spec['default_value'],
                                 obj_class.normalize(ca_spec['default_value']))
예제 #12
0
    def _validate_customization_arg_specs(self, customization_args):
        for ca_spec in customization_args:
            self.assertEqual(set(ca_spec.keys()), set([
                'name', 'description', 'schema', 'default_value']))

            self.assertTrue(isinstance(ca_spec['name'], basestring))
            self.assertTrue(self._is_alphanumeric_string(ca_spec['name']))
            self.assertTrue(isinstance(ca_spec['description'], basestring))
            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 = obj_services.Registry.get_object_class_by_type(
                    ca_spec['schema']['obj_type'])
                self.assertIsNotNone(obj_class.edit_html_filename)
                self.assertIsNotNone(obj_class.edit_js_filename)
                self.assertEqual(
                    ca_spec['default_value'],
                    obj_class.normalize(ca_spec['default_value']))
예제 #13
0
 def test_config_property_schemas_are_valid(self):
     for property_name in config_domain.Registry._config_registry:  # pylint: disable=protected-access
         schema = config_domain.Registry.get_config_property(
             property_name).schema
         schema_utils_test.validate_schema(schema)
예제 #14
0
 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)
예제 #15
0
 def test_config_property_schemas_are_valid(self):
     for property_name in config_domain.Registry._config_registry:
         schema = config_domain.Registry.get_config_property(
             property_name).schema
         schema_utils_test.validate_schema(schema)
예제 #16
0
 def test_config_property_schemas_are_valid(self):
     for property_name in config_domain.Registry._config_registry:  # pylint: disable=protected-access
         schema = config_domain.Registry.get_config_property(
             property_name).schema
         schema_utils_test.validate_schema(schema)