Test getting all projects for a user.
(mock_request, orm_session, test_user)
| 27 | |
| 28 | @pytest.mark.asyncio |
| 29 | async def test_get_projects(mock_request, orm_session, test_user): |
| 30 | """Test getting all projects for a user.""" |
| 31 | # Create an org first |
| 32 | org = OrgModel(name="Test Org for Projects") |
| 33 | orm_session.add(org) |
| 34 | orm_session.flush() |
| 35 | |
| 36 | # Create a user-org relationship with the test user fixture |
| 37 | user_org = UserOrgModel( |
| 38 | user_id=test_user.id, org_id=org.id, role=OrgRoles.owner, user_email=test_user.email |
| 39 | ) |
| 40 | orm_session.add(user_org) |
| 41 | |
| 42 | # Create a project |
| 43 | project = ProjectModel(name="Test Project", org_id=org.id, environment=Environment.development) |
| 44 | orm_session.add(project) |
| 45 | orm_session.flush() |
| 46 | |
| 47 | # Call the endpoint function |
| 48 | result = await get_projects(request=mock_request, orm=orm_session) |
| 49 | |
| 50 | # Verify that it returns a list and the test project is in the results |
| 51 | assert isinstance(result, list) |
| 52 | assert len(result) > 0 |
| 53 | |
| 54 | # Check that our test project is in the results |
| 55 | project_ids = [p.id for p in result] |
| 56 | assert str(project.id) in project_ids |
| 57 | |
| 58 | |
| 59 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected
searching dependent graphs…