diff --git a/.gitignore b/.gitignore index fece58d..a871b4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ hugothemes.db __pycache__ +test/__pycache__ hugo-themes-report hugo_themes_report.log diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..4996ff5 --- /dev/null +++ b/test/README.md @@ -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 +``` diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_selenium.py b/test/test_selenium.py new file mode 100644 index 0000000..8a46ba5 --- /dev/null +++ b/test/test_selenium.py @@ -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() diff --git a/test/test_title.py b/test/test_title.py new file mode 100644 index 0000000..accef62 --- /dev/null +++ b/test/test_title.py @@ -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')