-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(follow users) follow and unfollow users
- update profile model to include following functionality - update profile serializer to add a following field to the profile serialized data - write tests for the following functionality - add endpoints for the follow functionality to the url.py file - write functions to handle the follow functionlity [finishes #165890222]
- Loading branch information
1 parent
6614de1
commit 9daafe3
Showing
6 changed files
with
190 additions
and
7 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,24 @@ | ||
# Generated by Django 2.1 on 2019-05-10 06:54 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('profiles', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Follow', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('followed', models.ForeignKey(default=False, on_delete=django.db.models.deletion.CASCADE, related_name='followed', to=settings.AUTH_USER_MODEL)), | ||
('follower', models.ForeignKey(default=False, on_delete=django.db.models.deletion.CASCADE, related_name='follower', 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from .base import BaseTestCase | ||
|
||
|
||
class FollowTestCase(BaseTestCase): | ||
"""Testcases for following a user.""" | ||
|
||
def test_follow_user_post(self): | ||
"""Test start following a user.""" | ||
url = reverse('follow', kwargs={'username': 'test2'}) | ||
response = self.client.post(url, HTTP_AUTHORIZATION=self.auth_header) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_post_follow_already_followed_user(self): | ||
"""Test start following a user you already follow.""" | ||
url = reverse('follow', kwargs={'username': 'test2'}) | ||
self.client.post(url, HTTP_AUTHORIZATION=self.auth_header) | ||
response = self.client.post(url, HTTP_AUTHORIZATION=self.auth_header) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_follow_missing_user_post(self): | ||
"""Test trying to start following a missing user.""" | ||
url = reverse('follow', kwargs={'username': 'joel'}) | ||
response = self.client.post(url, HTTP_AUTHORIZATION=self.auth_header) | ||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) | ||
|
||
def test_delete_follow(self): | ||
"""Test unfollowing a user""" | ||
url = reverse('follow', kwargs={'username': 'test2'}) | ||
self.client.post(url, HTTP_AUTHORIZATION=self.auth_header) | ||
response = self.client.delete(url, HTTP_AUTHORIZATION=self.auth_header) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_delete_follow_of_not_followed_user(self): | ||
"""Test unfollowing a user you are not following""" | ||
url = reverse('follow', kwargs={'username': 'test2'}) | ||
response = self.client.delete(url, HTTP_AUTHORIZATION=self.auth_header) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
def test_list_followers_of_user(self): | ||
"""Test list followers of a user""" | ||
url_follow = reverse('follow', kwargs={'username': 'test2'}) | ||
self.client.post(url_follow, HTTP_AUTHORIZATION=self.auth_header) | ||
url_followers = reverse('getfollowers', kwargs={'username': 'test2'}) | ||
response = self.client.get(url_followers, HTTP_AUTHORIZATION=self.auth_header) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_list_user_is_following(self): | ||
"""Test list users the user is following""" | ||
url_follow = reverse('follow', kwargs={'username': 'test2'}) | ||
self.client.post(url_follow, HTTP_AUTHORIZATION=self.auth_header) | ||
url_following = reverse('getfollowing', kwargs={'username': 'test1'}) | ||
response = self.client.get(url_following, HTTP_AUTHORIZATION=self.auth_header) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) |
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,7 +1,15 @@ | ||
from django.urls import path | ||
from .views import UserProfiles, Updateprofile | ||
from .views import UserProfiles, Updateprofile, \ | ||
FollowView, Followers, Following | ||
|
||
urlpatterns = [ | ||
path('users/profiles/', UserProfiles.as_view(), name="get_profile"), | ||
path('users/profile/<str:username>/', Updateprofile.as_view(), name="update_profile") | ||
path('users/profile/<str:username>/', Updateprofile.as_view(), | ||
name="update_profile"), | ||
path('profiles/<str:username>/follow/', FollowView.as_view(), | ||
name="follow"), | ||
path('profiles/<str:username>/followers/', Followers.as_view(), | ||
name="getfollowers"), | ||
path('profiles/<str:username>/following/', Following.as_view(), | ||
name="getfollowing") | ||
] |
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