-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added user profile #85
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7a1b444
added user profile
purple-void 8a88bb7
Readded token
purple-void 8105237
Merge branch 'main' into feat/37_user-api
purple-void be4b67e
put dependencies for templates back (crispy forms/bootstrap)
seporterfield 10034dd
remove cors settings
seporterfield 4140f49
add template pack back
seporterfield cac6c2a
renamed private_rebuttals -> private_posts
seporterfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
backend/core/migrations/0002_alter_posts_answercount_alter_posts_commentcount_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,107 @@ | ||
# Generated by Django 5.0.4 on 2024-05-28 23:21 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0001_initial"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="posts", | ||
name="answerCount", | ||
field=models.IntegerField(default=0, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="posts", | ||
name="commentCount", | ||
field=models.IntegerField(default=0, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="posts", | ||
name="favoriteCount", | ||
field=models.IntegerField(default=0, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="posts", | ||
name="score", | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AlterField( | ||
model_name="posts", | ||
name="tags", | ||
field=models.ManyToManyField(related_name="tags", to="core.tags"), | ||
), | ||
migrations.AlterField( | ||
model_name="posts", | ||
name="viewcount", | ||
field=models.IntegerField(default=0, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="tags", | ||
name="count", | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AlterField( | ||
model_name="tags", | ||
name="isModeratorOnly", | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AlterField( | ||
model_name="tags", | ||
name="isRequired", | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.CreateModel( | ||
name="UserProfile", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("username", models.CharField(max_length=255, null=True)), | ||
("avatar", models.CharField(max_length=255, null=True)), | ||
("bio", models.TextField(max_length=255, null=True)), | ||
("reputation", models.IntegerField(default=0, null=True)), | ||
("joinDate", models.DateField()), | ||
("upVotes", models.IntegerField(default=0, null=True)), | ||
("downVotes", models.IntegerField(default=0, null=True)), | ||
( | ||
"edits", | ||
models.ManyToManyField(related_name="edits", to="core.posts"), | ||
), | ||
( | ||
"posts", | ||
models.ManyToManyField(related_name="posts", to="core.posts"), | ||
), | ||
( | ||
"privateRebuttals", | ||
models.ManyToManyField( | ||
related_name="private_rebuttals", to="core.posts" | ||
), | ||
), | ||
( | ||
"savedPosts", | ||
models.ManyToManyField(related_name="saved_posts", to="core.posts"), | ||
), | ||
( | ||
"user", | ||
models.OneToOneField( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
] |
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,16 +1,27 @@ | ||
# 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 | ||
from .models import Posts, Tags, UserProfile | ||
|
||
|
||
class CoreTests(TestCase): | ||
def setUp(self): | ||
# Create a client instance | ||
self.client = Client() | ||
|
||
# Create sample posts and tags | ||
# 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, | ||
|
@@ -33,30 +44,45 @@ def setUp(self): | |
closedDate=None, | ||
communityOwnedDate=None, | ||
) | ||
# Correctly assign the tag to the post | ||
self.sample_post.tags.set([self.sample_tag]) | ||
|
||
self.sample_tag = Tags.objects.create( | ||
tagName="tag1", | ||
count=1, | ||
excerptPostId=1, | ||
wikiPostId=1, | ||
isModeratorOnly=False, | ||
isRequired=True, | ||
# 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.privateRebuttals.set([self.sample_post]) | ||
|
||
# Correctly assign the tag to the post | ||
self.sample_post.tags.set([self.sample_tag]) | ||
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_tags_api(self): | ||
# Test the tags API endpoint | ||
response = self.client.get(reverse("tags-list")) | ||
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_tag.tagName) | ||
self.assertContains(response, self.sample_user_profile.username) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing 👍👍👍👍👍👍 |
||
def test_alivecheck_smoketest(self): | ||
response = self.client.get(reverse("alive-list")) | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good catch