Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamic resources collection. #518

Merged
merged 8 commits into from
Jan 4, 2019
Merged

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Dec 27, 2018

Fixes #517

@T4rk1n T4rk1n requested a review from rmarren1 December 27, 2018 21:16
dash/dash.py Outdated Show resolved Hide resolved
@rmarren1
Copy link
Contributor

Was looking into this too. We were not testing external routes, and in fact the tests in tests.test_resources were commented out and passed. Consider adding the tests I wrote?

import unittest
import dash
import mock
import dash_core_components as dcc

_monkey_patched_js_dist = [
    {
        'external_url': 'https://external_javascript.js',
        'relative_package_path': 'external_javascript.js',
        'namespace': 'dash_core_components'
    },
    {
        'external_url': 'https://external_css.css',
        'relative_package_path': 'external_css.css',
        'namespace': 'dash_core_components'
    },
    {
        'relative_package_path': 'fake_dcc.js',
        'dev_package_path': 'fake_dcc.dev.js',
        'external_url': 'https://component_library.bundle.js',
        'namespace': 'dash_core_components'
    },
    {
        'relative_package_path': 'fake_dcc.min.js.map',
        'dev_package_path': 'fake_dcc.dev.js.map',
        'external_url': 'https://component_library.bundle.js.map',
        'namespace': 'dash_core_components',
        'dynamic': True
    }
]

dcc._js_dist = _monkey_patched_js_dist
dcc.__version__ = 1

class StatMock(object):
    st_mtime = 1

class Tests(unittest.TestCase):

    def test_external(self):
        app = dash.Dash(__name__, assets_folder='tests/assets', assets_ignore='load_after.+.js')
        app.layout = dcc.Markdown()
        app.scripts.config.serve_locally = False
        with mock.patch('dash.dash.os.stat', return_value=StatMock()):
            resource = app._collect_and_register_resources(app.scripts.get_all_scripts())
        assert resource == [
            'https://external_javascript.js',
            'https://external_css.css',
            'https://component_library.bundle.js'
        ]

    def test_internal(self):
        app = dash.Dash(__name__, assets_folder='tests/assets', assets_ignore='load_after.+.js')
        app.layout = dcc.Markdown()
        app.scripts.config.serve_locally = True
        with mock.patch('dash.dash.os.stat', return_value=StatMock()):
            with mock.patch('dash.dash.importlib.import_module', return_value=dcc):
                resource = app._collect_and_register_resources(app.scripts.get_all_scripts())
        assert resource == [
            '/_dash-component-suites/dash_core_components/external_javascript.js?v=1&m=1',
            '/_dash-component-suites/dash_core_components/external_css.css?v=1&m=1',
            '/_dash-component-suites/dash_core_components/fake_dcc.js?v=1&m=1'
        ]

@T4rk1n T4rk1n changed the title Always skip dynamic from index resources collection. [WIP] Fix dynamic resources collection. Dec 27, 2018
@T4rk1n
Copy link
Contributor Author

T4rk1n commented Dec 28, 2018

@rmarren1 Thanks for the test, please review.

@T4rk1n T4rk1n changed the title [WIP] Fix dynamic resources collection. Fix dynamic resources collection. Dec 28, 2018
Copy link
Contributor

@rmarren1 rmarren1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@T4rk1n T4rk1n merged commit 2c182b1 into master Jan 4, 2019
@T4rk1n T4rk1n deleted the fix-dynamic-external-url branch January 4, 2019 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants