From 8f1d678d7e6fee0e88f4b115f23d26dc556f4a7d Mon Sep 17 00:00:00 2001 From: Mirabel Ekwenugo Date: Tue, 15 Nov 2016 12:13:15 +0100 Subject: [PATCH 1/2] add user test for update, delete and get all users. #14 --- maintt/tests/models/tests_user_profile.py | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/maintt/tests/models/tests_user_profile.py b/maintt/tests/models/tests_user_profile.py index 66e0936..db061f6 100644 --- a/maintt/tests/models/tests_user_profile.py +++ b/maintt/tests/models/tests_user_profile.py @@ -1,5 +1,6 @@ -from django.test import TestCase +from django.test import TestCase, Client from faker import Faker +from rest_framework.test import force_authenticate from django.contrib.auth.models import User from api.models import UserProfile @@ -16,6 +17,7 @@ 'is_staff': 1 } + class UserProfileTestCase(TestCase): ''' Test cases for the UserProfile model that has a @@ -55,3 +57,34 @@ def test_user_profile_created(self): self.assertIsNotNone(profile.created_at) self.assertIsNotNone(profile.updated_at) + def test_user_profile_updated(self): + ''' + Tests if User Profile Updates when a user field is changed + ''' + user = User.objects.get(username=user1['username']) + profile = UserProfile.objects.get(user=user) + self.assertEqual(user.last_name, user1['last_name']) + user.last_name = 'some_new_last_name' + user.save() + # check if user last_name has updated to new name + self.assertEqual(user.last_name, 'some_new_last_name') + self.assertEqual(profile.user.last_name, 'some_new_last_name') + + def test_user_profile_deleted(self): + ''' + Tests if User Profile gets deleted when User is deleted + ''' + user = User.objects.filter(username=user1['username']) + profile = UserProfile.objects.filter(user=user) + user.delete() + self.assertFalse(user.exists()) + self.assertFalse(profile.exists()) + + def test_get_users(self): + user2 = User.objects.create_user(fake.user_name(), fake.email(), fake.password()) + user2.save() + client = Client() + client.login(username=user1['username'], password=user1['password']) + response = client.get('/api/users/') + self.assertEqual(response.status_code, 200) + self.assertTrue(len(response.json()['results']) == 2) From 5d9e0de93cb490f601b72c4d7c064d6256f125db Mon Sep 17 00:00:00 2001 From: Mirabel Ekwenugo Date: Tue, 15 Nov 2016 12:24:42 +0100 Subject: [PATCH 2/2] remove force_authentication module #14 --- maintt/tests/models/tests_user_profile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maintt/tests/models/tests_user_profile.py b/maintt/tests/models/tests_user_profile.py index db061f6..5b91d0e 100644 --- a/maintt/tests/models/tests_user_profile.py +++ b/maintt/tests/models/tests_user_profile.py @@ -1,6 +1,5 @@ from django.test import TestCase, Client from faker import Faker -from rest_framework.test import force_authenticate from django.contrib.auth.models import User from api.models import UserProfile