示例#1
0
    def test_base_model_validator_ptransform(self):
        with pipeline.TestPipeline(runner=direct_runner.DirectRunner()) as p:
            invalid_id = MockModel(id='123@?!*',
                                   deleted=False,
                                   created_on=self.year_ago,
                                   last_updated=self.now)
            invalid_timestamp = MockModel(id='124',
                                          deleted=False,
                                          created_on=self.now,
                                          last_updated=self.year_later)
            expired_model = MockModel(id='125',
                                      deleted=True,
                                      created_on=self.year_ago,
                                      last_updated=self.year_ago)
            valid_model = MockModel(id='126',
                                    deleted=False,
                                    created_on=self.year_ago,
                                    last_updated=self.now)
            pcoll = (p
                     | beam.Create([
                         invalid_id, invalid_timestamp, expired_model,
                         valid_model
                     ]))

            output = pcoll | base_model_validator.BaseModelValidator()

            beam_testing_util.assert_that(
                output,
                beam_testing_util.equal_to([
                    errors.ModelInvalidIdError(invalid_id),
                    errors.ModelMutatedDuringJobError(invalid_timestamp),
                    errors.ModelExpiredError(expired_model)
                ]))
示例#2
0
    def test_base_model_validator_ptransform(self):
        model_with_invalid_id = base_models.BaseModel(id='123@?!*',
                                                      deleted=False,
                                                      created_on=self.YEAR_AGO,
                                                      last_updated=self.NOW)
        model_with_invalid_timestamp = base_models.BaseModel(
            id='124',
            deleted=False,
            created_on=self.NOW,
            last_updated=self.YEAR_LATER)
        expired_model = base_models.BaseModel(id='125',
                                              deleted=True,
                                              created_on=self.YEAR_AGO,
                                              last_updated=self.YEAR_AGO)
        valid_model = base_models.BaseModel(id='126',
                                            deleted=False,
                                            created_on=self.YEAR_AGO,
                                            last_updated=self.NOW)

        output = (self.pipeline
                  | beam.Create([
                      model_with_invalid_id,
                      model_with_invalid_timestamp,
                      expired_model,
                      valid_model,
                  ])
                  | base_model_validator.BaseModelValidator())

        self.assert_pcoll_equal(output, [
            errors.InvalidIdError(
                model_with_invalid_id,
                base_model_validator.DEFAULT_ID_REGEX_STRING),
            errors.ModelMutatedDuringJobError(model_with_invalid_timestamp),
            errors.ModelExpiredError(expired_model),
        ])
    def test_message(self):
        model = base_models.BaseModel(id='123',
                                      deleted=True,
                                      created_on=self.YEAR_AGO,
                                      last_updated=self.YEAR_AGO)
        error = errors.ModelExpiredError(model)

        self.assertEqual(
            error.message,
            'ModelExpiredError in BaseModel(id="123"): deleted=True when older '
            'than %d days' %
            (feconf.PERIOD_TO_HARD_DELETE_MODELS_MARKED_AS_DELETED.days))
    def test_model_expired_error(self):
        model = MockModel(id='123',
                          deleted=True,
                          created_on=self.year_ago,
                          last_updated=self.year_ago)

        error = errors.ModelExpiredError(model)

        days = cron_services.PERIOD_TO_HARD_DELETE_MODELS_MARKED_AS_DELETED.days
        msg = ('Entity id %s: Model marked as deleted is older than %s days' %
               (model.id, days))

        self.assertEqual(error.message, msg)
示例#5
0
    def test_process_reports_error_for_old_deleted_model(self):
        expired_model = base_models.BaseModel(id='123',
                                              deleted=True,
                                              created_on=self.YEAR_AGO,
                                              last_updated=self.YEAR_AGO)

        output = (self.pipeline
                  | beam.Create([expired_model])
                  | beam.ParDo(base_model_validator.ValidateDeletedModel()))

        self.assert_pcoll_equal(output, [
            errors.ModelExpiredError(expired_model),
        ])
示例#6
0
    def test_process_reports_error_for_old_deleted_model(self):
        with pipeline.TestPipeline(runner=direct_runner.DirectRunner()) as p:
            expired_model = MockModel(id='123',
                                      deleted=True,
                                      created_on=self.year_ago,
                                      last_updated=self.year_ago)
            pcoll = p | beam.Create([expired_model])

            output = (pcoll
                      | beam.ParDo(base_model_validator.ValidateDeleted()))

            beam_testing_util.assert_that(
                output,
                beam_testing_util.equal_to(
                    [errors.ModelExpiredError(expired_model)]))
示例#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:
            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)
 def test_eq_when_classes_are_different(self):
     self.assertEqual(
         errors.ModelInvalidIdError(self.model).__eq__(
             errors.ModelExpiredError(self.model)), NotImplemented)