def test_ne_when_classes_are_same(self):
        model_two = MockModel(id='123',
                              created_on=self.year_ago,
                              last_updated=self.now)

        self.assertFalse(
            errors.ModelInvalidIdError(self.model).__ne__(
                errors.ModelInvalidIdError(model_two)))
Пример #2
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)
                ]))
    def test_model_invalid_id_error(self):
        model = MockModel(id='123@?!*',
                          created_on=self.year_ago,
                          last_updated=self.now)
        error = errors.ModelInvalidIdError(model)

        msg = ('Entity id %s: Entity id does not match regex pattern' %
               (model.id))

        self.assertEqual(error.message, msg)
Пример #4
0
    def test_validate_model_id(self):
        with pipeline.TestPipeline(runner=direct_runner.DirectRunner()) as p:
            invalid_id_model = MockModel(id='123@?!*',
                                         created_on=self.year_ago,
                                         last_updated=self.now)
            pcoll = p | beam.Create([invalid_id_model])

            output = (pcoll
                      | beam.ParDo(
                          base_model_validator.ValidateModelIdWithRegex(),
                          '^[A-Za-z0-9-_]{1,%s}$' % base_models.ID_LENGTH))

            beam_testing_util.assert_that(
                output,
                beam_testing_util.equal_to(
                    [errors.ModelInvalidIdError(invalid_id_model)]))
Пример #5
0
    def process(self, input_model, regex_string):
        """Function that defines how to process each element in a pipeline of
        models.

        Args:
            input_model: datastore_services.Model. Entity to validate.
            regex_string: str. Regex pattern for valid ids to match.

        Yields:
            ModelInvalidIdError. An error class for models with invalid IDs.
        """
        regex = re.compile(regex_string)
        model = jobs_utils.clone_model(input_model)

        if not regex.match(model.id):
            yield errors.ModelInvalidIdError(model)
 def test_hash(self):
     test_err = errors.ModelInvalidIdError(self.model)
     expected_hash = hash(
         (test_err.__class__, test_err.key, test_err.message))
     self.assertEqual(test_err.__hash__(), expected_hash)
 def test_eq_when_classes_are_different(self):
     self.assertEqual(
         errors.ModelInvalidIdError(self.model).__eq__(
             errors.ModelExpiredError(self.model)), NotImplemented)
 def test_repr_returns_key(self):
     self.assertEqual(
         errors.ModelInvalidIdError(self.model).__repr__(),
         'ModelInvalidIdError: '
         'Entity id 123: Entity id does not match regex pattern')