-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '23-management-command' into merge-0.5
Conflicts: watchman/checks.py
- Loading branch information
Showing
10 changed files
with
207 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
test_django-watchman | ||
------------ | ||
Tests for `django-watchman` management commands. | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
import unittest | ||
|
||
from django.core.management import call_command | ||
from django.utils.six import StringIO | ||
|
||
|
||
class TestWatchman(unittest.TestCase): | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def test_successful_management_command_outputs_nothing(self): | ||
out = StringIO() | ||
call_command('watchman', stdout=out) | ||
self.assertEquals('', out.getvalue()) | ||
|
||
def test_successful_management_command_outputs_check_status_with_verbosity_2(self): | ||
out = StringIO() | ||
call_command('watchman', stdout=out, verbosity='2') | ||
self.assertIn('caches', out.getvalue()) | ||
|
||
def test_successful_management_command_outputs_check_status_with_verbosity_3(self): | ||
out = StringIO() | ||
call_command('watchman', stdout=out, verbosity='3') | ||
self.assertIn('caches', out.getvalue()) | ||
|
||
def test_successful_management_command_supports_check_list(self): | ||
out = StringIO() | ||
call_command('watchman', stdout=out, checks='watchman.checks.caches', verbosity='3') | ||
self.assertIn('caches', out.getvalue()) | ||
self.assertNotIn('databases', out.getvalue()) | ||
|
||
def test_successful_management_command_supports_skip_list(self): | ||
out = StringIO() | ||
call_command('watchman', stdout=out, skips='watchman.checks.email', verbosity='3') | ||
self.assertIn('caches', out.getvalue()) | ||
self.assertIn('databases', out.getvalue()) | ||
self.assertNotIn('email', out.getvalue()) |
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,59 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
test_django-watchman | ||
------------ | ||
Tests for `django-watchman` utils module. | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
import unittest | ||
|
||
from watchman.utils import get_checks | ||
|
||
|
||
class TestWatchman(unittest.TestCase): | ||
|
||
def assertListsEqual(self, l1, l2): | ||
try: | ||
# Python 3.4 | ||
self.assertCountEqual(l1, l2) | ||
except AttributeError: | ||
# Python 2.7 | ||
self.assertItemsEqual(l1, l2) | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def test_get_checks_returns_all_available_checks_by_default(self): | ||
checks = [check.__name__ for check in get_checks()] | ||
expected_checks = ['caches', 'databases', 'storage'] | ||
self.assertListsEqual(checks, expected_checks) | ||
|
||
def test_get_checks_with_check_list_returns_union(self): | ||
check_list = ['watchman.checks.caches'] | ||
checks = [check.__name__ for check in get_checks(check_list=check_list)] | ||
expected_checks = ['caches'] | ||
self.assertListsEqual(checks, expected_checks) | ||
|
||
def test_get_checks_with_skip_list_returns_difference(self): | ||
skip_list = ['watchman.checks.caches'] | ||
checks = [check.__name__ for check in get_checks(skip_list=skip_list)] | ||
expected_checks = ['databases', 'storage'] | ||
self.assertListsEqual(checks, expected_checks) | ||
|
||
def test_get_checks_with_matching_check_and_skip_list_returns_empty_list(self): | ||
check_list, skip_list = ['watchman.checks.caches'], ['watchman.checks.caches'] | ||
checks = [check.__name__ for check in get_checks(check_list=check_list, skip_list=skip_list)] | ||
expected_checks = [] | ||
self.assertListsEqual(checks, expected_checks) | ||
|
||
def test_get_checks_with_check_and_skip_list(self): | ||
check_list = ['watchman.checks.caches', 'watchman.checks.databases'] | ||
skip_list = ['watchman.checks.caches'] | ||
checks = [check.__name__ for check in get_checks(check_list=check_list, skip_list=skip_list)] | ||
expected_checks = ['databases'] | ||
self.assertListsEqual(checks, expected_checks) |
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.
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,50 @@ | ||
from __future__ import absolute_import | ||
|
||
import json | ||
from optparse import make_option | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from watchman.utils import get_checks | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Runs the default django-watchman checks' | ||
|
||
option_list = BaseCommand.option_list + ( | ||
make_option( | ||
'-c', | ||
'--checks', | ||
dest='checks', | ||
help='A comma-separated list of watchman checks to run (full python dotted paths)' | ||
), | ||
make_option( | ||
'-s', | ||
'--skips', | ||
dest='skips', | ||
help='A comma-separated list of watchman checks to skip (full python dotted paths)' | ||
), | ||
) | ||
|
||
def handle(self, *args, **options): | ||
check_list = None | ||
skip_list = None | ||
verbosity = options['verbosity'] | ||
print_all_checks = verbosity == '2' or verbosity == '3' | ||
|
||
checks = options['checks'] | ||
skips = options['skips'] | ||
|
||
if checks is not None: | ||
check_list = checks.split(',') | ||
|
||
if skips is not None: | ||
skip_list = skips.split(',') | ||
|
||
for check in get_checks(check_list=check_list, skip_list=skip_list): | ||
if callable(check): | ||
resp = json.dumps(check()) | ||
if '"ok": false' in resp: | ||
raise CommandError(resp) | ||
elif print_all_checks: | ||
self.stdout.write(resp) |
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