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