-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added report and suggestion functions in argument viewset actions and…
… added tests. Updated report model fields.
- Loading branch information
1 parent
b45121a
commit b80f64b
Showing
5 changed files
with
159 additions
and
16 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
backend/core/migrations/0013_report_options_alter_report_body.py
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,22 @@ | ||
# Generated by Django 5.0.7 on 2024-08-17 20:11 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0012_report_alter_post_type"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="report", | ||
name="options", | ||
field=models.CharField(max_length=255, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="report", | ||
name="body", | ||
field=models.CharField(max_length=255, null=True), | ||
), | ||
] |
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,58 @@ | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
|
||
from core.models import Post, Report | ||
|
||
|
||
class ReportTests(TestCase): | ||
def setUp(self): | ||
# Create a client instance | ||
self.client = Client() | ||
|
||
# Create sample post | ||
self.sample_post = Post.objects.create( | ||
id="008643568", | ||
type="argument", | ||
isPrivate=False, | ||
created="2024-06-26 02:20:58.689998+00:00", | ||
updated="2024-06-26 02:20:58.689998+00:00", | ||
body="<p>Sample post content</p>", | ||
ownerUserId=1, | ||
title="Sample Title", | ||
) | ||
|
||
# Create sample report dict | ||
self.sample_report_dict = { | ||
"id": "67659876", | ||
"parentId": "008643568", | ||
"created": "2024-06-26 02:20:58.689998+00:00", | ||
"body": "<p>Sample report content</p>", | ||
"options": "sample report options", | ||
} | ||
|
||
# Create sample report | ||
self.sample_report = Report.objects.create( | ||
id="65775545", | ||
parentId="008643568", | ||
created="2024-06-26 02:20:58.689998+00:00", | ||
body="<p>Sample report content</p>", | ||
options="sample report options", | ||
) | ||
|
||
def test_add_reports_api(self): | ||
# Test the suggestions API endpoint | ||
response = self.client.post( | ||
reverse("arguments-add-reports", kwargs={"pk": self.sample_post.id}), | ||
data=self.sample_report_dict, | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
if not Report.objects.filter(id=self.sample_report_dict["id"]).exists(): | ||
self.fail("Sample report not found") | ||
|
||
def test_report_options_api(self): | ||
# Test the report options API endpoint | ||
response = self.client.get( | ||
reverse("arguments-reports-options", kwargs={"pk": self.sample_post.id}) | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, self.sample_report.options) |
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