def setUp(self): self.app = create_app(TestConfig) self.tester = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() dummy_post(categories=['tiger', 'bird', 'dog'])
def test_categories_w_post_count(self): dummy_post(categories=["birds", "dogs"], slug="post_1") dummy_post(categories=["birds"], slug="post_2") dic = categories_w_post_count() self.assertEqual( dic["birds"][1], 2, "Total number of posts posted under our dummy " "category is not what is expected")
def test_util_html_content(self): """Testing of the ``util_html_content`` function. Here we will be testing 3 things: - That the markdown formatting is converted to html. - That media URLs are converted into embeds. - That non-media URLs are converted to hyperlinks. """ media = "youtube video: https://www.youtube.com/watch?v=aOC8E8z_ifw" general_markdown = "this written in **bold**." url_to_hyperlink = "https://www.google.com/" p = dummy_post(content=media, slug='media') self.assertIn( 'title="The Mandalorian | Official Trailer |', util_html_content(p), "Html for the embed has not been returned by the" " function.") p = dummy_post(content=general_markdown, slug='general_markdown') self.assertIn( '<strong>bold</strong>', util_html_content(p), "Html for the bold markdown has not been returned by the" " function.") p = dummy_post(content=url_to_hyperlink, slug='url_to_hyperlink') self.assertIn( '<a href="https://www.google.com/">' 'https://www.google.com/</a>', util_html_content(p), "Url was not converted to an hyperlink by the function.")
def test_duplicate_title_for_edited_post(self): """Testing that an edited post can't take the same title as an existing post. """ # First we will create a new post that we will edit later. dummy_post(title='Post to edit', content="post content", slug="post_to_edit") # We will then try to edit the newly created post so the title is the # same as the one we used for our dummy_post created in the setUp. response = posting(self.tester, '/post_to_edit/edit_post', title_field='Dummy post', content_field='test duplicate post title') self.assertIn( b'title is already in use', response.data, "No message telling you that the title" " is already in use.") response = self.tester.get('/') self.assertNotIn( b'test duplicate post title', response.data, "Test post with duplicate title was still published" " and can be found on the /index page.") self.assertIn( b'post content', response.data, "Content of the unedited test post can not be found" " on the /index page.")
def test_pages_dropdown_menu(self): """Testing the ``Pages`` dropdown menu in the navbar. This menu is only shown to logged in users. The test will verify the presence of the menu and the two hyperlinks it should contain: - The static ``Create Page`` hyperlink. - The dynamic ``Pages Index`` hyperlink. This item only appears when at least one page have already been created. """ login(self.tester) response = self.tester.get('/') self.assertIn(b'<a class="nav-link dropdown-toggle" href="#" ' b'id="PagesDropdown" role="button" data-toggle="dropdown"' b' aria-haspopup="true" ' b'aria-expanded="false">\n Pages', response.data, "The ``pages`` dropdown menu can not be found in the " "navbar.") self.assertIn(b'<a class="dropdown-item" href="/create_page">' b'Create Page</a>', response.data, "The ``Create Page`` hyperlink can not be found in the" " ``Pages`` dropdown menu in the navbar.") self.assertNotIn(b'<a class="dropdown-item" href="/pages">' b'Pages Index</a>', response.data, "The ``Pages Index`` hyperlink can still be found in " "the ``Pages`` dropdown menu in the navbar.") dummy_post(is_page=True) response = self.tester.get('/') self.assertIn(b'<a class="dropdown-item" href="/pages">Pages Index</a>', response.data, "The ``Pages Index`` hyperlink can not be found in the " "``Pages`` dropdown menu in the navbar.")
def setUp(self): self.app = create_app(TestConfig) self.tester = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() dummy_post()
def setUp(self): self.app = create_app(TestConfig) self.tester = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() dummy_post(title="published page", slug="published_page", is_page=True)
def setUp(self): self.app = create_app(TestConfig) self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() dummy_post() control_categories("no_posts") control_search_bar('navbar')
def setUp(self): self.app = create_app(TestConfig) self.tester = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() dummy_post() dummy_user()
def setUp(self): self.app = create_app(TestConfig) self.tester = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() self.category = "birds" dummy_post(categories=[self.category])
def setUp(self): self.app = create_app(TestConfig) self.tester = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() dummy_post() dummy_post(title='Dummy Draft Post', slug="dummy_draft", is_published=False)
def setUp(self): self.app = create_app(TestConfig) self.tester = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() dummy_post() dummy_post(is_published=False, slug='draft_dummy_post') dummy_user() add_social('Twitter', 'https://twitter.com/nytimes')
def setUp(self): self.app = create_app(TestConfig) self.tester = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() dummy_post(categories=["birds"]) default_categories_presence() sbc = SearchBarControls(placement="sidebar") sbc.add_to_or_remove_from_sidebar() db.session.add(sbc) db.session.commit()
def test_index(self): """Functional test to verify that our /index routes can list pages. The test will see that both published and draft widgets are being listed on the page. """ dummy_post(title="draft page", slug="draft_page", is_page=True, is_published=False) response = self.tester.get("/pages") for title in [b"draft page", b"published page"]: self.assertIn( title, response.data, "Did not find the expected pages listed at the " "address.")
def setUp(self): self.app = create_app(TestConfig) self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() self.post = dummy_post(is_page=True)
def test_existing_drafts_in_navbar(self): """Testing the presence of the /draft page hyperlink in the navbar. It is supposed to show in the navbar for logged in users only. The hyperlink can only be displayed when a draft already exist.""" dummy_post(is_published=False) response = self.tester.get('/') self.assertNotIn(b'<a class="nav-link" href="/drafts">Drafts</a>', response.data, "Hyperlink to the /drafts page can still be found" " in the menu for non-logged in users.") login(self.tester) response = self.tester.get('/') self.assertIn(b'<a class="nav-link" href="/drafts">Drafts</a>', response.data, "Hyperlink to the /drafts page can not be found" " in the menu for logged-in users.")
def test_controls_dropdown_menu(self): """Testing the ``Controls`` dropdown menu in the navbar. This menu is only shown to logged in users. The test will verify the presence of the menu and the four hyperlinks it should contain: - The static ``Search Bar`` hyperlink. - The static ``Categories`` hyperlink. - The static ``Socials`` hyperlink. - The dynamic ``Widgets Order`` hyperlink. This item only appears when at least two widgets have been assigned to the sidebar. """ login(self.tester) response = self.tester.get('/') self.assertIn(b'Controls\n </a>', response.data, "The ``Controls`` dropdown menu can not be found" " in the navbar.") self.assertIn(b'<a class="dropdown-item" href="/controls/search_bar">' b'Search Bar</a>', response.data, "The ``Search Bar`` hyperlink can not be found in the" " ``Controls`` dropdown menu in the navbar.") self.assertIn(b'<a class="dropdown-item" href="/controls/categories">' b'Categories</a>', response.data, "The ``Categories`` hyperlink can not be found in the" " ``Controls`` dropdown menu in the navbar.") self.assertIn(b'<a class="dropdown-item" href="/controls/categories">' b'Categories</a>', response.data, "The ``Categories`` hyperlink can not be found in the" " ``Controls`` dropdown menu in the navbar.") self.assertNotIn(b'<a class="dropdown-item" href="/controls/' b'widgets_order">Widgets Order</a>', response.data, "The ``Widgets Order`` hyperlink can still be found" " in the ``Controls`` dropdown menu in the navbar.") dmc = dummy_content_widget() dmc.add_to_or_remove_from_sidebar() dummy_post() response = self.tester.get('/') self.assertIn(b'<a class="dropdown-item" href="/controls/' b'widgets_order">Widgets Order</a>', response.data, "The ``Widgets Order`` hyperlink can not be found in " "the ``Controls`` dropdown menu in the navbar.")
def test_pagination_for_drafts(self): """Will test pagination for our /drafts route. """ dummy_post(title='Dummy post1', slug="dummy_post1", is_published=False) dummy_post(title='Dummy post2', slug="dummy_post2", is_published=False) dummy_post(title='Dummy post3', slug="dummy_post3", is_published=False) response = self.tester.get('/drafts?page=2') self.assertIn( b'Dummy post1', response.data, "Can't find the last dummy post on the second page of " "the /drafts.")
def test_pagination_for_search(self): """Will test pagination for our /search route. """ dummy_post(title='Dummy post1', slug="dummy_post1", is_published=True) dummy_post(title='Dummy post2', slug="dummy_post2", is_published=True) dummy_post(title='Dummy post3', slug="dummy_post3", is_published=True) response = self.tester.get('/search?page=2&q=dummy') self.assertIn( b'Dummy post3', response.data, "Can't find the last dummy post on the second page of " "the search results.")
def test_pagination_for_index(self): """Will test pagination for our /index route. """ # We will add several dummy posts so we can create at least # one more page to paginate too when reaching the /index route. # The same pattern of creating dummy posts is going to be used for # the subsequent tests. dummy_post(title='Dummy post1', slug="dummy_post1", is_published=True) dummy_post(title='Dummy post2', slug="dummy_post2", is_published=True) dummy_post(title='Dummy post3', slug="dummy_post3", is_published=True) response = self.tester.get('/index?page=2') self.assertIn( b'Dummy post1', response.data, "Can't find the last dummy post on the second page of " "the /index.")
def test_draft_exists(self): dummy_post(slug='draft_post', is_published=False) de = draft_exists() self.assertTrue(de, "Function have not been capable to find any draft")