Пример #1
0
    def _to_model_class(self):
        """Returns the model class associated with this instance.

        Returns:
            type(BaseModel). The model type.
        """
        return job_utils.get_model_class(self._model_kind)
Пример #2
0
    def get_model_kind_references(cls, model_kind, property_name):
        """Returns the kinds of models referenced by the given property.

        Args:
            model_kind: str. The kind of model the property belongs to.
            property_name: str. The property's name.

        Returns:
            list(str). The kinds of models referenced by the given property.
        """
        model_cls = job_utils.get_model_class(model_kind)
        prop = model_property.ModelProperty(model_cls,
                                            getattr(model_cls, property_name))
        return cls._ID_REFERENCING_PROPERTIES.get(prop, set())
Пример #3
0
 def test_get_from_non_existing_model(self):
     with self.assertRaisesRegexp(Exception, 'No model class found'):
         job_utils.get_model_class('InvalidModel')
Пример #4
0
 def test_get_from_existing_model(self):
     self.assertIs(
         job_utils.get_model_class('BaseModel'), base_models.BaseModel)
Пример #5
0
 def test_get_from_non_existing_model(self) -> None:
     with self.assertRaisesRegexp(
             Exception,
             'No model class found'):  # type: ignore[no-untyped-call]
         job_utils.get_model_class('InvalidModel')