def test_model_with_draft_change_list_but_no_last_updated(self): model = user_models.ExplorationUserDataModel( id='123', user_id=self.VALID_USER_ID, exploration_id=self.VALID_EXPLORATION_ID, draft_change_list=self.VALID_DRAFT_CHANGE_LIST, draft_change_list_last_updated=None, created_on=self.NOW, last_updated=self.NOW) output = (self.pipeline | beam.Create([model]) | beam.ParDo( user_validation.ValidateDraftChangeListLastUpdated())) self.assert_pcoll_equal(output, [ user_validation_errors.DraftChangeListLastUpdatedNoneError(model) ])
def test_message(self): draft_change_list = [{ 'cmd': 'edit_exploration_property', 'property_name': 'objective', 'new_value': 'the objective' }] model = user_models.ExplorationUserDataModel( id='123', user_id='test', exploration_id='exploration_id', draft_change_list=draft_change_list, draft_change_list_last_updated=None, created_on=self.YEAR_AGO, last_updated=self.YEAR_AGO) error = ( user_validation_errors.DraftChangeListLastUpdatedNoneError(model)) self.assertEqual( error.message, 'DraftChangeListLastUpdatedNoneError in ExplorationUserDataModel' '(id=\'123\'): draft change list %s exists but draft change list ' 'last updated is None' % draft_change_list)
def process(self, input_model): """Function that checks if last_updated for draft change list is valid. Args: input_model: user_models.ExplorationUserDataModel. Entity to validate. Yields: DraftChangeListLastUpdatedNoneError. Error for models with draft change list but no draft_change_list_last_updated DraftChangeListLastUpdatedInvalidError. Error for models with draft_change_list_last_updated greater than current time. """ model = job_utils.clone_model(input_model) if (model.draft_change_list and not model.draft_change_list_last_updated): yield user_validation_errors.DraftChangeListLastUpdatedNoneError( model) current_time = datetime.datetime.utcnow() if (model.draft_change_list_last_updated and model.draft_change_list_last_updated > current_time): yield user_validation_errors.DraftChangeListLastUpdatedInvalidError( model)