Coverage for src/models/test/test_page.py: 100%
29 statements
« prev ^ index » next coverage.py v7.3.0, created at 2024-10-10 12:25 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2024-10-10 12:25 +0000
1import tempfile
2import unittest
4from ..page import Page
7class TestPage(unittest.TestCase):
8 def test_filename(self):
9 actual = Page('./pages/index.html').filename
10 expected = 'index.html'
11 self.assertEqual(actual, expected)
13 actual = Page('./pages/index.html.j2').filename
14 expected = 'index.html'
15 self.assertEqual(actual, expected)
17 def test_is_entry(self):
18 self.assertFalse(Page('./pages/index.html').is_entry)
19 self.assertFalse(Page('./pages/index.html.j2').is_entry)
20 self.assertFalse(Page('./pages/index.html.j2').is_entry)
21 self.assertTrue(Page('./entries/something.html').is_entry)
23 def test_date(self):
24 actual = Page('./entries/2023-08-10.html').date
25 actual = (actual.year, actual.month, actual.day)
26 expected = (2023, 8, 10)
27 self.assertEqual(actual, expected)
29 def test_metadata(self):
30 content = '''
31<!-- meta:title A Test Title -->
32<!-- meta:description A Test Description -->
33 '''
35 tmp = tempfile.NamedTemporaryFile()
37 with open(tmp.name, 'w') as f:
38 f.write(content)
40 actual = Page(tmp.name).metadata
41 expected = {
42 'title': 'A Test Title',
43 'description': 'A Test Description',
44 }
45 self.assertEqual(actual, expected)