Exemplo n.º 1
0
def test_raw_code_sample_file(
    code_sample_doc, constance_config, wiki_user, admin_client, settings
):

    # Upload an attachment
    upload_url = reverse(
        "attachments.edit_attachment", kwargs={"document_path": code_sample_doc.slug}
    )
    file_for_upload = make_test_file(content="Something something unique")
    post_data = {
        "title": "An uploaded file",
        "description": "A unique experience for your file serving needs.",
        "comment": "Yadda yadda yadda",
        "file": file_for_upload,
    }
    constance_config.WIKI_ATTACHMENT_ALLOWED_TYPES = "text/plain"
    response = admin_client.post(
        upload_url, data=post_data, HTTP_HOST=settings.WIKI_HOST
    )
    assert response.status_code == 302
    edit_url = reverse("wiki.edit", args=(code_sample_doc.slug,))
    assert response.url == edit_url

    # Add a relative reference to the sample content
    attachment = Attachment.objects.get(title="An uploaded file")
    filename = attachment.current_revision.filename
    url_css = 'url("files/%(attachment_id)s/%(filename)s")' % {
        "attachment_id": attachment.id,
        "filename": filename,
    }
    new_content = code_sample_doc.current_revision.content.replace(
        "color: red", url_css
    )
    code_sample_doc.current_revision = Revision.objects.create(
        document=code_sample_doc, creator=wiki_user, content=new_content
    )
    code_sample_doc.save()

    # URL is in the sample
    sample_url = reverse("wiki.code_sample", args=[code_sample_doc.slug, "sample1"])

    settings.ATTACHMENT_HOST = "testserver"
    response = admin_client.get(sample_url)
    assert response.status_code == 200
    assert url_css.encode() in response.content
    assert "public" in response["Cache-Control"]
    assert "max-age=86400" in response["Cache-Control"]

    # Getting the URL redirects to the attachment
    file_url = reverse(
        "wiki.raw_code_sample_file",
        args=(code_sample_doc.slug, "sample1", attachment.id, filename),
    )
    response = admin_client.get(file_url)
    assert response.status_code == 302
    assert response.url == attachment.get_file_url()
    assert not response.has_header("Vary")
    assert "Cache-Control" in response
    assert "public" in response["Cache-Control"]
    assert "max-age=432000" in response["Cache-Control"]
Exemplo n.º 2
0
def test_raw_code_sample_file(code_sample_doc, constance_config, wiki_user,
                              admin_client):

    # Upload an attachment
    upload_url = reverse('attachments.edit_attachment',
                         locale='en-US',
                         kwargs={'document_path': code_sample_doc.slug})
    file_for_upload = make_test_file(content='Something something unique')
    post_data = {
        'title': 'An uploaded file',
        'description': 'A unique experience for your file serving needs.',
        'comment': 'Yadda yadda yadda',
        'file': file_for_upload,
    }
    constance_config.KUMA_WIKI_IFRAME_ALLOWED_HOSTS = '^.*testserver'
    constance_config.WIKI_ATTACHMENT_ALLOWED_TYPES = 'text/plain'
    response = admin_client.post(upload_url, data=post_data)
    assert response.status_code == 302
    edit_url = reverse('wiki.edit',
                       locale='en-US',
                       args=(code_sample_doc.slug, ))
    assert response.url == 'http://testserver' + edit_url

    # Add a relative reference to the sample content
    attachment = Attachment.objects.get(title='An uploaded file')
    filename = attachment.current_revision.filename
    url_css = 'url("files/%(attachment_id)s/%(filename)s")' % {
        'attachment_id': attachment.id,
        'filename': filename,
    }
    new_content = code_sample_doc.current_revision.content.replace(
        'color: red', url_css)
    code_sample_doc.current_revision = Revision.objects.create(
        document=code_sample_doc, creator=wiki_user, content=new_content)
    code_sample_doc.save()

    # URL is in the sample
    sample_url = reverse('wiki.code_sample',
                         locale='en-US',
                         args=[code_sample_doc.slug, 'sample1'])

    response = admin_client.get(sample_url)
    assert response.status_code == 200
    assert url_css in response.content
    assert 'public' in response['Cache-Control']
    assert 'max-age=86400' in response['Cache-Control']

    # Getting the URL redirects to the attachment
    file_url = reverse('wiki.raw_code_sample_file',
                       locale='en-US',
                       args=(code_sample_doc.slug, 'sample1', attachment.id,
                             filename))
    response = admin_client.get(file_url)
    assert response.status_code == 302
    assert response.url == attachment.get_file_url()
    assert not response.has_header('Vary')
    assert 'Cache-Control' in response
    assert 'public' in response['Cache-Control']
    assert 'max-age=432000' in response['Cache-Control']
Exemplo n.º 3
0
def test_raw_code_sample_file(code_sample_doc, constance_config,
                              wiki_user, admin_client):

    # Upload an attachment
    upload_url = reverse('attachments.edit_attachment', locale='en-US',
                         kwargs={'document_path': code_sample_doc.slug})
    file_for_upload = make_test_file(content='Something something unique')
    post_data = {
        'title': 'An uploaded file',
        'description': 'A unique experience for your file serving needs.',
        'comment': 'Yadda yadda yadda',
        'file': file_for_upload,
    }
    constance_config.KUMA_WIKI_IFRAME_ALLOWED_HOSTS = '^.*testserver'
    constance_config.WIKI_ATTACHMENT_ALLOWED_TYPES = 'text/plain'
    response = admin_client.post(upload_url, data=post_data)
    assert response.status_code == 302
    edit_url = reverse('wiki.edit', locale='en-US',
                       args=(code_sample_doc.slug,))
    assert response.url == 'http://testserver' + edit_url

    # Add a relative reference to the sample content
    attachment = Attachment.objects.get(title='An uploaded file')
    filename = attachment.current_revision.filename
    url_css = 'url("files/%(attachment_id)s/%(filename)s")' % {
        'attachment_id': attachment.id,
        'filename': filename,
    }
    new_content = code_sample_doc.current_revision.content.replace(
        'color: red', url_css)
    code_sample_doc.current_revision = Revision.objects.create(
        document=code_sample_doc, creator=wiki_user, content=new_content)
    code_sample_doc.save()

    # URL is in the sample
    sample_url = reverse('wiki.code_sample', locale='en-US',
                         args=[code_sample_doc.slug, 'sample1'])

    response = admin_client.get(sample_url)
    assert response.status_code == 200
    assert url_css in response.content
    assert 'public' in response['Cache-Control']
    assert 'max-age=86400' in response['Cache-Control']

    # Getting the URL redirects to the attachment
    file_url = reverse('wiki.raw_code_sample_file', locale='en-US',
                       args=(code_sample_doc.slug, 'sample1', attachment.id,
                             filename))
    response = admin_client.get(file_url)
    assert response.status_code == 302
    assert response.url == attachment.get_file_url()
    assert not response.has_header('Vary')
    assert 'Cache-Control' in response
    assert 'public' in response['Cache-Control']
    assert 'max-age=432000' in response['Cache-Control']