Example #1
0
    def test_moment_from_cdn_with_custom_sri_hash(self):
        include_moment = _moment.include_moment(sri='sha384-12345678')

        assert include_moment.startswith(
            '<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/{}'
            '/moment-with-locales.min.js" integrity="sha384-12345678" '
            'crossorigin="anonymous"></script>'.format(default_moment_version))

        include_moment = _moment.include_moment(version='2.0.0',
                                                sri='sha384-12345678')

        assert include_moment.startswith(
            '<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.0.0'
            '/moment-with-langs.min.js" integrity="sha384-12345678" '
            'crossorigin="anonymous"></script>')
    def test_moment_from_cdn_with_custom_sri_hash(self):
        include_moment = _moment.include_moment(sri='sha384-12345678')

        assert include_moment.startswith(
            '<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/{}'
            '/moment-with-locales.min.js" integrity="sha384-12345678" '
            'crossorigin="anonymous"></script>'.format(default_moment_version))

        include_moment = _moment.include_moment(version='2.0.0',
                                                sri='sha384-12345678')

        assert include_moment.startswith(
            '<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.0.0'
            '/moment-with-langs.min.js" integrity="sha384-12345678" '
            'crossorigin="anonymous"></script>')
Example #3
0
    def test_include_moment_with_local_js_directly(self):
        include_moment = _moment.include_moment(
            local_js="/path/to/local/moment.js")

        assert isinstance(include_moment, Markup)
        assert "<script src=\"/path/to/local/moment.js\"></script>" in str(
            include_moment)
    def test_include_moment_with_local_js_directly(self):
        include_moment = _moment.include_moment(
            local_js="/path/to/local/moment.js")

        assert isinstance(include_moment, Markup)
        assert "<script src=\"/path/to/local/moment.js\"></script>" in str(
            include_moment)
Example #5
0
    def test_moment_with_non_default_versions(self):
        include_moment = None

        def _check_assertions():
            assert 'src=\"' in include_moment
            assert 'integrity=\"' not in include_moment
            assert 'crossorigin\"' not in include_moment

        include_moment = _moment.include_moment(version='2.8.0')
        _check_assertions()
        include_moment = _moment.include_moment(version='2.3.1')
        _check_assertions()
        include_moment = _moment.include_moment(version='2.16.8')
        _check_assertions()
        include_moment = _moment.include_moment(version='2.30.1')
        _check_assertions()
Example #6
0
    def test_moment_local_with_sri(self):
        include_moment = _moment.include_moment(local_js=True,
                                                sri='sha384-87654321')

        assert 'src=\"' in include_moment
        assert 'integrity=\"sha384-87654321\"' in include_moment
        assert 'crossorigin=\"anonymous\"' in include_moment
    def test_include_moment_directly(self):
        include_moment = _moment.include_moment()

        assert isinstance(include_moment, Markup)
        assert "<script" in str(include_moment)
        assert default_moment_version + "/moment-with-locales.min.js" in str(
            include_moment)
    def test_moment_local_with_sri(self):
        include_moment = _moment.include_moment(local_js=True,
                                                sri='sha384-87654321')

        assert 'src=\"' in include_moment
        assert 'integrity=\"sha384-87654321\"' in include_moment
        assert 'crossorigin=\"anonymous\"' in include_moment
    def test_moment_with_non_default_versions(self):
        include_moment = None

        def _check_assertions():
            assert 'src=\"' in include_moment
            assert 'integrity=\"' not in include_moment
            assert 'crossorigin\"' not in include_moment

        include_moment = _moment.include_moment(version='2.8.0')
        _check_assertions()
        include_moment = _moment.include_moment(version='2.3.1')
        _check_assertions()
        include_moment = _moment.include_moment(version='2.16.8')
        _check_assertions()
        include_moment = _moment.include_moment(version='2.30.1')
        _check_assertions()
Example #10
0
    def test_include_moment_directly(self):
        include_moment = _moment.include_moment()

        assert isinstance(include_moment, Markup)
        assert "<script" in str(include_moment)
        assert default_moment_version + "/moment-with-locales.min.js" in str(
            include_moment)
Example #11
0
    def test_moment_with_default_version(self):
        include_moment = _moment.include_moment()

        assert include_moment.startswith(
            '<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/{}'
            '/moment-with-locales.min.js" integrity="{}" '
            'crossorigin="anonymous"></script>'.format(default_moment_version,
                                                       default_moment_sri))
    def test_moment_with_default_version(self):
        include_moment = _moment.include_moment()

        assert include_moment.startswith(
            '<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/{}'
            '/moment-with-locales.min.js" integrity="{}" '
            'crossorigin="anonymous"></script>'.format(
                default_moment_version, default_moment_sri))
    def test_include_moment_with_different_version_directly(self):
        include_moment = _moment.include_moment(version="2.17.1")

        assert isinstance(include_moment, Markup)
        assert "<script" in str(include_moment)
        assert "2.17.1/moment-with-locales.min.js" in str(include_moment)
    def test_disabling_moment_custom_version(self):
        include_moment = _moment.include_moment(version='2.17.9', sri=False)

        assert 'src=\"' in include_moment
        assert 'integrity=\"' not in include_moment
        assert 'crossorigin' not in include_moment
    def test_disabling_moment_custom(self):
        include_moment = _moment.include_moment(local_js=True, sri=False)

        assert 'src=\"' in include_moment
        assert 'integrity=\"' not in include_moment
        assert 'crossorigin' not in include_moment
    def test_disabling_moment_default(self):
        include_moment = _moment.include_moment(sri=False)

        assert 'src=\"' in include_moment
        assert 'integrity=\"' not in include_moment
        assert 'crossorigin' not in include_moment
Example #17
0
    def test_include_moment_with_different_version_directly(self):
        include_moment = _moment.include_moment(version="2.17.1")

        assert isinstance(include_moment, Markup)
        assert "<script" in str(include_moment)
        assert "2.17.1/moment-with-locales.min.js" in str(include_moment)
Example #18
0
    def test_disabling_moment_custom_version(self):
        include_moment = _moment.include_moment(version='2.17.9', sri=False)

        assert 'src=\"' in include_moment
        assert 'integrity=\"' not in include_moment
        assert 'crossorigin' not in include_moment
Example #19
0
    def test_disabling_moment_custom(self):
        include_moment = _moment.include_moment(local_js=True, sri=False)

        assert 'src=\"' in include_moment
        assert 'integrity=\"' not in include_moment
        assert 'crossorigin' not in include_moment
Example #20
0
    def test_disabling_moment_default(self):
        include_moment = _moment.include_moment(sri=False)

        assert 'src=\"' in include_moment
        assert 'integrity=\"' not in include_moment
        assert 'crossorigin' not in include_moment
    def test_moment_local(self):
        include_moment = _moment.include_moment(local_js=True)

        assert 'src=\"' in include_moment
        assert 'integrity=\"' not in include_moment
        assert 'crossorigin\"' not in include_moment
Example #22
0
    def test_moment_local(self):
        include_moment = _moment.include_moment(local_js=True)

        assert 'src=\"' in include_moment
        assert 'integrity=\"' not in include_moment
        assert 'crossorigin\"' not in include_moment