def test_base_validation(self): base_model_with_invalid_id = self.create_model( base_models.BaseModel, id='123@?!*', deleted=False) base_model_with_invalid_timestamps = self.create_model( base_models.BaseModel, id='124', deleted=False, created_on=self.NOW, last_updated=self.YEAR_LATER) base_model_with_inconsistent_timestamps = self.create_model( base_models.BaseModel, id='125', deleted=False, created_on=self.YEAR_LATER, last_updated=self.YEAR_AGO) expired_base_model = self.create_model( base_models.BaseModel, id='126', deleted=True) valid_base_model = self.create_model( base_models.BaseModel, id='127', deleted=False) self.put_multi([ base_model_with_invalid_id, base_model_with_invalid_timestamps, base_model_with_inconsistent_timestamps, expired_base_model, valid_base_model, ]) self.assert_job_output_is([ base_validation_errors.ModelIdRegexError( base_model_with_invalid_id, base_validation.BASE_MODEL_ID_PATTERN), base_validation_errors.ModelMutatedDuringJobError( base_model_with_invalid_timestamps), base_validation_errors.InconsistentTimestampsError( base_model_with_inconsistent_timestamps), base_validation_errors.ModelExpiredError(expired_base_model), ])
def test_message(self): model = base_models.BaseModel(id='123', deleted=True, created_on=self.YEAR_AGO, last_updated=self.YEAR_AGO) error = base_validation_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_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_validation.ValidateDeletedModel())) self.assert_pcoll_equal(output, [ base_validation_errors.ModelExpiredError(expired_model), ])
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 = job_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 base_validation_errors.ModelExpiredError(model)