Exemplo n.º 1
0
def test_workspacelog_search_by_id(rf):
    workspace = WorkspaceFactory()
    user = UserFactory()

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

    JobFactory(job_request=JobRequestFactory())

    job_request2 = JobRequestFactory(created_by=user, workspace=workspace)
    JobFactory(job_request=job_request2, id=99)

    request = rf.get("/?q=99")
    request.user = user

    response = WorkspaceLog.as_view()(
        request,
        org_slug=workspace.project.org.slug,
        project_slug=workspace.project.slug,
        workspace_slug=workspace.name,
    )

    assert len(response.context_data["object_list"]) == 1
    assert response.context_data["object_list"][0] == job_request2
Exemplo n.º 2
0
def test_workspacelog_filter_by_one_backend(rf):
    workspace = WorkspaceFactory()
    user = UserFactory()

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

    backend = BackendFactory()
    job_request1 = JobRequestFactory(workspace=workspace, backend=backend)

    JobRequestFactory(workspace=workspace, backend=BackendFactory())

    request = rf.get(f"/?backend={backend.slug}")
    request.user = user

    response = WorkspaceLog.as_view()(
        request,
        org_slug=workspace.project.org.slug,
        project_slug=workspace.project.slug,
        workspace_slug=workspace.name,
    )

    assert len(response.context_data["object_list"]) == 1
    assert response.context_data["object_list"][0] == job_request1
def test_workspacelog_unknown_workspace(rf):
    # Build a RequestFactory instance
    request = rf.get(MEANINGLESS_URL)
    request.user = UserFactory()
    response = WorkspaceLog.as_view()(request, name="test")

    assert response.status_code == 302
    assert response.url == "/"
def test_workspacelog_with_unauthenticated_user(rf):
    """
    Check WorkspaceLog renders the Add Job button for authenticated Users
    """
    workspace = WorkspaceFactory()
    job_request = JobRequestFactory(workspace=workspace)
    JobFactory(job_request=job_request)

    # Build a RequestFactory instance
    request = rf.get(MEANINGLESS_URL)
    request.user = AnonymousUser()
    response = WorkspaceLog.as_view()(request, name=workspace.name)

    assert response.status_code == 200
    assert "Add Job" not in response.rendered_content
Exemplo n.º 5
0
def test_workspacelog_with_authenticated_user(rf):
    workspace = WorkspaceFactory()
    job_request = JobRequestFactory(workspace=workspace)
    JobFactory(job_request=job_request)

    request = rf.get("/")
    request.user = UserFactory()

    response = WorkspaceLog.as_view()(
        request,
        org_slug=workspace.project.org.slug,
        project_slug=workspace.project.slug,
        workspace_slug=workspace.name,
    )

    assert response.status_code == 200
def test_workspacelog_success(rf):
    workspace = WorkspaceFactory()
    user = UserFactory()
    job_request = JobRequestFactory(created_by=user, workspace=workspace)
    JobFactory(job_request=job_request)

    # Build a RequestFactory instance
    request = rf.get(MEANINGLESS_URL)
    request.user = user

    with patch("jobserver.views.workspaces.can_run_jobs",
               return_value=True,
               autospec=True):
        response = WorkspaceLog.as_view()(request, name=workspace.name)

    assert response.status_code == 200
    assert len(response.context_data["object_list"]) == 1
Exemplo n.º 7
0
def test_workspacelog_unknown_workspace(rf):
    project = ProjectFactory()
    user = UserFactory()

    ProjectMembershipFactory(project=project, user=user, roles=[ProjectDeveloper])

    request = rf.get("/")
    request.user = user

    response = WorkspaceLog.as_view()(
        request,
        org_slug=project.org.slug,
        project_slug=project.slug,
        workspace_slug="test",
    )

    assert response.status_code == 302
    assert response.url == "/"
def test_workspacelog_with_authenticated_user(rf):
    """
    Check WorkspaceLog renders the Add Job button for authenticated Users
    """
    workspace = WorkspaceFactory()
    job_request = JobRequestFactory(workspace=workspace)
    JobFactory(job_request=job_request)

    # Build a RequestFactory instance
    request = rf.get(MEANINGLESS_URL)
    request.user = UserFactory()

    with patch("jobserver.views.workspaces.can_run_jobs",
               return_value=True,
               autospec=True):
        response = WorkspaceLog.as_view()(request, name=workspace.name)

    assert response.status_code == 200
    assert "Add Job" in response.rendered_content
def test_workspacelog_search_by_id(rf):
    workspace = WorkspaceFactory()
    user = UserFactory()

    JobFactory(job_request=JobRequestFactory())

    job_request2 = JobRequestFactory(created_by=user, workspace=workspace)
    JobFactory(job_request=job_request2, id=99)

    # Build a RequestFactory instance
    request = rf.get("/?q=99")
    request.user = user

    with patch("jobserver.views.workspaces.can_run_jobs",
               return_value=True,
               autospec=True):
        response = WorkspaceLog.as_view()(request, name=workspace.name)

    assert len(response.context_data["object_list"]) == 1
    assert response.context_data["object_list"][0] == job_request2
Exemplo n.º 10
0
def test_workspacelog_success(rf):
    workspace = WorkspaceFactory()
    user = UserFactory()

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

    job_request = JobRequestFactory(created_by=user, workspace=workspace)
    JobFactory(job_request=job_request)

    request = rf.get("/")
    request.user = user

    response = WorkspaceLog.as_view()(
        request,
        org_slug=workspace.project.org.slug,
        project_slug=workspace.project.slug,
        workspace_slug=workspace.name,
    )

    assert response.status_code == 200
    assert len(response.context_data["object_list"]) == 1
Exemplo n.º 11
0
def test_workspacelog_filter_by_several_backends(rf):
    workspace = WorkspaceFactory()
    user = UserFactory()

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

    JobRequestFactory(workspace=workspace, backend=BackendFactory())

    backend1 = BackendFactory()
    job_request1 = JobRequestFactory(workspace=workspace, backend=backend1)

    backend2 = BackendFactory()
    job_request2 = JobRequestFactory(workspace=workspace, backend=backend2)

    backend3 = BackendFactory()
    job_request3 = JobRequestFactory(workspace=workspace, backend=backend3)

    request = rf.get(
        f"/?backend={backend1.slug}&backend={backend2.slug}&backend={backend3.slug}"
    )
    request.user = user

    response = WorkspaceLog.as_view()(
        request,
        org_slug=workspace.project.org.slug,
        project_slug=workspace.project.slug,
        workspace_slug=workspace.name,
    )

    assert len(response.context_data["object_list"]) == 3
    assert set(response.context_data["object_list"]) == {
        job_request1,
        job_request2,
        job_request3,
    }