def test_index_blog_shows_posts_and_can_be_consulted(self): # Nato goes to the blog and creates a posts and keeps the url first_post = PostFactory.build(title='First post title') create_post_page = CreatePostPage(self).create_post(first_post) first_post_url = self.browser.current_url # He can see the post in the index page of the posts index_blog_page = IndexBlogPage(self).go_to_index_blog_page() index_blog_page.wait_for_title_post_in_the_posts(first_post.title) # He clicks the Read More link and can see that he is in the page # for that post post = index_blog_page.get_post_from_this_page(first_post.title) post.find_element_by_link_text('READ MORE').click() self.wait_for( lambda: self.assertEqual(self.browser.current_url, first_post_url) ) # He creates another post and again saves the url second_post = PostFactory.build(title='Second post title') create_post_page.create_post(second_post) second_post_url = self.browser.current_url # And now he sees the new created post in the index index_blog_page = IndexBlogPage(self).go_to_index_blog_page() index_blog_page.wait_for_title_post_in_the_posts(second_post.title) # And he checks is the page that shows him the post post = index_blog_page.get_post_from_this_page(second_post.title) post.find_element_by_link_text('READ MORE').click() self.wait_for( lambda: self.assertEqual(self.browser.current_url, second_post_url) )
def test_index_blog_does_not_show_non_published_post(self): # Nato goes to the blog and creates an expired post non_published_post = PostFactory.build(title='Expired post') non_published_post.publication_date = datetime.date.today( ) + datetime.timedelta(1) create_post_page = CreatePostPage(self).create_post(non_published_post) # And creates a non expired post published_post = PostFactory.build(title='Not expired post') published_post.publication_date = datetime.date.today() published_post.expiring_date = datetime.date.today() create_post_page.create_post(published_post) # He can see the post in the index page of the posts index_post_page = IndexBlogPage(self).go_to_index_blog_page() index_post_page.wait_for_title_post_in_the_posts(published_post.title) # And as expected he can't see the expired post body = self.browser.find_element_by_tag_name('body') self.assertNotIn(non_published_post.title, body.text)
def test_can_delete_a_post(self): # Nato goes to the blog and creates two post first_post = PostFactory.build(title='First post title') second_post = PostFactory.build(title='Second post title') create_post_page = CreatePostPage(self).create_post(first_post) create_post_page.create_post(second_post) # He can see the posts in the index index_post_page = IndexPostPage(self).go_to_index_post_page() index_post_page.wait_for_title_post_in_the_posts(first_post.title) index_post_page.wait_for_title_post_in_the_posts(second_post.title) # He clicks the Delete button of one post post = index_post_page.get_post_from_this_page(second_post.title) post.find_element_by_name('delete post').click() index_post_page.check_message_in_messages( 'The blog post has been succesfully deleted') # and he can see the post has been deleted body = self.browser.find_element_by_tag_name('body') self.assertNotIn(second_post.title, body.text) index_post_page.wait_for_title_post_in_the_posts(first_post.title)