add unittest test_title

This commit is contained in:
Trent Palmer 2021-08-20 11:40:12 -07:00
parent beb1bdadba
commit 4dec9f77c9
5 changed files with 66 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
hugothemes.db
__pycache__
test/__pycache__
hugo-themes-report
hugo_themes_report.log

20
test/README.md Normal file
View File

@ -0,0 +1,20 @@
To run these tests just type the command
```python
python3 -m unittest
```
Or you can just run a specific file of tests
```python
python3 -m unittest test.test_title
```
Or run a specific test class in a specific file
```python
python3 -m unittest test.test_title.TestTitle
```
Or run a specific test function in a specific class in a specific file
```python
python3 -m unittest test.test_title.TestTitle.test_title_anchor
```

0
test/__init__.py Normal file
View File

21
test/test_selenium.py Normal file
View File

@ -0,0 +1,21 @@
import unittest
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
OPTIONS = Options()
OPTIONS.add_argument('--ignore-certificate-errors')
OPTIONS.add_argument('--incognito')
OPTIONS.add_argument('--headless')
SERVICE = Service('/usr/bin/chromedriver')
SOURCE_FILE = Path('hugo-themes-report/hugo-themes-report.html').resolve()
SOURCE_PAGE = f'file://{str(SOURCE_FILE)}'
class TestSelenium(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(options=OPTIONS, service=SERVICE)
self.driver.get(SOURCE_PAGE)
def tearDown(self):
self.driver.quit()

24
test/test_title.py Normal file
View File

@ -0,0 +1,24 @@
from test.test_selenium import TestSelenium
import unittest
class TestTitle(TestSelenium, unittest.TestCase):
def setUp(self):
super(TestTitle, self).setUp()
self.x = self.driver.find_elements_by_tag_name('h1')
def test_title(self):
self.assertEqual(len(self.x), 1)
self.assertEqual(self.x[0].get_attribute('id'), 'title')
self.assertEqual(self.x[0].value_of_css_property('text-align'), 'center')
self.assertEqual(self.x[0].value_of_css_property('display'), 'block')
self.assertEqual(self.x[0].value_of_css_property('max-width'), '736px')
self.assertEqual(self.x[0].value_of_css_property('font-size'), '32px')
self.assertEqual(self.x[0].value_of_css_property('font-weight'), '700')
self.assertEqual(self.x[0].value_of_css_property('font-family'), 'sans-serif')
def test_title_anchor(self):
x_anchors = self.x[0].find_elements_by_tag_name('a')
self.assertEqual(len(x_anchors), 1)
self.assertEqual(x_anchors[0].get_attribute('href'), 'https://github.com/TrentSPalmer/hugo_themes_report')
self.assertEqual(x_anchors[0].get_attribute('target'), '_blank')