100% coverage en user api_views
This commit is contained in:
@@ -8,9 +8,6 @@ from users.models import User, SocialNetworks
|
||||
|
||||
|
||||
def user_view(request, user_id=None):
|
||||
if user_id is None:
|
||||
return JsonResponse({'status': 400, 'error': 'No se entrego un user_id'}, status=400)
|
||||
|
||||
user = User.objects.filter(pk=user_id)
|
||||
if user.count() != 1:
|
||||
return JsonResponse({'status': 404, 'error': f'No existe un usuario con id {user_id}'}, status=404)
|
||||
@@ -51,9 +48,6 @@ def _put_user(request, user):
|
||||
|
||||
|
||||
def social_networks_view(request, user_id=None):
|
||||
if user_id is None:
|
||||
return JsonResponse({'status': 400, 'error': 'No se entrego un user_id'}, status=400)
|
||||
|
||||
social_networks = SocialNetworks.objects.filter(user_id=user_id)
|
||||
if social_networks.count() != 1:
|
||||
return JsonResponse({'status': 404, 'error': f'No existe redes sociales de un usuario con id {user_id}'},
|
||||
|
||||
@@ -111,13 +111,14 @@ class TestAPIViews(TestCase):
|
||||
self.assertEqual(social_networks.youtube, new_social_data['youtube'])
|
||||
self.assertEqual(social_networks.twitch, new_social_data['twitch'])
|
||||
|
||||
def test_put_social_networks_empty(self):
|
||||
new_social_data = {}
|
||||
def test_put_social_networks_invalid(self):
|
||||
# max length para los fields es 255 => len('toolong'*37) == 259
|
||||
new_social_data = {'twitter': 'toolong'*37}
|
||||
|
||||
response = self.client.put('/api/users/user/2/social_networks', json.dumps(new_social_data),
|
||||
HTTP_AUTHORIZATION=self._user_header())
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
def test_put_social_networks_not_modifying_self(self):
|
||||
new_social_data = {}
|
||||
|
||||
Reference in New Issue
Block a user