Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmills-DIT committed Apr 2, 2024
1 parent a87ac50 commit 4e714ad
Showing 2 changed files with 32 additions and 11 deletions.
41 changes: 31 additions & 10 deletions reference_documents/tests/test_preferential_rates_views.py
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ def test_success_url(self):
"user_type, expected_http_status",
[
("regular", 403),
("superuser", 200),
("superuser", 302),
],
)
def test_post(
@@ -185,27 +185,48 @@ def test_post(
@pytest.mark.reference_documents
class TestPreferentialRateDeleteView:
@pytest.mark.parametrize(
"http_method, user_type, expected_http_status",
"http_method, expected_http_status",
[
("get", "regular", 403),
("get", "superuser", 200),
("post", "regular", 403),
("post", "superuser", 302),
("get", 200),
("post", 302),
],
)
def test_get_without_permissions(
self,
valid_user_client,
superuser_client,
http_method,
user_type,
expected_http_status,
):
pref_rate = factories.PreferentialRateFactory.create()

client = superuser_client
if user_type == "regular":
client = valid_user_client

resp = getattr(client, http_method)(
reverse(
"reference_documents:preferential_rates_delete",
kwargs={
"pk": pref_rate.pk,
},
),
)
assert resp.status_code == expected_http_status

@pytest.mark.parametrize(
"http_method, expected_http_status",
[
("get", 403),
("post", 403),
],
)
def test_regular_user_get_post(
self,
valid_user_client,
http_method,
expected_http_status,
):
pref_rate = factories.PreferentialRateFactory.create()

client = valid_user_client

resp = getattr(client, http_method)(
reverse(
2 changes: 1 addition & 1 deletion reference_documents/views/preferential_rate_views.py
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ def get_success_url(self):
def form_valid(self, form):
instance = form.instance
reference_document_version = ReferenceDocumentVersion.objects.get(
pk=self.kwargs["pk"],
pk=self.kwargs["version_pk"],
)
instance.order = len(reference_document_version.preferential_rates.all()) + 1
instance.reference_document_version = reference_document_version

0 comments on commit 4e714ad

Please sign in to comment.