Beispiel #1
0
def test_library_url_hashing_norecompute(tmpdir):
    foo = Library('foo', tmpdir.strpath)

    needed = NeededResources(versioning=True, recompute_hashes=False)

    url = needed.library_url(foo)

    # now create a file
    resource = tmpdir.join('test.js')
    resource.write('/* test */')

    # since we're not re-computing hashes, the hash in the URL won't change
    assert needed.library_url(foo) == url
Beispiel #2
0
def test_library_url_hashing_norecompute(tmpdir):
    foo = Library('foo', tmpdir.strpath)

    needed = NeededResources(versioning=True, recompute_hashes=False)

    url = needed.library_url(foo)

    # now create a file
    resource = tmpdir.join('test.js')
    resource.write('/* test */')

    # since we're not re-computing hashes, the hash in the URL won't change
    assert needed.library_url(foo) == url
Beispiel #3
0
def test_library_url_base_url():
    foo = Library('foo', '')

    needed = NeededResources(base_url="http://example.com/something")

    assert (needed.library_url(foo) ==
            'http://example.com/something/fanstatic/foo')
Beispiel #4
0
def test_library_url_version_hashing(tmpdir):
    foo = Library('foo', tmpdir.strpath)

    needed = NeededResources(versioning=True)
    url = needed.library_url(foo)
    assert re.match('/fanstatic/foo/:version:[0-9T:.-]*$', url)

    # The md5 based version URL is available through the
    # `versioning_use_md5` parameter:
    needed = NeededResources(versioning=True, versioning_use_md5=True)
    md5_url = needed.library_url(foo)
    assert url != md5_url

    # If the Library defines a version, the version is used.
    bar = Library('bar', '', version='1')
    assert needed.library_url(bar) == '/fanstatic/bar/:version:1'
Beispiel #5
0
def test_library_url_version_hashing(tmpdir):
    foo = Library('foo', tmpdir.strpath)

    needed = NeededResources(versioning=True)
    url = needed.library_url(foo)
    assert re.match('/fanstatic/foo/:version:[0-9T:.-]*$', url)

    # The md5 based version URL is available through the
    # `versioning_use_md5` parameter:
    needed = NeededResources(versioning=True, versioning_use_md5=True)
    md5_url = needed.library_url(foo)
    assert url != md5_url

    # If the Library defines a version, the version is used.
    bar = Library('bar', '', version='1')
    assert needed.library_url(bar) == '/fanstatic/bar/:version:1'
Beispiel #6
0
def test_library_url_base_url():
    foo = Library('foo', '')

    needed = NeededResources(base_url="http://example.com/something")

    assert (needed.library_url(foo) ==
            'http://example.com/something/fanstatic/foo')
Beispiel #7
0
def test_library_url_script_name_base_url():
    foo = Library('foo', '')
    needed = NeededResources(script_name='/root',
                             base_url="http://example.com/something")

    # base_url is set so script_name should be ignored
    assert (needed.library_url(foo) ==
            'http://example.com/something/fanstatic/foo')
Beispiel #8
0
def test_library_url_script_name_base_url():
    foo = Library('foo', '')
    needed = NeededResources(
        script_name='/root', base_url="http://example.com/something")

    # base_url is set so script_name should be ignored
    assert (needed.library_url(foo) ==
            'http://example.com/something/fanstatic/foo')
Beispiel #9
0
def test_library_url_hashing_recompute(tmpdir):
    foo = Library('foo', tmpdir.strpath)

    needed = NeededResources(versioning=True, recompute_hashes=True)

    url = needed.library_url(foo)

    # now create a file
    resource = tmpdir.join('test.js')

    time.sleep(0.02)
    # Sleep extra long on filesystems that report in seconds
    # instead of milliseconds.
    if os.path.getmtime(os.curdir).is_integer():
        time.sleep(1)
    resource.write('/* test */')

    # the hash is recalculated now, so it changes
    assert needed.library_url(foo) != url
Beispiel #10
0
def test_library_url_hashing_recompute(tmpdir):
    foo = Library('foo', tmpdir.strpath)

    needed = NeededResources(versioning=True, recompute_hashes=True)

    url = needed.library_url(foo)

    # now create a file
    resource = tmpdir.join('test.js')

    time.sleep(0.02)
    # Sleep extra long on filesystems that report in seconds
    # instead of milliseconds.
    if os.path.getmtime(os.curdir).is_integer():
        time.sleep(1)
    resource.write('/* test */')

    # the hash is recalculated now, so it changes
    assert needed.library_url(foo) != url
Beispiel #11
0
def test_library_url_with_url_caching(tmpdir):
    foo = Library('foo', tmpdir.strpath)

    needed = NeededResources(versioning=True, recompute_hashes=True)

    url = needed.library_url(foo)

    # now create a file
    resource = tmpdir.join('test.js')

    time.sleep(0.5)
    # Sleep extra long on filesystems that report in seconds
    # instead of milliseconds.
    if os.path.getmtime(os.curdir).is_integer():
        time.sleep(1)
    resource.write('/* test */')

    # The url is cached on the needed resources object.
    assert needed.library_url(foo) == url
Beispiel #12
0
def test_library_url_publisher_signature():
    foo = Library('foo', '')

    needed = NeededResources(publisher_signature='waku')

    assert needed.library_url(foo) == '/waku/foo'
Beispiel #13
0
def test_library_url_script_name():
    foo = Library('foo', '')
    needed = NeededResources(script_name='/root')
    assert needed.library_url(foo) == '/root/fanstatic/foo'
Beispiel #14
0
def test_library_url_default_publisher_signature():
    foo = Library('foo', '')

    needed = NeededResources()

    assert needed.library_url(foo) == '/fanstatic/foo'
Beispiel #15
0
def test_library_url_publisher_signature():
    foo = Library('foo', '')

    needed = NeededResources(publisher_signature='waku')

    assert needed.library_url(foo) == '/waku/foo'
Beispiel #16
0
def test_library_url_default_publisher_signature():
    foo = Library('foo', '')

    needed = NeededResources()

    assert needed.library_url(foo) == '/fanstatic/foo'
Beispiel #17
0
def test_library_url_script_name():
    foo = Library('foo', '')
    needed = NeededResources(script_name='/root')
    assert needed.library_url(foo) == '/root/fanstatic/foo'