class PrivateUseApiTests(TestCase): """Test Api requests that require authentication""" def setUp(self): self.user = create_user(email='*****@*****.**', password='******', name='name') self.client = APIClient() self.client.forcre_authenticate(user=self.user) def test_retrieve_profile_success(self): """Test retrieving profile for logged in used""" res = self.client.get(USER_URL) self.assertEqual(res.status_code, status.HTTP_200_OK) self.assertEqual(res.data, { 'name': res.data.name, 'email': res.data.email }) def test_post_user_id_not_allowed(self): """Test that POST is not allowed on the user id url""" res = self.client.post(USER_URL, {}) self.assertEqual(res.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) def test_update_user_profile(self): """Test updating the user profile for authenticated user""" payload = {'name': 'new name', 'password': '******'} res = self.client.path(USER_URL, payload) self.user.refresh_from_db() self.assertEqual(self.user.name, payload['name']) self.assertTrue(self.user.check_password(payload['password'])) self.assertEqual(res.status_code, status.HTTP_200_OK)