Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Dec 27, 2020
1 parent 79f9dff commit d94ab7f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app_enabler/enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import django.conf

from .django import get_settings_path, get_urlconf_path, load_addon
from .errors import messages
from .patcher import setup_django, update_setting, update_urlconf


Expand Down Expand Up @@ -100,6 +101,8 @@ def apply_configuration(application_config: Dict[str, Any]):
update_urlconf(urlconf_file, application_config)
if verify_installation(django.conf.settings, application_config):
output_message(application_config.get("message", ""))
else:
output_message(messages["verify_error"].format(package=application_config.get("package-name")))


def enable_application(application: str, verbose: bool = False):
Expand Down
1 change: 1 addition & 0 deletions app_enabler/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
"no_managepy": "app-enabler must be executed in the same directory as the project manage.py file",
"install_error": "Package {package} not installable in the current virtualenv",
"enable_error": "Package {package} not installed in the current virtualenv",
"verify_error": "Error verifying {package} configuration",
}
17 changes: 17 additions & 0 deletions tests/test_enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from unittest.mock import patch

from app_enabler.enable import _verify_settings, _verify_urlconf, apply_configuration_set, enable_application
from app_enabler.errors import messages
from tests.utils import working_directory


Expand Down Expand Up @@ -53,6 +54,22 @@ def test_enable_minimal(capsys, pytester, project_dir, addon_config_minimal, tea
assert _verify_urlconf(imported, addon_config_minimal)


def test_verify_fail(capsys, pytester, project_dir, addon_config_minimal, blog_package, teardown_django):
"""Enabling application load the addon configuration in settings and urlconf - minimal addon config."""

with working_directory(project_dir), patch("app_enabler.enable.load_addon") as load_addon, patch(
"app_enabler.enable.verify_installation"
) as verify_installation:
load_addon.return_value = addon_config_minimal
verify_installation.return_value = False
os.environ["DJANGO_SETTINGS_MODULE"] = "test_project.settings"

enable_application("djangocms_blog")

captured = capsys.readouterr()
assert captured.out == messages["verify_error"].format(package="djangocms-blog")


def test_enable_no_application(pytester, project_dir, addon_config, teardown_django):
"""Enabling application with empty addon configuration does not alter the configuration."""

Expand Down

0 comments on commit d94ab7f

Please sign in to comment.