-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loading of periodic tasks and clean up extension loading.
This does a few things: - add tests for extension loading - refactor the extension and periodic task loading - better handle assertions raised by extensions (e.g. when an extension tries to override an already registered view) - attach exception traceback to error log during loading for improved debugging
- Loading branch information
Showing
6 changed files
with
128 additions
and
37 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
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,15 @@ | ||
module_attribute = "hello!" | ||
|
||
|
||
def extension(app): | ||
"""This extension will work""" | ||
return "extension loaded" | ||
|
||
|
||
def assertive_extension(app): | ||
"""This extension won't work""" | ||
assert False | ||
|
||
|
||
def periodic_task(*args, **kwargs): | ||
"""This periodic task will successfully load""" |
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,23 @@ | ||
from setuptools import setup | ||
|
||
|
||
setup( | ||
name="redash-dummy", | ||
version="0.1", | ||
description="Redash extensions for testing", | ||
author="Redash authors", | ||
license="MIT", | ||
entry_points={ | ||
"redash.extensions": [ | ||
"working_extension = redash_dummy:extension", | ||
"non_callable_extension = redash_dummy:module_attribute", | ||
"not_findable_extension = redash_dummy:missing_attribute", | ||
"not_importable_extension = missing_extension_module:extension", | ||
"assertive_extension = redash_dummy:assertive_extension", | ||
], | ||
"redash.periodic_tasks": [ | ||
"dummy_periodic_task = redash_dummy:periodic_task" | ||
], | ||
}, | ||
py_modules=["redash_dummy"], | ||
) |
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,48 @@ | ||
import logging | ||
import os | ||
import subprocess | ||
|
||
from redash import extensions | ||
from tests import BaseTestCase | ||
|
||
logger = logging.getLogger(__name__) | ||
here = os.path.dirname(__file__) | ||
dummy_extension = "redash-dummy" | ||
|
||
|
||
class TestExtensions(BaseTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
dummy_path = os.path.join(here, dummy_extension) | ||
subprocess.call( | ||
["pip", "install", "--disable-pip-version-check", "--user", "--editable", dummy_path] | ||
) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
subprocess.call(["pip", "uninstall", "--yes", dummy_extension]) | ||
|
||
def test_working_extension(self): | ||
self.assertIn("working_extension", extensions.extensions.keys()) | ||
self.assertEqual( | ||
extensions.extensions.get("working_extension"), "extension loaded" | ||
) | ||
|
||
def test_assertive_extension(self): | ||
self.assertNotIn("assertive_extension", extensions.extensions.keys()) | ||
|
||
def test_not_findable_extension(self): | ||
self.assertNotIn("not_findable_extension", extensions.extensions.keys()) | ||
|
||
def test_not_importable_extension(self): | ||
self.assertNotIn("not_importable_extension", extensions.extensions.keys()) | ||
|
||
def test_non_callable_extension(self): | ||
self.assertNotIn("non_callable_extension", extensions.extensions.keys()) | ||
|
||
def test_dummy_periodic_task(self): | ||
# need to load the periodic tasks manually since this isn't | ||
# done automatically on test suite start but only part of | ||
# the worker configuration | ||
extensions.load_periodic_tasks(logger) | ||
self.assertIn("dummy_periodic_task", extensions.periodic_tasks.keys()) |