fixes to the my_ views, and their tests
This commit is contained in:
@@ -521,8 +521,11 @@ class MyUserViewTest(APITestCase):
|
||||
|
||||
# Query endpoint
|
||||
response = self.client.get(self.endpoint)
|
||||
payload = response.json()
|
||||
|
||||
# Assert forbidden code
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEquals(self.email, payload['email'])
|
||||
|
||||
def test_anon_user_cannot_access(self):
|
||||
# send in request
|
||||
|
||||
@@ -128,7 +128,7 @@ def create_company_user(request):
|
||||
}
|
||||
try:
|
||||
user = models.CustomUser.objects.create(email=user_data['email'])
|
||||
except IntegrityError as e:
|
||||
except IntegrityError as e:
|
||||
return Response({"errors": {"details": str(e)}}, status=status.HTTP_409_CONFLICT)
|
||||
|
||||
try:
|
||||
@@ -159,9 +159,13 @@ def create_company_user(request):
|
||||
@api_view(['GET',])
|
||||
@permission_classes([IsAuthenticated,])
|
||||
def my_user(request):
|
||||
qs = User.objects.filter(email=request.user.email)
|
||||
user_serializer = core_serializers.CustomUserReadSerializer(qs, many=True)
|
||||
return Response(data=user_serializer.data)
|
||||
try:
|
||||
instance = User.objects.get(email=request.user.email)
|
||||
user_serializer = core_serializers.CustomUserReadSerializer(instance)
|
||||
return Response(data=user_serializer.data)
|
||||
except Exception as e:
|
||||
return Response({'error': {str(type(e))}}, status=500)
|
||||
|
||||
|
||||
|
||||
@api_view(['POST',])
|
||||
|
||||
Reference in New Issue
Block a user