def test_validation_type_for_domain_object_strict(self) -> None: blog_model = blog_models.BlogPostModel(id='validblogid2', title='Sample Title', content='<p>hello</p>,', author_id='user', url_fragment='url-fragment-1', created_on=self.YEAR_AGO, last_updated=self.NOW, published_on=self.NOW, thumbnail_filename='sample.svg', tags=['learners']) blog_rights_model = blog_models.BlogPostRightsModel( id='validblogid2', editor_ids=['user'], blog_post_is_published=True, created_on=self.YEAR_AGO, last_updated=self.NOW) blog_rights_model.update_timestamps() blog_rights_model.put() output = ( self.pipeline | beam.Create([blog_model]) | beam.ParDo( blog_validation.ValidateBlogPostModelDomainObjectsInstances())) self.assert_pcoll_equal(output, []) # type: ignore[no-untyped-call]
def test_reports_model_last_updated_timestamp_relationship_error( self ) -> None: invalid_timestamp = blog_models.BlogPostModel( id='validblogid1', title='Sample Title', content='<p>hello</p>,', author_id='user', url_fragment='url-fragment-1', created_on=self.YEAR_AGO, last_updated=self.YEAR_AGO, published_on=self.NOW) output = ( self.pipeline | beam.Create([invalid_timestamp]) | beam.ParDo(blog_validation.ValidateModelPublishTimestamps()) ) self.assert_pcoll_equal( # type: ignore[no-untyped-call] output, [ blog_validation_errors .InconsistentPublishLastUpdatedTimestampsError( invalid_timestamp), ] )
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))
def setUp(self) -> None: """Set up blog post models in datastore for use in testing.""" super(BlogPostModelTest, self).setUp() self.blog_post_model = blog_models.BlogPostModel( id='blog_one', author_id=self.USER_ID, content=self.CONTENT, title=self.TITLE, published_on=datetime.datetime.utcnow(), url_fragment='sample-url-fragment', tags=self.TAGS, thumbnail_filename=self.THUMBNAIL) self.blog_post_model.update_timestamps() self.blog_post_model.put()
def test_message(self) -> None: model = blog_models.BlogPostModel(id='validblogid1', title='Sample Title', content='<p>hello</p>,', author_id='user', url_fragment='url_fragment_1', created_on=self.NOW, last_updated=self.YEAR_AGO, published_on=self.YEAR_AGO) error = blog_validation_errors.InconsistentPublishTimestampsError( model) self.assertEqual( error.stderr, 'InconsistentPublishTimestampsError in BlogPostModel' '(id="validblogid1"): created_on=%r is later than published_on=%r' % (self.NOW, self.YEAR_AGO))
def test_message(self) -> None: model = blog_models.BlogPostModel(id='validblogid1', title='Sample Title', content='<p>hello</p>,', author_id='user', url_fragment='url_fragment_1', created_on=self.YEAR_AGO, last_updated=self.NOW, published_on=self.YEAR_AGO) error = blog_validation_errors.ModelMutatedDuringJobError(model) self.assertEqual( error.stderr, 'ModelMutatedDuringJobError in BlogPostModel(id="validblogid1"): ' 'published_on=%r is later than the audit job\'s start time' % (model.published_on))
def test_process_reports_no_error_if_published_on_is_none(self) -> None: valid_timestamp = blog_models.BlogPostModel( id='124', title='Sample Title', content='<p>hello</p>,', author_id='user', url_fragment='url-fragment-1', created_on=self.NOW, last_updated=self.NOW, published_on=None) output = (self.pipeline | beam.Create([valid_timestamp]) | beam.ParDo( blog_validation.ValidateModelPublishTimestamps())) self.assert_pcoll_equal(output, []) # type: ignore[no-untyped-call]
def test_process_reports_model_mutated_during_job_error(self) -> None: invalid_timestamp = blog_models.BlogPostModel( id='124', title='Sample Title', content='<p>hello</p>,', author_id='user', url_fragment='url-fragment-1', created_on=self.NOW, last_updated=self.YEAR_LATER, published_on=self.YEAR_LATER) output = (self.pipeline | beam.Create([invalid_timestamp]) | beam.ParDo( blog_validation.ValidateModelPublishTimestamps())) self.assert_pcoll_equal(output, [ blog_validation_errors.ModelMutatedDuringJobError( invalid_timestamp), ])