Example #1
0
 def run(self) -> beam.Pipeline:
     return (self.pipeline
             | 'Get every Blog Summary Model' >>
             (ndb_io.GetModels(blog_models.BlogPostSummaryModel.query()))
             | GetModelsWithDuplicatePropertyValues('title')
             | 'Flatten models into a list of errors' >>
             beam.FlatMap(lambda models: [
                 blog_validation_errors.DuplicateBlogTitleError(model)
                 for model in models
             ]))
Example #2
0
    def test_run_with_same_titles_for_blog_posts(self):
        # type: () -> None
        blog_post_model_1 = self.create_model( # type: ignore[no-untyped-call]
            blog_models.BlogPostModel,
            id='validblogid1',
            title='Sample Title',
            content='<p>hello</p>,',
            author_id='user',
            url_fragment='url_fragment_1')
        blog_post_model_2 = self.create_model( # type: ignore[no-untyped-call]
            blog_models.BlogPostModel,
            id='validblogid2',
            title='Sample Title',
            content='<p>hello tho</p>,',
            author_id='user',
            url_fragment='url_fragment_2')
        blog_post_model_3 = self.create_model( # type: ignore[no-untyped-call]
            blog_models.BlogPostModel,
            id='validblogid3',
            title='Sample Diff Title',
            content='<p>hello tho</p>,',
            author_id='user',
            url_fragment='url_fragment_2')

        self.put_multi( # type: ignore[no-untyped-call]
            [
                blog_post_model_1,
                blog_post_model_2,
                blog_post_model_3,
            ]
        )

        self.assert_job_output_is( # type: ignore[no-untyped-call]
            [
                blog_validation_errors.DuplicateBlogTitleError(
                    blog_post_model_1
                ),
                blog_validation_errors.DuplicateBlogTitleError(
                    blog_post_model_2
                ),
            ]
        )
Example #3
0
 def run(self):
     # type: () -> base_jobs.JobBase.pipeline
     return (self.pipeline
             | 'Get every Blog Model' >> (
                 ndb_io.GetModels(  # type: ignore[no-untyped-call]
                     blog_models.BlogPostModel.query()))
             | GetModelsWithDuplicatePropertyValues('title')
             | 'Flatten models into a list of errors' >>
             beam.FlatMap(lambda models: [
                 blog_validation_errors.DuplicateBlogTitleError(model)
                 for model in models
             ]))
Example #4
0
    def test_message(self) -> None:
        blog_post_model = blog_models.BlogPostModel(
            id='validblogid1',
            title='Sample Title',
            content='<p>hello</p>,',
            author_id='user',
            url_fragment='url_fragment_1')

        error = blog_validation_errors.DuplicateBlogTitleError(blog_post_model)

        self.assertEqual(
            error.stderr,
            'DuplicateBlogTitleError in BlogPostModel(id="validblogid1"):'
            ' title=%s is not unique' % utils.quoted(blog_post_model.title))