コード例 #1
0
    def test_clone_model(self):
        model = base_models.BaseModel(id='123', deleted=True)
        clone = jobs_utils.clone_model(model)

        self.assertEqual(model.id, clone.id)
        self.assertEqual(model, clone)
        self.assertIsNot(model, clone)
        self.assertIsInstance(clone, base_models.BaseModel)
コード例 #2
0
    def test_clone_with_changes(self):
        model = base_models.BaseModel(id='123', deleted=True)
        clone = jobs_utils.clone_model(model, deleted=False)

        self.assertNotEqual(model, clone)
        self.assertIsNot(model, clone)
        self.assertIsInstance(clone, base_models.BaseModel)
        self.assertTrue(model.deleted)
        self.assertFalse(clone.deleted)
コード例 #3
0
ファイル: jobs_utils_test.py プロジェクト: isarojgupta/oppia
    def test_clone_sub_class_with_changes(self):
        model = FooModel(id='123', prop='original')
        clone = jobs_utils.clone_model(model, prop='updated')

        self.assertNotEqual(model, clone)
        self.assertIsNot(model, clone)
        self.assertIsInstance(clone, FooModel)
        self.assertEqual(model.prop, 'original')
        self.assertEqual(clone.prop, 'updated')
コード例 #4
0
ファイル: jobs_utils_test.py プロジェクト: isarojgupta/oppia
    def test_clone_with_changes_to_id(self):
        model = base_models.BaseModel(id='123')
        clone = jobs_utils.clone_model(model, id='124')

        self.assertNotEqual(model, clone)
        self.assertIsNot(model, clone)
        self.assertIsInstance(clone, base_models.BaseModel)
        self.assertEqual(model.id, '123')
        self.assertEqual(clone.id, '124')
コード例 #5
0
    def test_clone_sub_class_with_changes(self):
        class DerivedModel(base_models.BaseModel):
            """Simple model with an extra 'field' string property."""

            field = datastore_services.StringProperty()

        model = DerivedModel(id='123', field='original')
        clone = jobs_utils.clone_model(model, field='updated')

        self.assertNotEqual(model, clone)
        self.assertIsNot(model, clone)
        self.assertIsInstance(clone, DerivedModel)
        self.assertEqual(model.field, 'original')
        self.assertEqual(clone.field, 'updated')
コード例 #6
0
    def process(self, input_model, regex_string):
        """Function that defines how to process each element in a pipeline of
        models.

        Args:
            input_model: datastore_services.Model. Entity to validate.
            regex_string: str. Regex pattern for valid ids to match.

        Yields:
            InvalidIdError. An error class for models with invalid IDs.
        """
        model = jobs_utils.clone_model(input_model)

        if not re.match(regex_string, model.id):
            yield errors.InvalidIdError(model, regex_string)
コード例 #7
0
    def process(self, input_model):
        """Function that defines how to process each element in a pipeline of
        models.

        Args:
            input_model: datastore_services.Model. Entity to validate.

        Yields:
            ModelIdRegexError. An error class for models with invalid IDs.
        """
        model = jobs_utils.clone_model(input_model)
        regex = self.MODEL_ID_REGEX

        if not regex.match(model.id):
            yield audit_errors.ModelIdRegexError(model, regex.pattern)
コード例 #8
0
ファイル: base_model_validator.py プロジェクト: jcqli/oppia
    def process(self, input_model):
        """Function validates that post_commit_is_private is true iff
        post_commit_status is private

        Args:
            input_model: base_models.BaseCommitLogEntryModel.
                Entity to validate.

        Yields:
            ModelInvalidCommitStatus. Error for commit_type validation.
        """
        model = jobs_utils.clone_model(input_model)
        expected_post_commit_is_private = (
            model.post_commit_status == feconf.POST_COMMIT_STATUS_PRIVATE)
        if model.post_commit_is_private != expected_post_commit_is_private:
            yield errors.ModelInvalidCommitStatusError(model)
コード例 #9
0
    def process(self, input_model):
        """Yields audit errors that are discovered in the input model.

        Args:
            input_model: datastore_services.Model. Entity to validate.

        Yields:
            ModelExpiredError. An error class for expired models.
        """
        model = jobs_utils.clone_model(input_model)

        expiration_date = (
            datetime.datetime.utcnow() -
            feconf.PERIOD_TO_HARD_DELETE_MODELS_MARKED_AS_DELETED)

        if model.last_updated < expiration_date:
            yield audit_errors.ModelExpiredError(model)
コード例 #10
0
    def process(self, input_model):
        """Function that defines how to process each element in a pipeline of
        models.

        Args:
            input_model: datastore_services.Model. Entity to validate.

        Yields:
            ModelExpiredError. An error class for expired models.
        """
        model = jobs_utils.clone_model(input_model)

        expiration_date = (
            datetime.datetime.utcnow() -
            feconf.PERIOD_TO_HARD_DELETE_MODELS_MARKED_AS_DELETED)

        if model.last_updated < expiration_date:
            yield errors.ModelExpiredError(model)
コード例 #11
0
    def process(self, input_model):
        """Function that defines how to process each element in a pipeline of
        models.

        Args:
            input_model: datastore_services.Model. Entity to validate.

        Yields:
            ModelMutatedDuringJobError. Error for timestamp validation.
            ModelTimestampRelationshipError. Error for timestamp validation.
        """
        model = jobs_utils.clone_model(input_model)
        if model.created_on > (model.last_updated + MAX_CLOCK_SKEW_SECS):
            yield errors.ModelTimestampRelationshipError(model)

        current_datetime = datetime.datetime.utcnow()
        if (model.last_updated - MAX_CLOCK_SKEW_SECS) > current_datetime:
            yield errors.ModelMutatedDuringJobError(model)
コード例 #12
0
 def test_hashable(self):
     set_of_errors = {
         FooError(self.model),
         FooError(jobs_utils.clone_model(self.model)),
     }
     self.assertEqual(len(set_of_errors), 1)
コード例 #13
0
 def test_equality_between_same_types_and_different_values(self):
     self.assertNotEqual(
         FooError(self.model),
         FooError(jobs_utils.clone_model(self.model, id='987')))
コード例 #14
0
 def test_equality_between_same_types_and_same_values(self):
     self.assertEqual(FooError(self.model),
                      FooError(jobs_utils.clone_model(self.model)))