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}"
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, }, )
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, }, )
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
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
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
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": []}
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
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": []}
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": []}
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
def test_snapshot_is_published(): assert SnapshotFactory(published_at=timezone.now()).is_published
def test_snapshot_is_draft(): assert SnapshotFactory(published_at=None).is_draft