forked from jazzband/django-dbbackup
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jazzband#78 from ZuluPro/basecommand
Added base command class & fixed tests for dbbackup command
- Loading branch information
Showing
8 changed files
with
96 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from optparse import make_option | ||
from django.core.management.base import BaseCommand, LabelCommand | ||
|
||
|
||
class BaseDbBackupCommand(LabelCommand): | ||
option_list = BaseCommand.option_list + ( | ||
make_option("--noinput", action='store_false', dest='interactive', default=True, | ||
help='Tells Django to NOT prompt the user for input of any kind.'), | ||
make_option('-q', "--quiet", action='store_true', default=False, | ||
help='Tells Django to NOT output other text than errors.') | ||
) | ||
|
||
verbosity = 1 | ||
quiet = False | ||
|
||
def log(self, msg, level): | ||
if not self.quiet and self.verbosity >= level: | ||
self.stdout.write(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
try: | ||
from StringIO import StringIO | ||
except ImportError: # Py3 | ||
from io import StringIO | ||
from django.test import TestCase | ||
from dbbackup.management.commands._base import BaseDbBackupCommand | ||
|
||
|
||
class BaseDbBackupCommandLogTest(TestCase): | ||
def setUp(self): | ||
self.command = BaseDbBackupCommand() | ||
self.command.stdout = StringIO() | ||
|
||
def test_less_level(self): | ||
self.command.verbosity = 1 | ||
self.command.log("foo", 2) | ||
self.command.stdout.seek(0) | ||
self.assertFalse(self.command.stdout.read()) | ||
|
||
def test_more_level(self): | ||
self.command.verbosity = 1 | ||
self.command.log("foo", 0) | ||
self.command.stdout.seek(0) | ||
self.assertEqual('foo', self.command.stdout.read()) | ||
|
||
def test_quiet(self): | ||
self.command.quiet = True | ||
self.command.verbosity = 1 | ||
self.command.log("foo", 0) | ||
self.command.stdout.seek(0) | ||
self.assertFalse(self.command.stdout.read()) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters