This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
211 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.10 on 2022-01-29 16:05 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0018_auto_20220116_2114"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="submission", | ||
name="approved", | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import json | ||
|
||
from django.test import Client | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
from utils.test_helpers import create_submission, setup_user_client | ||
|
||
|
||
class TestSubmissionApprove: | ||
"""Tests validating the behavior of the Submission approval process.""" | ||
|
||
def test_approve_no_params(self, client: Client) -> None: | ||
"""Verify that approving a submission works without parameters.""" | ||
client, headers, user = setup_user_client(client) | ||
|
||
submission = create_submission(id=3) | ||
assert not submission.approved | ||
|
||
data = {} | ||
|
||
result = client.patch( | ||
reverse("submission-approve", args=[submission.id]), | ||
json.dumps(data), | ||
content_type="application/json", | ||
**headers | ||
) | ||
|
||
submission.refresh_from_db() | ||
|
||
assert result.status_code == status.HTTP_200_OK | ||
assert submission.approved | ||
|
||
def test_approve_no_change(self, client: Client) -> None: | ||
"""Verify that approving a submission works without parameters.""" | ||
client, headers, user = setup_user_client(client) | ||
|
||
submission = create_submission(id=3, approved=True) | ||
assert submission.approved | ||
|
||
data = {} | ||
|
||
result = client.patch( | ||
reverse("submission-approve", args=[submission.id]), | ||
json.dumps(data), | ||
content_type="application/json", | ||
**headers | ||
) | ||
|
||
submission.refresh_from_db() | ||
|
||
assert result.status_code == status.HTTP_200_OK | ||
assert submission.approved | ||
|
||
def test_approve_param_false(self, client: Client) -> None: | ||
"""Verify that reverting the approval works correctly.""" | ||
client, headers, user = setup_user_client(client) | ||
|
||
submission = create_submission(id=3, approved=True) | ||
assert submission.approved | ||
|
||
data = {"approved": False} | ||
|
||
result = client.patch( | ||
reverse("submission-approve", args=[submission.id]), | ||
json.dumps(data), | ||
content_type="application/json", | ||
**headers | ||
) | ||
|
||
submission.refresh_from_db() | ||
|
||
assert result.status_code == status.HTTP_200_OK | ||
assert not submission.approved | ||
|
||
def test_approve_param_true(self, client: Client) -> None: | ||
"""Verify that approving a submission works with parameters.""" | ||
client, headers, user = setup_user_client(client) | ||
|
||
submission = create_submission(id=3) | ||
assert not submission.removed_from_queue | ||
|
||
data = {"approved": True} | ||
|
||
result = client.patch( | ||
reverse("submission-approve", args=[submission.id]), | ||
json.dumps(data), | ||
content_type="application/json", | ||
**headers | ||
) | ||
|
||
submission.refresh_from_db() | ||
|
||
assert result.status_code == status.HTTP_200_OK | ||
assert submission.approved | ||
|
||
def test_approve_reverting_removal(self, client: Client) -> None: | ||
"""Verify that approving a submission reverts its removal.""" | ||
client, headers, user = setup_user_client(client) | ||
|
||
submission = create_submission(id=3, removed_from_queue=True) | ||
assert not submission.approved | ||
assert submission.removed_from_queue | ||
|
||
data = {} | ||
|
||
result = client.patch( | ||
reverse("submission-approve", args=[submission.id]), | ||
json.dumps(data), | ||
content_type="application/json", | ||
**headers | ||
) | ||
|
||
submission.refresh_from_db() | ||
|
||
assert result.status_code == status.HTTP_200_OK | ||
assert submission.approved | ||
assert not submission.removed_from_queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters