diff --git a/tests/domain/test_projects.py b/tests/domain/test_projects.py index 2c4788e6..e09ab666 100644 --- a/tests/domain/test_projects.py +++ b/tests/domain/test_projects.py @@ -1,9 +1,10 @@ from atst.domain.projects import Projects -from tests.factories import WorkspaceFactory +from atst.domain.workspaces import Workspaces +from tests.factories import RequestFactory def test_create_project_with_multiple_environments(): - workspace = WorkspaceFactory.create() + workspace = Workspaces.create(RequestFactory.create()) project = Projects.create( workspace.owner, workspace, "My Test Project", "Test", ["dev", "prod"] ) diff --git a/tests/domain/test_users.py b/tests/domain/test_users.py index 16d78366..f27f26aa 100644 --- a/tests/domain/test_users.py +++ b/tests/domain/test_users.py @@ -8,13 +8,13 @@ DOD_ID = "my_dod_id" def test_create_user(): - user = Users.create("developer") + user = Users.create("developer", dod_id=DOD_ID) assert user.atat_role.name == "developer" def test_create_user_with_nonexistent_role(): with pytest.raises(NotFoundError): - Users.create("nonexistent") + Users.create("nonexistent", dod_id=DOD_ID) def test_get_or_create_nonexistent_user(): @@ -29,13 +29,13 @@ def test_get_or_create_existing_user(): def test_get_user(): - new_user = Users.create("developer") + new_user = Users.create("developer", dod_id=DOD_ID) user = Users.get(new_user.id) assert user.id == new_user.id def test_get_nonexistent_user(): - Users.create("developer") + Users.create("developer", dod_id=DOD_ID) with pytest.raises(NotFoundError): Users.get(uuid4()) @@ -47,19 +47,19 @@ def test_get_user_by_dod_id(): def test_update_user(): - new_user = Users.create("developer") + new_user = Users.create("developer", dod_id=DOD_ID) updated_user = Users.update(new_user.id, "ccpo") assert updated_user.atat_role.name == "ccpo" def test_update_nonexistent_user(): - Users.create("developer") + Users.create("developer", dod_id=DOD_ID) with pytest.raises(NotFoundError): Users.update(uuid4(), "ccpo") def test_update_existing_user_with_nonexistent_role(): - new_user = Users.create("developer") + new_user = Users.create("developer", dod_id=DOD_ID) with pytest.raises(NotFoundError): Users.update(new_user.id, "nonexistent") diff --git a/tests/domain/test_workspace_users.py b/tests/domain/test_workspace_users.py index be24796b..c07473f2 100644 --- a/tests/domain/test_workspace_users.py +++ b/tests/domain/test_workspace_users.py @@ -1,23 +1,23 @@ from atst.domain.workspace_users import WorkspaceUsers from atst.domain.users import Users -from tests.factories import WorkspaceFactory +from tests.factories import WorkspaceFactory, UserFactory def test_can_create_new_workspace_user(): workspace = WorkspaceFactory.create() - new_user = Users.create("developer") + new_user = UserFactory.create() workspace_user_dicts = [{"id": new_user.id, "workspace_role": "owner"}] workspace_users = WorkspaceUsers.add_many(workspace.id, workspace_user_dicts) assert workspace_users[0].user.id == new_user.id - assert workspace_users[0].user.atat_role.name == "developer" - assert workspace_users[0].workspace_role.role.name == "owner" + assert workspace_users[0].user.atat_role.name == new_user.atat_role.name + assert workspace_users[0].workspace_role.role.name == new_user.workspace_roles[0].role.name def test_can_update_existing_workspace_user(): workspace = WorkspaceFactory.create() - new_user = Users.create("developer") + new_user = UserFactory.create() WorkspaceUsers.add_many( workspace.id, [{"id": new_user.id, "workspace_role": "owner"}] @@ -26,5 +26,5 @@ def test_can_update_existing_workspace_user(): workspace.id, [{"id": new_user.id, "workspace_role": "developer"}] ) - assert workspace_users[0].user.id == new_user.id - assert workspace_users[0].workspace_role.role.name == "developer" + assert workspace_users[0].user.atat_role.name == new_user.atat_role.name + assert workspace_users[0].workspace_role.role.name == new_user.workspace_roles[0].role.name diff --git a/tests/factories.py b/tests/factories.py index b462701c..d2ecc62a 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -27,6 +27,8 @@ class RoleFactory(Base): class Meta: model = Role + name = factory.Faker("job") + description = "This is a test role." permissions = [] diff --git a/tests/models/test_requests.py b/tests/models/test_requests.py index 528d0b06..3d5bcf72 100644 --- a/tests/models/test_requests.py +++ b/tests/models/test_requests.py @@ -80,38 +80,36 @@ def test_annual_spend(): def test_reviews(): request = RequestFactory.create() ccpo = UserFactory.from_atat_role("ccpo") - request.status_events = [ - RequestStatusEventFactory.create( - revision=request.latest_revision, - review=RequestReviewFactory.create(reviewer=ccpo), - ), - RequestStatusEventFactory.create( - revision=request.latest_revision, - review=RequestReviewFactory.create(reviewer=ccpo), - ), - RequestStatusEventFactory.create(revision=request.latest_revision), - ] + RequestStatusEventFactory.create( + request=request, + revision=request.latest_revision, + review=RequestReviewFactory.create(reviewer=ccpo), + ), + RequestStatusEventFactory.create( + request=request, + revision=request.latest_revision, + review=RequestReviewFactory.create(reviewer=ccpo), + ), + RequestStatusEventFactory.create(request=request, revision=request.latest_revision), assert len(request.reviews) == 2 def test_review_comment(): request = RequestFactory.create() ccpo = UserFactory.from_atat_role("ccpo") - request.status_events = [ - RequestStatusEventFactory.create( - revision=request.latest_revision, - new_status=RequestStatus.CHANGES_REQUESTED, - review=RequestReviewFactory.create(reviewer=ccpo, comment="do better"), - ) - ] + RequestStatusEventFactory.create( + request=request, + revision=request.latest_revision, + new_status=RequestStatus.CHANGES_REQUESTED, + review=RequestReviewFactory.create(reviewer=ccpo, comment="do better"), + ) assert request.review_comment == "do better" - request.status_events = [ - RequestStatusEventFactory.create( - revision=request.latest_revision, - new_status=RequestStatus.APPROVED, - review=RequestReviewFactory.create(reviewer=ccpo, comment="much better"), - ) - ] + RequestStatusEventFactory.create( + request=request, + revision=request.latest_revision, + new_status=RequestStatus.APPROVED, + review=RequestReviewFactory.create(reviewer=ccpo, comment="much better"), + ) assert not request.review_comment diff --git a/tests/routes/test_financial_verification.py b/tests/routes/test_financial_verification.py index 1a2c4606..fe601c35 100644 --- a/tests/routes/test_financial_verification.py +++ b/tests/routes/test_financial_verification.py @@ -162,14 +162,13 @@ def test_displays_ccpo_review_comment(user_session, client): ccpo = UserFactory.from_atat_role("ccpo") user_session(creator) request = RequestFactory.create(creator=creator) + status = RequestStatusEventFactory.create( + revision=request.latest_revision, + new_status=RequestStatus.CHANGES_REQUESTED_TO_FINVER, + request=request, + ) review_comment = "add all of the correct info, instead of the incorrect info" - request.status_events = [ - RequestStatusEventFactory.create( - revision=request.latest_revision, - new_status=RequestStatus.CHANGES_REQUESTED_TO_FINVER, - review=RequestReviewFactory.create(reviewer=ccpo, comment=review_comment), - ) - ] + RequestReviewFactory.create(reviewer=ccpo, comment=review_comment, status=status) response = client.get("/requests/verify/{}".format(request.id)) body = response.data.decode() assert review_comment in body diff --git a/tests/routes/test_request_new.py b/tests/routes/test_request_new.py index 9bc8a668..71dfcedc 100644 --- a/tests/routes/test_request_new.py +++ b/tests/routes/test_request_new.py @@ -227,14 +227,13 @@ def test_displays_ccpo_review_comment(user_session, client): ccpo = UserFactory.from_atat_role("ccpo") user_session(creator) request = RequestFactory.create(creator=creator) + status = RequestStatusEventFactory.create( + request=request, + revision=request.latest_revision, + new_status=RequestStatus.CHANGES_REQUESTED, + ) review_comment = "add all of the correct info, instead of the incorrect info" - request.status_events = [ - RequestStatusEventFactory.create( - revision=request.latest_revision, - new_status=RequestStatus.CHANGES_REQUESTED, - review=RequestReviewFactory.create(reviewer=ccpo, comment=review_comment), - ) - ] + RequestReviewFactory.create(reviewer=ccpo, comment=review_comment, status=status) response = client.get("/requests/new/1/{}".format(request.id)) body = response.data.decode() assert review_comment in body