Debian Codegraph @

tests/test_checks.py

raw
1 from unittest.mock import patch
2
3 from django.test import TestCase
4
5 try:
6 from dbbackup import checks
7 from dbbackup.apps import DbbackupConfig
8 except ImportError:
9 checks = None
10
11
12 def foobar_func(*args, **kwargs):
13 return "foo"
14
15
16 class ChecksTest(TestCase):
17 def setUp(self):
18 if checks is None:
19 self.skipTest("Test framework has been released in Django 1.7")
20
21 def test_check(self):
22 assert not checks.check_settings(DbbackupConfig)
23
24 @patch("dbbackup.checks.settings.HOSTNAME", "")
25 def test_hostname_invalid(self):
26 expected_errors = [checks.W001]
27 errors = checks.check_settings(DbbackupConfig)
28 assert expected_errors == errors
29
30 @patch("dbbackup.checks.settings.STORAGE", "")
31 def test_hostname_storage(self):
32 expected_errors = [checks.W002]
33 errors = checks.check_settings(DbbackupConfig)
34 assert expected_errors == errors
35
36 @patch("dbbackup.checks.settings.FILENAME_TEMPLATE", foobar_func)
37 def test_filename_template_is_callable(self):
38 assert not checks.check_settings(DbbackupConfig)
39
40 @patch("dbbackup.checks.settings.FILENAME_TEMPLATE", "{datetime}.bak")
41 def test_filename_template_is_string(self):
42 assert not checks.check_settings(DbbackupConfig)
43
44 @patch("dbbackup.checks.settings.FILENAME_TEMPLATE", "foo.bak")
45 def test_filename_template_no_date(self):
46 expected_errors = [checks.W003]
47 errors = checks.check_settings(DbbackupConfig)
48 assert expected_errors == errors
49
50 @patch("dbbackup.checks.settings.MEDIA_FILENAME_TEMPLATE", foobar_func)
51 def test_media_filename_template_is_callable(self):
52 assert not checks.check_settings(DbbackupConfig)
53
54 @patch("dbbackup.checks.settings.MEDIA_FILENAME_TEMPLATE", "{datetime}.bak")
55 def test_media_filename_template_is_string(self):
56 assert not checks.check_settings(DbbackupConfig)
57
58 @patch("dbbackup.checks.settings.MEDIA_FILENAME_TEMPLATE", "foo.bak")
59 def test_media_filename_template_no_date(self):
60 expected_errors = [checks.W004]
61 errors = checks.check_settings(DbbackupConfig)
62 assert expected_errors == errors
63
64 @patch("dbbackup.checks.settings.DATE_FORMAT", "[email protected]")
65 def test_date_format_warning(self):
66 expected_errors = [checks.W005]
67 errors = checks.check_settings(DbbackupConfig)
68 assert expected_errors == errors
69
70 @patch("dbbackup.checks.settings.FILENAME_TEMPLATE", "foo/bar-{datetime}.ext")
71 def test_db_filename_template_with_slash(self):
72 expected_errors = [checks.W007]
73 errors = checks.check_settings(DbbackupConfig)
74 assert expected_errors == errors
75
76 @patch("dbbackup.checks.settings.FILENAME_TEMPLATE", lambda _: "foo/bar")
77 def test_db_filename_template_callable_with_slash(self):
78 expected_errors = [checks.W007]
79 errors = checks.check_settings(DbbackupConfig)
80 assert expected_errors == errors
81
82 @patch("dbbackup.checks.settings.MEDIA_FILENAME_TEMPLATE", "foo/bar-{datetime}.ext")
83 def test_media_filename_template_with_slash(self):
84 expected_errors = [checks.W008]
85 errors = checks.check_settings(DbbackupConfig)
86 assert expected_errors == errors
87
88 @patch("dbbackup.checks.settings.MEDIA_FILENAME_TEMPLATE", lambda _: "foo/bar")
89 def test_media_filename_template_callable_with_slash(self):
90 expected_errors = [checks.W008]
91 errors = checks.check_settings(DbbackupConfig)
92 assert expected_errors == errors