Coverage for src/models/test/test_image.py: 100%
48 statements
« prev ^ index » next coverage.py v7.3.0, created at 2024-12-08 12:26 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2024-12-08 12:26 +0000
1import unittest
3from ..image import Image
6class TestImage(unittest.TestCase):
7 def test_filename(self):
8 self.assertEqual(Image('test.jpg').filename, 'test.jpg')
9 self.assertEqual(Image('something/test.jpg').filename, 'test.jpg')
11 def test_date_slug(self):
12 actual = Image('1990-09-28-test.jpg').date_slug
13 expected = '1990-09-28'
14 self.assertEqual(actual, expected)
16 actual = Image('banners/1990-09-28.jpg').date_slug
17 expected = '1990-09-28'
18 self.assertEqual(actual, expected)
20 with self.assertRaises(ValueError):
21 Image('banners/quotes.jpg').date_slug
23 def test_date(self):
24 actual = Image('1990-09-28-test.jpg').date
25 actual = (actual.year, actual.month, actual.day)
26 expected = (1990, 9, 28)
27 self.assertEqual(actual, expected)
29 with self.assertRaises(ValueError):
30 Image('banners/quotes.jpg').date
32 def test_slug(self):
33 actual = Image('1990-09-28-test-image.jpg').slug
34 expected = 'test-image'
35 self.assertEqual(actual, expected)
37 actual = Image('1990-09-28.jpg').slug
38 self.assertIsNone(actual)
40 actual = Image('bare-image.jpg').slug
41 expected = 'bare-image'
42 self.assertEqual(actual, expected)
44 def test_title(self):
45 actual = Image('1990-09-28-test-image.jpg').title
46 expected = 'Test Image'
47 self.assertEqual(actual, expected)
49 def test_href(self):
50 actual = Image('www/images/test.jpg').href
51 expected = './images/test.jpg'
52 self.assertEqual(actual, expected)
54 actual = Image('www/images/subfolder/test.jpg').href
55 expected = './images/subfolder/test.jpg'
56 self.assertEqual(actual, expected)
58 actual = Image('./www/images/test.jpg').href
59 expected = './images/test.jpg'
60 self.assertEqual(actual, expected)
62 def test_is_banner(self):
63 self.assertTrue(Image('./www/images/2024-01-01.jpg').is_banner)
64 self.assertFalse(Image('./www/images/2024-01-01-test.jpg').is_banner)