Exemple #1
0
 def test_model_with_draft_change_list_last_updated_greater_than_now(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=(self.NOW +
                                         datetime.timedelta(days=5)),
         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.DraftChangeListLastUpdatedInvalidError(
             model)
     ])
    def test_message(self):
        draft_change_list = [{
            'cmd': 'edit_exploration_property',
            'property_name': 'objective',
            'new_value': 'the objective'
        }]
        last_updated = self.NOW + datetime.timedelta(days=5)
        model = user_models.ExplorationUserDataModel(
            id='123',
            user_id='test',
            exploration_id='exploration_id',
            draft_change_list=draft_change_list,
            draft_change_list_last_updated=last_updated,
            created_on=self.YEAR_AGO,
            last_updated=self.NOW)
        error = (user_validation_errors.DraftChangeListLastUpdatedInvalidError(
            model))

        self.assertEqual(
            error.message, 'DraftChangeListLastUpdatedInvalidError in '
            'ExplorationUserDataModel(id=\'123\'): draft change list last '
            'updated %s is greater than the time when job was run' %
            last_updated)
    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)