def test_message(self): model = user_models.UserQueryModel(id='test', submitter_id='submitter', created_on=self.YEAR_AGO, last_updated=self.YEAR_AGO) error = user_validation_errors.ModelExpiringError(model) self.assertEqual( error.message, 'ModelExpiringError in UserQueryModel(id=\'test\'): mark model ' 'as deleted when older than %s days' % (feconf.PERIOD_TO_MARK_MODELS_AS_DELETED.days))
def test_model_not_marked_as_deleted_when_older_than_4_weeks(self): model = user_models.UserQueryModel( id=self.VALID_USER_ID, submitter_id=self.SUBMITTER_ID, created_on=self.NOW - datetime.timedelta(weeks=5), last_updated=self.NOW - datetime.timedelta(weeks=5)) output = (self.pipeline | beam.Create([model]) | beam.ParDo( user_validation.ValidateOldModelsMarkedDeleted())) self.assert_pcoll_equal( output, [user_validation_errors.ModelExpiringError(model)])
def process(self, input_model): """Function that checks if a model is old enough to mark them deleted. Args: input_model: user_models.UserQueryModel. Entity to validate. Yields: ModelExpiringError. An error class for expiring models. """ model = job_utils.clone_model(input_model) expiration_date = (datetime.datetime.utcnow() - feconf.PERIOD_TO_MARK_MODELS_AS_DELETED) if expiration_date > model.last_updated: yield user_validation_errors.ModelExpiringError(model)