fix: profile: block: fix test and simplify code
This commit is contained in:
parent
9bbe5a4705
commit
c1624cce83
@ -3,6 +3,8 @@ from django.http import HttpResponse
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import status
|
||||
|
||||
from profiles.serializers.ProfileSerializer import ProfileSerializer
|
||||
from profiles.models.ProfileModel import ProfileModel
|
||||
|
||||
class ProfileTest(TestCase):
|
||||
def setUp(self):
|
||||
@ -29,6 +31,8 @@ class BlockTest(TestCase):
|
||||
self.client.login(username=self.blocker.username, password=self.blocker_password)
|
||||
response: HttpResponse = self.client.post(f'/api/profiles/block/{self.blocked.pk}')
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
blocked_profile = ProfileModel.objects.get(user=self.blocked)
|
||||
|
||||
response = self.client.get('/api/profiles/block')
|
||||
self.assertListEqual(response.json(), [{'blocked': self.blocked.pk}])
|
||||
self.assertListEqual(response.json(), [ProfileSerializer(blocked_profile).data])
|
||||
|
@ -2,6 +2,7 @@ from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import permissions, status
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
from rest_framework.request import Request
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import gettext as _
|
||||
@ -15,11 +16,11 @@ class GetBlocksView(APIView):
|
||||
permission_classes = (permissions.IsAuthenticated,)
|
||||
authentication_classes = (SessionAuthentication,)
|
||||
|
||||
def get(self, request):
|
||||
def get(self, request: Request):
|
||||
profiles = []
|
||||
blocks = BlockModel.objects.filter(blocker=request.user.pk)
|
||||
blocks = BlockModel.objects.filter(blocker=request.user)
|
||||
for block in blocks:
|
||||
profile = ProfileModel.objects.filter(user_id=block.blocked.pk)
|
||||
profile = ProfileModel.objects.filter(user=block.blocked)
|
||||
if (profile.exists()):
|
||||
profiles.append(profile[0])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user