コード例 #1
0
 def run(self) -> beam.Pipeline:
     return (self.pipeline
             | 'Get every Blog Post Model' >>
             (ndb_io.GetModels(blog_models.BlogPostModel.query()))
             | GetModelsWithDuplicatePropertyValues('url_fragment')
             | 'Flatten models into a list of errors' >>
             beam.FlatMap(lambda models: [
                 blog_validation_errors.DuplicateBlogUrlError(model)
                 for model in models
             ]))
コード例 #2
0
    def test_run_with_same_url_for_blog_posts(self):
        # type: () -> None
        blog_post_summary_model_1 = self.create_model( # type: ignore[no-untyped-call]
            blog_models.BlogPostSummaryModel,
            id='validblogid1',
            title='Sample Title 1',
            summary='<p>hello</p>,',
            author_id='user',
            url_fragment='url_fragment')
        blog_post_summary_model_2 = self.create_model( # type: ignore[no-untyped-call]
            blog_models.BlogPostSummaryModel,
            id='validblogid2',
            title='Sample Title 2',
            summary='<p>hello tho</p>,',
            author_id='user',
            url_fragment='url_fragment')
        blog_post_summary_model_3 = self.create_model( # type: ignore[no-untyped-call]
            blog_models.BlogPostSummaryModel,
            id='validblogid3',
            title='Sample Diff Title',
            summary='<p>hello tho</p>,',
            author_id='user',
            url_fragment='diff_url_fragment')

        self.put_multi( # type: ignore[no-untyped-call]
            [
                blog_post_summary_model_1,
                blog_post_summary_model_2,
                blog_post_summary_model_3,
            ]
        )

        self.assert_job_output_is(# type: ignore[no-untyped-call]
            [
                blog_validation_errors.DuplicateBlogUrlError(
                    blog_post_summary_model_1
                ),
                blog_validation_errors.DuplicateBlogUrlError(
                    blog_post_summary_model_2
                ),
            ])
コード例 #3
0
 def run(self):
     # type: () -> base_jobs.JobBase.pipeline
     return (self.pipeline
             | 'Get every Blog Post Model' >> (
                 ndb_io.GetModels(  # type: ignore[no-untyped-call]
                     blog_models.BlogPostModel.query()))
             | GetModelsWithDuplicatePropertyValues('url_fragment')
             | 'Flatten models into a list of errors' >>
             beam.FlatMap(lambda models: [
                 blog_validation_errors.DuplicateBlogUrlError(model)
                 for model in models
             ]))
コード例 #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.DuplicateBlogUrlError(blog_post_model)

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