-
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.
Merge pull request #217 from Monstarrrr/feat/4_add-arguments
#4 Create new arguments
- Loading branch information
Showing
28 changed files
with
479 additions
and
157 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
backend/core/migrations/0003_remove_posts_acceptedanswerid_and_more.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,97 @@ | ||
# Generated by Django 5.0.4 on 2024-06-24 17:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0002_alter_posts_answercount_alter_posts_commentcount_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="acceptedAnswerId", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="answerCount", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="closedDate", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="commentCount", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="communityOwnedDate", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="creationDate", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="deletionDate", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="favoriteCount", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="lastActivityDate", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="lastEditDate", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="lastEditorDisplayName", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="lastEditorUserId", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="ownerDisplayName", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="parentId", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="postTypeId", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="score", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="tags", | ||
), | ||
migrations.RemoveField( | ||
model_name="posts", | ||
name="viewcount", | ||
), | ||
migrations.AddField( | ||
model_name="posts", | ||
name="type", | ||
field=models.CharField( | ||
choices=[ | ||
("argument", "argument"), | ||
("rebuttal", "rebuttal"), | ||
("comment", "comment"), | ||
], | ||
default="argument", | ||
max_length=10, | ||
), | ||
), | ||
] |
26 changes: 26 additions & 0 deletions
26
backend/core/migrations/0004_posts_createdat_posts_updatedat.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,26 @@ | ||
# Generated by Django 5.0.4 on 2024-06-25 14:53 | ||
|
||
import django.utils.timezone | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0003_remove_posts_acceptedanswerid_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="posts", | ||
name="createdAt", | ||
field=models.DateTimeField( | ||
auto_now_add=True, default=django.utils.timezone.now | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="posts", | ||
name="updatedAt", | ||
field=models.DateTimeField(auto_now=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Generated by Django 5.0.4 on 2024-06-26 02:24 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0004_posts_createdat_posts_updatedat"), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name="Tags", | ||
), | ||
] |
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 |
---|---|---|
@@ -1,89 +1,26 @@ | ||
# Create your tests here. | ||
from django.contrib.auth.models import User | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
|
||
from ..models import Posts, Tags, UserProfile | ||
from core.models import Posts | ||
|
||
|
||
class CoreTests(TestCase): | ||
class PostsTests(TestCase): | ||
def setUp(self): | ||
# Create a client instance | ||
self.client = Client() | ||
|
||
# Create sample tag | ||
self.sample_tag = Tags.objects.create( | ||
tagName="tag1", | ||
count=1, | ||
excerptPostId=1, | ||
wikiPostId=1, | ||
isModeratorOnly=False, | ||
isRequired=True, | ||
) | ||
|
||
# Create sample post | ||
self.sample_post = Posts.objects.create( | ||
postTypeId=1, | ||
acceptedAnswerId=1, | ||
parentId=1, | ||
creationDate="2024-01-01", | ||
deletionDate=None, | ||
score=10, | ||
viewcount=100, | ||
type="argument", | ||
createdAt="2024-06-26 02:20:58.689998+00:00", | ||
updatedAt="2024-06-26 02:20:58.689998+00:00", | ||
body="<p>Sample post content</p>", | ||
ownerUserId=1, | ||
ownerDisplayName="John Doe", | ||
lastEditorUserId=1, | ||
lastEditorDisplayName="Jane Doe", | ||
lastEditDate="2024-01-02", | ||
lastActivityDate="2024-01-03", | ||
title="Sample Title", | ||
answerCount=0, | ||
commentCount=0, | ||
favoriteCount=0, | ||
closedDate=None, | ||
communityOwnedDate=None, | ||
) | ||
# Correctly assign the tag to the post | ||
self.sample_post.tags.set([self.sample_tag]) | ||
|
||
# Create sample user | ||
user = User.objects.create_superuser("username") | ||
# Create sample user profile | ||
self.sample_user_profile = UserProfile.objects.create( | ||
user=user, | ||
username="username", | ||
avatar="avatar", | ||
bio="bio", | ||
reputation=1, | ||
joinDate="2024-01-01", | ||
upVotes=1, | ||
downVotes=1, | ||
) | ||
# Correctly assign the post to the user profile | ||
self.sample_user_profile.posts.set([self.sample_post]) | ||
self.sample_user_profile.edits.set([self.sample_post]) | ||
self.sample_user_profile.savedPosts.set([self.sample_post]) | ||
self.sample_user_profile.private_post.set([self.sample_post]) | ||
|
||
def test_tags_api(self): | ||
# Test the tags API endpoint | ||
response = self.client.get(reverse("tags-list")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, self.sample_tag.tagName) | ||
|
||
def test_posts_api(self): | ||
# Test the posts API endpoint | ||
response = self.client.get(reverse("posts-list")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, self.sample_post.title) | ||
|
||
def test_user_profile_api(self): | ||
# Test the user profile API endpoint | ||
response = self.client.get(reverse("user-profile-list")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, self.sample_user_profile.username) | ||
|
||
def test_alivecheck_smoketest(self): | ||
response = self.client.get(reverse("alive-list")) | ||
self.assertEqual(response.status_code, 200) |
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,43 @@ | ||
from django.contrib.auth.models import User | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
|
||
from core.models import Posts, UserProfile | ||
|
||
|
||
class UserTests(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
user = User.objects.create_superuser("username") | ||
|
||
self.sample_post = Posts.objects.create( | ||
type="argument", | ||
createdAt="2024-06-26 02:20:58.689998+00:00", | ||
updatedAt="2024-06-26 02:20:58.689998+00:00", | ||
body="<p>Sample post content</p>", | ||
ownerUserId=1, | ||
title="Sample Title", | ||
) | ||
|
||
# Create sample user profile | ||
self.sample_user_profile = UserProfile.objects.create( | ||
user=user, | ||
username="username", | ||
avatar="avatar", | ||
bio="bio", | ||
reputation=1, | ||
joinDate="2024-01-01", | ||
upVotes=1, | ||
downVotes=1, | ||
) | ||
# Correctly assign the post to the user profile | ||
self.sample_user_profile.posts.set([self.sample_post]) | ||
self.sample_user_profile.edits.set([self.sample_post]) | ||
self.sample_user_profile.savedPosts.set([self.sample_post]) | ||
self.sample_user_profile.private_post.set([self.sample_post]) | ||
|
||
def test_user_profile_api(self): | ||
# Test the user profile API endpoint | ||
response = self.client.get(reverse("user-profile-list")) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, self.sample_user_profile.username) |
Oops, something went wrong.