Initial commit from ZIP
This commit is contained in:
commit
378d4692a9
454 files changed
+40367
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import pytest
|
||||
|
||||
from pytest import fixture
|
||||
from pytest_factoryboy import LazyFixture
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class GetProductBriefE2ETests:
|
||||
@fixture(autouse=True)
|
||||
def product_stages(self, product_stages):
|
||||
pass
|
||||
|
||||
@fixture
|
||||
def brief_url(self, product):
|
||||
return f"/briefs/{product.id}/"
|
||||
|
||||
@fixture
|
||||
def published_brief_url(self, published_product):
|
||||
return f"/briefs/{published_product.id}/"
|
||||
|
||||
def test_unauthorized_cannot_open_brief(self, token, client, brief_url):
|
||||
response = client.get(path=brief_url, content_type="application/json",)
|
||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"token__user,expected_status_code",
|
||||
[
|
||||
(LazyFixture("client_user"), status.HTTP_403_FORBIDDEN),
|
||||
(LazyFixture("agency_user"), status.HTTP_200_OK),
|
||||
(LazyFixture("supplier_user"), status.HTTP_200_OK),
|
||||
],
|
||||
)
|
||||
def test_only_supplier_and_agency_can_open_nonpublished_brief(
|
||||
self, token, client, brief_url, expected_status_code
|
||||
):
|
||||
response = client.get(
|
||||
path=brief_url,
|
||||
content_type="application/json",
|
||||
HTTP_AUTHORIZATION=f"Bearer {token.key}",
|
||||
)
|
||||
assert response.status_code == expected_status_code
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"token__user,expected_status_code",
|
||||
[
|
||||
(LazyFixture("client_user"), status.HTTP_200_OK),
|
||||
(LazyFixture("agency_user"), status.HTTP_200_OK),
|
||||
(LazyFixture("supplier_user"), status.HTTP_200_OK),
|
||||
],
|
||||
)
|
||||
def test_everyone_can_open_published_brief(
|
||||
self, token, client, published_brief_url, expected_status_code
|
||||
):
|
||||
response = client.get(
|
||||
path=published_brief_url,
|
||||
content_type="application/json",
|
||||
HTTP_AUTHORIZATION=f"Bearer {token.key}",
|
||||
)
|
||||
assert response.status_code == expected_status_code
|
||||
@@ -0,0 +1,38 @@
|
||||
import pytest
|
||||
|
||||
from pytest import fixture
|
||||
from pytest_factoryboy import LazyFixture
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class GetProductE2ETests:
|
||||
@fixture(autouse=True)
|
||||
def product_stages(self, product_stages):
|
||||
pass
|
||||
|
||||
@fixture
|
||||
def request_url(self, product):
|
||||
return f"/products/{product.id}/"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"token__user,project__published,expected_status_code",
|
||||
[
|
||||
(LazyFixture("agency_user"), False, status.HTTP_200_OK),
|
||||
(LazyFixture("client_user"), False, status.HTTP_403_FORBIDDEN),
|
||||
(LazyFixture("supplier_user"), False, status.HTTP_200_OK),
|
||||
(LazyFixture("agency_user"), True, status.HTTP_200_OK),
|
||||
(LazyFixture("client_user"), True, status.HTTP_200_OK),
|
||||
(LazyFixture("supplier_user"), True, status.HTTP_200_OK),
|
||||
],
|
||||
)
|
||||
def test_user_can_see_product(
|
||||
self, client, request_url, expected_status_code, token, project
|
||||
):
|
||||
response = client.get(
|
||||
path=request_url,
|
||||
content_type="application/json",
|
||||
HTTP_AUTHORIZATION=f"Bearer {token.key}",
|
||||
)
|
||||
data = response.json()
|
||||
assert response.status_code == expected_status_code
|
||||
@@ -0,0 +1,56 @@
|
||||
import pytest
|
||||
from pytest import fixture
|
||||
from pytest_factoryboy import LazyFixture
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class GetProductsListForProjectE2ETests:
|
||||
@fixture(autouse=True)
|
||||
def product_stages(self, product_stages):
|
||||
pass
|
||||
|
||||
@fixture(autouse=True)
|
||||
def project_with_two_products(self, project_factory):
|
||||
return project_factory(products_amount=2, published=False)
|
||||
|
||||
@fixture(autouse=True)
|
||||
def another_project_with_three_products(self, project_factory):
|
||||
project_factory(products_amount=3, published=False)
|
||||
|
||||
@fixture
|
||||
def request_url(self, project_with_two_products):
|
||||
return f"/products/?project={project_with_two_products.id}"
|
||||
|
||||
def test_anonymous_user_is_not_authorized(self, client, request_url):
|
||||
response = client.get(request_url, content_type="application/json")
|
||||
|
||||
# Assert
|
||||
assert (
|
||||
response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||
), "Wrong HTTP response code."
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"token__user,expected_count",
|
||||
[
|
||||
(LazyFixture("agency_user"), 2),
|
||||
(LazyFixture("client_user"), 0),
|
||||
(LazyFixture("supplier_user"), 2),
|
||||
],
|
||||
)
|
||||
def test_user_sees_only_published_products(
|
||||
self, client, request_url, token, expected_count
|
||||
):
|
||||
# Arrange
|
||||
|
||||
# Act
|
||||
response = client.get(
|
||||
path=request_url,
|
||||
content_type="application/json",
|
||||
HTTP_AUTHORIZATION=f"Bearer {token.key}",
|
||||
)
|
||||
data = response.json()
|
||||
|
||||
# Assert
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert len(data) == expected_count
|
||||
@@ -0,0 +1,21 @@
|
||||
import pytest
|
||||
|
||||
from pytest import fixture
|
||||
from pytest_factoryboy import LazyFixture
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
@pytest.mark.skip("Not yet implemented")
|
||||
@pytest.mark.django_db
|
||||
class UpdateProductBriefE2ETests:
|
||||
@fixture(autouse=True)
|
||||
def product_stages(self, product_stages):
|
||||
pass
|
||||
|
||||
@fixture
|
||||
def brief_url(self, product):
|
||||
return f"/briefs/{product.id}/"
|
||||
|
||||
@fixture
|
||||
def published_brief_url(self, published_product):
|
||||
return f"/briefs/{published_product.id}/"
|
||||
Reference in new issue
Block a user