-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tests to account for registry finickiness.
- Loading branch information
Showing
3 changed files
with
124 additions
and
94 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,112 @@ | ||
""" | ||
Tests for `kolibri.utils.cli` module. | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
|
||
import tempfile | ||
|
||
import pytest | ||
|
||
from kolibri.plugins.utils import autoremove_unavailable_plugins | ||
from kolibri.utils import cli | ||
|
||
|
||
@pytest.fixture | ||
def plugins(): | ||
from kolibri import plugins | ||
|
||
_, config_file = tempfile.mkstemp(suffix="json") | ||
old_config_file = plugins.conf_file | ||
plugins.conf_file = config_file | ||
plugins.config.set_defaults() | ||
yield plugins | ||
plugins.conf_file = old_config_file | ||
|
||
|
||
def test_bogus_plugin_autoremove(plugins): | ||
""" | ||
Checks that a plugin is auto-removed when it cannot be imported | ||
""" | ||
plugin_name = "giraffe.horse" | ||
plugins.config["INSTALLED_PLUGINS"].add(plugin_name) | ||
plugins.config.save() | ||
autoremove_unavailable_plugins() | ||
assert plugin_name not in plugins.config["INSTALLED_PLUGINS"] | ||
|
||
|
||
def test_bogus_plugin_autoremove_no_path(plugins): | ||
""" | ||
Checks that a plugin without a dotted path is also auto-removed | ||
""" | ||
plugin_name = "giraffehorse" | ||
plugins.config["INSTALLED_PLUGINS"].add(plugin_name) | ||
plugins.config.save() | ||
autoremove_unavailable_plugins() | ||
assert plugin_name not in plugins.config["INSTALLED_PLUGINS"] | ||
|
||
|
||
def test_bogus_plugin_disable(plugins): | ||
installed_apps_before = plugins.config["INSTALLED_PLUGINS"].copy() | ||
disabled_apps_before = plugins.config["DISABLED_PLUGINS"].copy() | ||
try: | ||
cli.disable.callback(("i_do_not_exist",), False) | ||
except Exception: | ||
pass | ||
assert installed_apps_before == plugins.config["INSTALLED_PLUGINS"] | ||
assert disabled_apps_before == plugins.config["DISABLED_PLUGINS"] | ||
|
||
|
||
def test_plugin_cannot_be_imported_disable(plugins): | ||
""" | ||
A plugin may be in plugins.config['INSTALLED_PLUGINS'] but broken or uninstalled | ||
""" | ||
plugin_name = "giraffe.horse" | ||
plugins.config["INSTALLED_PLUGINS"].add(plugin_name) | ||
plugins.config.save() | ||
try: | ||
cli.disable.callback((plugin_name,), False) | ||
except Exception: | ||
pass | ||
assert plugin_name not in plugins.config["INSTALLED_PLUGINS"] | ||
# We also don't want to endlessly add cruft to the disabled apps | ||
assert plugin_name not in plugins.config["DISABLED_PLUGINS"] | ||
|
||
|
||
def test_real_plugin_disable(plugins): | ||
installed_apps_before = plugins.config["INSTALLED_PLUGINS"].copy() | ||
test_plugin = "kolibri.plugins.media_player" | ||
assert test_plugin in installed_apps_before | ||
# Because RIP example plugin | ||
cli.disable.callback((test_plugin,), False) | ||
assert test_plugin not in plugins.config["INSTALLED_PLUGINS"] | ||
assert test_plugin in plugins.config["DISABLED_PLUGINS"] | ||
|
||
|
||
def test_real_plugin_disable_twice(plugins): | ||
installed_apps_before = plugins.config["INSTALLED_PLUGINS"].copy() | ||
test_plugin = "kolibri.plugins.media_player" | ||
assert test_plugin in installed_apps_before | ||
cli.disable.callback((test_plugin,), False) | ||
assert test_plugin not in plugins.config.ACTIVE_PLUGINS | ||
assert test_plugin not in plugins.config["INSTALLED_PLUGINS"] | ||
assert test_plugin in plugins.config["DISABLED_PLUGINS"] | ||
installed_apps_before = plugins.config["INSTALLED_PLUGINS"].copy() | ||
cli.disable.callback((test_plugin,), False) | ||
assert test_plugin not in plugins.config.ACTIVE_PLUGINS | ||
assert test_plugin not in plugins.config["INSTALLED_PLUGINS"] | ||
assert test_plugin in plugins.config["DISABLED_PLUGINS"] | ||
|
||
|
||
def test_plugin_with_no_plugin_class(plugins): | ||
""" | ||
Expected behavior is that nothing blows up with exceptions, user just gets | ||
a warning and nothing is enabled or changed in the configuration. | ||
""" | ||
# For fun, we pass in a system library | ||
installed_apps_before = plugins.config["INSTALLED_PLUGINS"].copy() | ||
try: | ||
cli.enable.callback(("os.path",), False) | ||
except Exception: | ||
pass | ||
assert installed_apps_before == plugins.config["INSTALLED_PLUGINS"] |