2020-05-07 15:22:07 +01:00
|
|
|
from bs4 import BeautifulSoup
|
2020-04-13 10:50:59 +01:00
|
|
|
from django.test import SimpleTestCase
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
|
|
|
|
class BaseTestCase(SimpleTestCase):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class HomepageViewTestCase(BaseTestCase):
|
|
|
|
def test_accessible(self):
|
|
|
|
response = self.client.get(reverse("homepage"))
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2020-04-13 12:50:08 +01:00
|
|
|
|
|
|
|
def test_contains_view_name(self):
|
|
|
|
response = self.client.get(reverse("homepage"))
|
|
|
|
self.assertContains(response, '<body class="homepageview">')
|
2020-04-25 20:35:34 +01:00
|
|
|
|
2020-05-07 15:22:07 +01:00
|
|
|
def test_navbar_links_accessible(self):
|
|
|
|
response = self.client.get(reverse("homepage"))
|
|
|
|
soup = BeautifulSoup(response.content, features="html.parser")
|
|
|
|
nav_links = list(soup.find("nav").find_all("a", class_="nav-link"))
|
|
|
|
self.assertEqual(len(nav_links), 2)
|
|
|
|
for nav_link in nav_links:
|
|
|
|
nav_link_response = self.client.head(nav_link.attrs["href"])
|
|
|
|
self.assertEqual(nav_link_response.status_code, 200)
|
|
|
|
|
|
|
|
def test_navbar_link_text(self):
|
|
|
|
response = self.client.get(reverse("homepage"))
|
|
|
|
soup = BeautifulSoup(response.content, features="html.parser")
|
|
|
|
nav_links = list(soup.find("nav").find_all("a", class_="nav-link"))
|
|
|
|
self.assertEqual(
|
|
|
|
{nav_link.find("code").text for nav_link in nav_links},
|
|
|
|
{"~/about", "~/blog"},
|
|
|
|
)
|
|
|
|
|
2020-04-25 20:35:34 +01:00
|
|
|
|
|
|
|
class AboutViewTestCase(BaseTestCase):
|
|
|
|
def test_accessible(self):
|
|
|
|
response = self.client.get(reverse("about"))
|
|
|
|
self.assertEqual(response.status_code, 200)
|