Beispiel #1
0
def test_upload_file_conflict_directory(mount, context):
    root = Path(mount.backend.root)
    path = context.path
    fname = "baz"
    (root / path / fname).mkdir(parents=True)
    request = DummyRequest(
        params={
            "content": Upload("frob", b"frob\n"),
            "filename": fname,
        }
    )
    resp = upload_file_view(context, request)
    assert isinstance(resp, HTTPConflict)
Beispiel #2
0
def test_upload_file_destname(mount, context):
    root = Path(mount.backend.root)
    path = context.path
    content = b"frob\n"
    fname = "baz"
    request = DummyRequest(
        params={
            "content": Upload("frob", content),
            "filename": fname,
        }
    )
    resp = upload_file_view(context, request)
    assert isinstance(resp, HTTPSeeOther)
    respath = root / path / fname
    assert respath.is_file()
    with respath.open("rb") as f:
        assert f.read() == content
Beispiel #3
0
def test_upload_file_replace_forbidden(testconfig, mount, context):
    sec_pol = DummySecurityPolicy(permissive=False)
    testconfig.set_authorization_policy(sec_pol)
    testconfig.set_authentication_policy(sec_pol)
    root = Path(mount.backend.root)
    path = context.path
    fname = "baz"
    respath = (root / path / fname)
    with respath.open("w"):
        pass
    request = DummyRequest(
        params={
            "content": Upload("frob", b"frob\n"),
            "filename": fname,
        }
    )
    resp = upload_file_view(context, request)
    assert isinstance(resp, HTTPForbidden)