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
|
# -*- coding: utf-8 -*-
import pytest
from django.core.management import CommandError, call_command
def test_without_args(capsys):
call_command("print_settings")
out, err = capsys.readouterr()
assert "DEBUG" in out
assert "INSTALLED_APPS" in out
def test_with_setting_args(capsys):
call_command("print_settings", "DEBUG")
out, err = capsys.readouterr()
assert "DEBUG" in out
assert "INSTALLED_APPS" not in out
def test_with_setting_wildcard(capsys):
call_command("print_settings", "*_DIRS")
out, err = capsys.readouterr()
assert "FIXTURE_DIRS" in out
assert "STATICFILES_DIRS" in out
assert "INSTALLED_APPS" not in out
def test_with_setting_fail(capsys):
with pytest.raises(CommandError, match="INSTALLED_APPZ not found in settings."):
call_command("print_settings", "-f", "INSTALLED_APPZ")
def test_with_multiple_setting_args(capsys):
call_command(
"print_settings",
"SECRET_KEY",
"DATABASES",
"INSTALLED_APPS",
)
out, err = capsys.readouterr()
assert "DEBUG" not in out
assert "SECRET_KEY" in out
assert "DATABASES" in out
assert "INSTALLED_APPS" in out
def test_format(capsys):
call_command(
"print_settings",
"DEBUG",
"--format=text",
)
out, err = capsys.readouterr()
expected = "DEBUG = False\n"
assert expected == out
def test_format_json_without_indent(capsys):
call_command(
"print_settings",
"DEBUG",
"--format=json",
"--indent=0",
)
expected = '{\n"DEBUG": false\n}\n'
out, err = capsys.readouterr()
assert expected == out
|