Skip to content

Commit

Permalink
fix: Adjust test accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik003 committed Oct 10, 2023
1 parent ab345aa commit 2245cf4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 75 deletions.
2 changes: 1 addition & 1 deletion backend/capellacollab/projects/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def update_project(
patch_project: models.PatchProject,
) -> models.DatabaseProject:
if patch_project.name:
patch_project.name = slugify.slugify(patch_project.name)
project.slug = slugify.slugify(patch_project.name)

database.patch_database_with_pydantic_object(project, patch_project)

Expand Down
149 changes: 75 additions & 74 deletions backend/tests/projects/test_projects_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def test_get_projects_not_authenticated(client: testclient.TestClient):
assert response.json() == {"detail": "Not authenticated"}


def test_get_projects_as_user_only_shows_default_internal_project(
def test_get_internal_default_project_as_user(
client: testclient.TestClient, db: orm.Session, executor_name: str
):
users_crud.create_user(db, executor_name, users_models.Role.USER)

response = client.get("/api/v1/projects")
response = client.get("/api/v1/projects/default")

assert response.status_code == 200
assert {
Expand All @@ -34,7 +34,24 @@ def test_get_projects_as_user_only_shows_default_internal_project(
"description": "",
"visibility": "internal",
"users": {"leads": 0, "contributors": 0, "subscribers": 0},
} in response.json()
"is_archived": False,
} == response.json()


def test_get_projects_as_user_only_shows_default_internal_project(
client: testclient.TestClient, db: orm.Session, executor_name: str
):
users_crud.create_user(db, executor_name, users_models.Role.USER)

response = client.get("/api/v1/projects")

assert response.status_code == 200

data = response.json()

assert len(data) == 1
assert data[0]["slug"] == "default"
assert data[0]["visibility"] == "internal"


@pytest.mark.usefixtures("project_manager")
Expand All @@ -44,47 +61,50 @@ def test_get_projects_as_user_with_project(
response = client.get("/api/v1/projects")

assert response.status_code == 200
assert {
"name": project.name,
"slug": project.slug,
"description": "",
"visibility": "private",
"users": {"leads": 1, "contributors": 0, "subscribers": 0},
} in response.json()

data = response.json()

assert len(data) == 2
assert data[0]["slug"] == project.slug
assert data[0]["visibility"] == "private"


def test_get_projects_as_admin(
client: testclient.TestClient, db: orm.Session, executor_name: str
):
project = projects_crud.create_project(
db, "test project", visibility=projects_models.Visibility.PRIVATE
)
users_crud.create_user(db, executor_name, users_models.Role.ADMIN)

response = client.get("/api/v1/projects")

assert response.status_code == 200
assert {
"name": "default",
"slug": "default",
"description": "",
"visibility": "internal",
"users": {"leads": 0, "contributors": 0, "subscribers": 0},
} in response.json()

data = response.json()

assert len(data) == 2
assert data[1]["slug"] == project.slug
assert data[1]["visibility"] == "private"


def test_get_internal_projects_as_user(
client: testclient.TestClient, db: orm.Session, executor_name: str
):
project = projects_crud.create_project(
db, "test project", visibility=projects_models.Visibility.INTERNAL
)
users_crud.create_user(db, executor_name, users_models.Role.USER)

response = client.get("/api/v1/projects")

assert response.status_code == 200
assert {
"name": "default",
"slug": "default",
"description": "",
"visibility": "internal",
"users": {"leads": 0, "contributors": 0, "subscribers": 0},
} in response.json()

data = response.json()

assert len(data) == 2
assert data[1]["slug"] == project.slug
assert data[1]["visibility"] == "internal"


def test_get_internal_projects_as_user_without_duplicates(
Expand All @@ -105,38 +125,18 @@ def test_get_internal_projects_as_user_without_duplicates(
response = client.get("/api/v1/projects")

assert response.status_code == 200
assert {
"name": "default",
"slug": "default",
"description": "",
"visibility": "internal",
"users": {"leads": 0, "contributors": 0, "subscribers": 0},
} in response.json()
assert {
"name": "test project",
"slug": "test-project",
"description": "",
"visibility": "internal",
"users": {"leads": 0, "contributors": 1, "subscribers": 0},
} in response.json()
assert len(response.json()) == 2

data = response.json()

def test_get_internal_default_project_as_user(
client: testclient.TestClient, db: orm.Session, executor_name: str
):
users_crud.create_user(db, executor_name, users_models.Role.USER)
assert len(data) == 2

response = client.get("/api/v1/projects/default")
assert data[0]["slug"] == "default"
assert data[0]["visibility"] == "internal"
assert data[0]["users"]["contributors"] == 0

assert response.status_code == 200
assert {
"name": "default",
"slug": "default",
"description": "",
"visibility": "internal",
"users": {"leads": 0, "contributors": 0, "subscribers": 0},
} == response.json()
assert data[1]["slug"] == project.slug
assert data[1]["visibility"] == "internal"
assert data[1]["users"]["contributors"] == 1


def test_create_private_project_as_admin(
Expand All @@ -153,13 +153,11 @@ def test_create_private_project_as_admin(
)

assert response.status_code == 200
assert {
"name": "test project",
"slug": "test-project",
"description": "",
"visibility": "private",
"users": {"leads": 0, "contributors": 0, "subscribers": 0},
} == response.json()

data = response.json()

assert data["slug"] == "test-project"
assert data["visibility"] == "private"


def test_create_internal_project_as_admin(
Expand All @@ -177,35 +175,38 @@ def test_create_internal_project_as_admin(
)

assert response.status_code == 200
assert {
"name": "test project",
"slug": "test-project",
"description": "",
"visibility": "internal",
"users": {"leads": 0, "contributors": 0, "subscribers": 0},
} == response.json()

data = response.json()

assert data["slug"] == "test-project"
assert data["visibility"] == "internal"


def test_update_project_as_admin(
client: testclient.TestClient, db: orm.Session, executor_name: str
):
users_crud.create_user(db, executor_name, users_models.Role.ADMIN)
projects_crud.create_project(db, "new project")
project = projects_crud.create_project(db, "new project")

assert project.slug == "new-project"
assert project.visibility == projects_models.Visibility.PRIVATE
assert project.is_archived == False

response = client.patch(
"/api/v1/projects/new-project",
json={
"name": "test project",
"description": "",
"visibility": "internal",
"is_archived": "true",
},
)

assert response.status_code == 200
assert {
"name": "test project",
"slug": "test-project",
"description": "",
"visibility": "internal",
"users": {"leads": 0, "contributors": 0, "subscribers": 0},
} == response.json()

data = response.json()

assert data["name"] == "test project"
assert data["slug"] == "test-project"
assert data["visibility"] == "internal"
assert data["is_archived"]
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const mockProjects: Project[] = [
contributors: 0,
subscribers: 0,
},
is_archived: false,
},
];

Expand Down Expand Up @@ -98,6 +99,7 @@ describe('CreateProjectComponent', () => {
slug: project.name!,
visibility: project.visibility!,
users: { leads: 1, contributors: 0, subscribers: 0 },
is_archived: false,
};
this._project.next(projectToCreate);
return of(projectToCreate);
Expand Down

0 comments on commit 2245cf4

Please sign in to comment.