import pytest from pytest import fixture from pytest_factoryboy import LazyFixture @pytest.mark.django_db class GetProductByIdE2ETests: @fixture(autouse=True) def product_stages(self, product_stages): pass @fixture def request_url(self, project): return f"/projects/{project.id}/" @pytest.mark.parametrize( "token__user,project__published,expected_status_code", [ (LazyFixture("agency_user"), False, 200), (LazyFixture("supplier_user"), False, 200), (LazyFixture("agency_user"), True, 200), (LazyFixture("client_user"), True, 200), (LazyFixture("supplier_user"), True, 200), ], ) def test_user_can_see_project( self, client, request_url, expected_status_code, token ): response = client.get( path=request_url, content_type="application/json", HTTP_AUTHORIZATION=f"Bearer {token.key}", ) assert response.status_code == expected_status_code @pytest.mark.parametrize( "token__user,project__published", [ (LazyFixture("agency_user"), False), (LazyFixture("supplier_user"), False), (LazyFixture("agency_user"), True), (LazyFixture("client_user"), True), (LazyFixture("supplier_user"), True), ], ) def test_user_sees_correct_project(self, client, request_url, token, project): response = client.get( path=request_url, content_type="application/json", HTTP_AUTHORIZATION=f"Bearer {token.key}", ) data = response.json() assert data["slug"] == project.slug