Exemplo n.º 1
0
def test_raw_file_if_modified_since(client, settings, file_attachment):
    settings.ATTACHMENT_HOST = 'demos'
    attachment = file_attachment['attachment']
    created = attachment.current_revision.created
    url = attachment.get_file_url()

    response = client.get(url,
                          HTTP_HOST=settings.ATTACHMENT_HOST,
                          HTTP_IF_MODIFIED_SINCE=convert_to_http_date(created))
    assert response.status_code == 304
    assert response['Last-Modified'] == convert_to_http_date(created)
    assert 'public' in response['Cache-Control']
    assert 'max-age=900' in response['Cache-Control']
Exemplo n.º 2
0
def test_raw_file_if_modified_since(client, settings, file_attachment):
    settings.ATTACHMENT_HOST = 'demos'
    attachment = file_attachment['attachment']
    created = attachment.current_revision.created
    url = attachment.get_file_url()

    response = client.get(
        url,
        HTTP_HOST=settings.ATTACHMENT_HOST,
        HTTP_IF_MODIFIED_SINCE=convert_to_http_date(created)
    )
    assert response.status_code == 304
    assert response['Last-Modified'] == convert_to_http_date(created)
    assert 'public' in response['Cache-Control']
    assert 'max-age=900' in response['Cache-Control']
Exemplo n.º 3
0
def test_raw_file_requires_attachment_host(client, settings, file_attachment):
    settings.ATTACHMENT_HOST = 'demos'
    attachment = file_attachment['attachment']
    created = attachment.current_revision.created
    url = attachment.get_file_url()

    # Force the HOST header to look like something other than "demos".
    response = client.get(url, HTTP_HOST='localhost')
    assert response.status_code == 301
    assert 'public' in response['Cache-Control']
    assert 'max-age=900' in response['Cache-Control']
    assert response['Location'] == url
    assert 'Vary' not in response

    response = client.get(
        url,
        HTTP_ACCEPT_ENCODING='gzip',
        HTTP_HOST=settings.ATTACHMENT_HOST
    )
    assert response.status_code == 200
    assert response.streaming
    assert response['x-frame-options'] == 'ALLOW-FROM %s' % settings.DOMAIN
    assert 'Last-Modified' in response
    assert response['Last-Modified'] == convert_to_http_date(created)
    assert 'Cache-Control' in response
    assert 'public' in response['Cache-Control']
    assert 'max-age=900' in response['Cache-Control']
    assert response['Content-Encoding'] == 'gzip'
    assert response['Vary'] == 'Accept-Encoding'
Exemplo n.º 4
0
def test_raw_file_requires_attachment_host(client, settings, file_attachment):
    settings.ATTACHMENT_HOST = 'demos'
    attachment = file_attachment['attachment']
    created = attachment.current_revision.created
    url = attachment.get_file_url()

    # Force the HOST header to look like something other than "demos".
    response = client.get(url, HTTP_HOST='localhost')
    assert response.status_code == 301
    assert response['Location'] == url
    assert 'Vary' not in response

    response = client.get(url,
                          HTTP_ACCEPT_ENCODING='gzip',
                          HTTP_HOST=settings.ATTACHMENT_HOST)
    assert response.status_code == 200
    assert response.streaming
    assert response['x-frame-options'] == 'ALLOW-FROM %s' % settings.DOMAIN
    assert 'Last-Modified' in response
    assert response['Last-Modified'] == convert_to_http_date(created)
    assert 'Cache-Control' in response
    assert 'public' in response['Cache-Control']
    assert 'max-age=900' in response['Cache-Control']
    assert response['Content-Encoding'] == 'gzip'
    assert response['Vary'] == 'Accept-Encoding'