Coverage for src/models/test/test_site.py: 100%

40 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2024-10-10 12:25 +0000

1import argparse 

2import datetime 

3import unittest 

4import unittest.mock 

5 

6from ..site import Site, load_site 

7 

8 

9class SiteTestCase(unittest.TestCase): 

10 def test_load_site(self): 

11 parser = argparse.ArgumentParser() 

12 parser.add_argument('--site-title') 

13 parser.add_argument('--site-description') 

14 parser.add_argument('--site-author') 

15 parser.add_argument('--site-email') 

16 

17 args = parser.parse_args( 

18 [ 

19 '--site-title', 'Hello', 

20 '--site-description', 'a website', 

21 '--site-author', 'Alex Recker', 

22 '--site-email', 'email@test.com' 

23 ] 

24 ) 

25 site = load_site(args) 

26 self.assertEqual(site.title, 'Hello') 

27 self.assertEqual(site.description, 'a website') 

28 self.assertEqual(site.author, 'Alex Recker') 

29 self.assertEqual(site.email, 'email@test.com') 

30 

31 def test_python_version(self): 

32 patch = unittest.mock.patch( 

33 'platform.python_version', return_value='1.2.3') 

34 

35 with patch: 

36 actual = Site().python_version 

37 expected = 'v1.2.3' 

38 self.assertEqual(actual, expected) 

39 

40 def test_python_executable(self): 

41 mock = unittest.mock.PropertyMock(return_value='/bin/fart') 

42 patch = unittest.mock.patch('sys.executable', new_callable=mock) 

43 

44 with patch: 

45 actual = Site().python_executable 

46 expected = '/bin/fart' 

47 self.assertEqual(actual, expected) 

48 

49 def test_url(self): 

50 actual = Site(protocol='http', domain='localhost').url 

51 expected = 'http://localhost' 

52 self.assertEqual(actual, expected) 

53 

54 def test_timestamp(self): 

55 site = Site() 

56 expected = datetime.datetime.now() 

57 site._timestamp = expected 

58 self.assertEqual(site.timestamp, expected)