Skip to content

Commit

Permalink
add unit tests to check for ImproperlyConfigured and add TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlabe committed Oct 2, 2020
1 parent acf0d1d commit 806e0e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
20 changes: 11 additions & 9 deletions dbbackup/tests/commands/test_dbbackup.py
Expand Up @@ -2,6 +2,8 @@
Tests for dbbackup command.
"""
import os

from django.core.exceptions import ImproperlyConfigured
from six import StringIO
from django.core.management import execute_from_command_line

Expand Down Expand Up @@ -53,15 +55,15 @@ def test_path(self):
# tearDown
os.remove(self.command.path)

# def test_fallback(self):
# stdout = StringIO()
# with patch('sys.stdout', stdout):
# execute_from_command_line(['', 'dbbackup', '--fallback'])
# stdout.seek(0)
# stdout.readline()
# for line in stdout.readlines():
# self.assertIn('You must specify a storage class using '
# 'DBBACKUP_FALLBACK_STORAGE settings.', line)
def test_fallback(self):
stdout = StringIO()
with self.assertRaises(ImproperlyConfigured) as ic:
with patch('sys.stdout', stdout):
execute_from_command_line(['', 'dbbackup', '--fallback'])
self.assertEqual(str(ic.exception),
'You must specify a storage class using DBBACKUP_FALLBACK_STORAGE settings.')

# TODO: Update DBBACKUP_FALLBACK_STORAGE and verify successful backup.


@patch('dbbackup.settings.GPG_RECIPIENT', 'test@test')
Expand Down
13 changes: 13 additions & 0 deletions dbbackup/tests/commands/test_dbrestore.py
@@ -1,6 +1,8 @@
"""
Tests for dbrestore command.
"""
from django.core.exceptions import ImproperlyConfigured
from django.core.management import execute_from_command_line
from mock import patch
from tempfile import mktemp
from shutil import copyfileobj
Expand All @@ -9,6 +11,7 @@
from django.core.management.base import CommandError
from django.core.files import File
from django.conf import settings
from six import StringIO

from dbbackup import utils
from dbbackup.db.base import get_connector
Expand Down Expand Up @@ -90,6 +93,16 @@ def test_path(self, *args):
)
self.command._restore_backup()

def test_fallback(self, *args):
stdout = StringIO()
with self.assertRaises(ImproperlyConfigured) as ic:
with patch('sys.stdout', stdout):
execute_from_command_line(['', 'dbrestore', '--fallback'])
self.assertEqual(str(ic.exception),
'You must specify a storage class using DBBACKUP_FALLBACK_STORAGE settings.')

# TODO: Update DBBACKUP_FALLBACK_STORAGE and verify successful restore.


class DbrestoreCommandGetDatabaseTest(TestCase):
def setUp(self):
Expand Down

0 comments on commit 806e0e6

Please sign in to comment.