Exemple #1
0
def test_snapshot_str():
    user = UserFactory()

    snapshot = SnapshotFactory(created_by=user, published_at=timezone.now())
    assert str(snapshot) == f"Published Snapshot made by {user.username}"

    snapshot = SnapshotFactory(created_by=user)
    assert str(snapshot) == f"Draft Snapshot made by {user.username}"
Exemple #2
0
def test_snapshot_get_publish_api_url():
    snapshot = SnapshotFactory()

    url = snapshot.get_publish_api_url()

    assert url == reverse(
        "api:snapshot-publish",
        kwargs={
            "workspace_id": snapshot.workspace.name,
            "snapshot_id": snapshot.pk,
        },
    )
Exemple #3
0
def test_snapshot_get_download_url():
    snapshot = SnapshotFactory()

    url = snapshot.get_download_url()

    assert url == reverse(
        "workspace-snapshot-download",
        kwargs={
            "org_slug": snapshot.workspace.project.org.slug,
            "project_slug": snapshot.workspace.project.slug,
            "workspace_slug": snapshot.workspace.name,
            "pk": snapshot.pk,
        },
    )
Exemple #4
0
def test_snapshotpublishapi_success(api_rf):
    snapshot = SnapshotFactory()

    assert snapshot.is_draft

    request = api_rf.post("/")
    request.user = UserFactory(roles=[OutputPublisher])

    response = SnapshotPublishAPI.as_view()(
        request,
        workspace_id=snapshot.workspace.name,
        snapshot_id=snapshot.pk,
    )

    assert response.status_code == 200

    snapshot.refresh_from_db()
    assert snapshot.is_published
Exemple #5
0
def test_snapshotapi_unpublished_with_anonymous_user(api_rf):
    snapshot = SnapshotFactory(published_at=None)

    request = api_rf.get("/")

    response = SnapshotAPI.as_view()(
        request,
        workspace_id=snapshot.workspace.name,
        snapshot_id=snapshot.pk,
    )

    assert response.status_code == 403
Exemple #6
0
def test_snapshotapi_unpublished_without_permission(api_rf):
    snapshot = SnapshotFactory(published_at=None)

    request = api_rf.get("/")
    request.user = UserFactory()  # logged in, but no permission

    response = SnapshotAPI.as_view()(
        request,
        workspace_id=snapshot.workspace.name,
        snapshot_id=snapshot.pk,
    )

    assert response.status_code == 403
Exemple #7
0
def test_snapshotapi_published_with_anonymous_user(api_rf, freezer):
    snapshot = SnapshotFactory(published_at=timezone.now())

    request = api_rf.get("/")

    response = SnapshotAPI.as_view()(
        request,
        workspace_id=snapshot.workspace.name,
        snapshot_id=snapshot.pk,
    )

    assert response.status_code == 200
    assert response.data == {"files": []}
Exemple #8
0
def test_snapshotpublishapi_without_permission(api_rf):
    snapshot = SnapshotFactory()

    request = api_rf.post("/")
    request.user = UserFactory()

    response = SnapshotPublishAPI.as_view()(
        request,
        workspace_id=snapshot.workspace.name,
        snapshot_id=snapshot.pk,
    )

    assert response.status_code == 403
Exemple #9
0
def test_snapshotapi_unpublished_with_permission(api_rf):
    snapshot = SnapshotFactory(published_at=None)

    request = api_rf.get("/")
    request.user = UserFactory(roles=[ProjectCollaborator])

    response = SnapshotAPI.as_view()(
        request,
        workspace_id=snapshot.workspace.name,
        snapshot_id=snapshot.pk,
    )

    assert response.status_code == 200
    assert response.data == {"files": []}
Exemple #10
0
def test_snapshotapi_published_without_permission(api_rf):
    snapshot = SnapshotFactory(published_at=timezone.now())

    request = api_rf.get("/")
    request.user = UserFactory()  # logged in, but no permission

    response = SnapshotAPI.as_view()(
        request,
        workspace_id=snapshot.workspace.name,
        snapshot_id=snapshot.pk,
    )

    assert response.status_code == 200
    assert response.data == {"files": []}
Exemple #11
0
def test_snapshotcreate_with_existing_snapshot(api_rf, build_release_with_files):
    workspace = WorkspaceFactory()
    release = build_release_with_files(["file1.txt"])
    snapshot = SnapshotFactory(workspace=workspace)
    snapshot.files.set(release.files.all())

    user = UserFactory()
    ProjectMembershipFactory(
        project=workspace.project, user=user, roles=[ProjectDeveloper]
    )

    request = api_rf.post("/", data={"file_ids": [release.files.first().pk]})
    request.user = user

    response = SnapshotCreateAPI.as_view()(request, workspace_id=workspace.name)

    assert response.status_code == 400, response.data

    msg = "A release with the current files already exists"
    assert msg in response.data["detail"], response.data
Exemple #12
0
def test_snapshot_is_published():
    assert SnapshotFactory(published_at=timezone.now()).is_published
Exemple #13
0
def test_snapshot_is_draft():
    assert SnapshotFactory(published_at=None).is_draft