Exemplo n.º 1
0
    def test_login_user(self):
        """
        Test if user login
        """
        UtilityFunctions.create_user(**payload)

        res = self.client.post(LOGIN_USER_URL, payload)
        self.assertEqual(res.status_code, HTTP_200_OK)
Exemplo n.º 2
0
    def test_user_exists(self):
        """
        Test user already exists
        """
        UtilityFunctions.create_user(**payload)

        res = self.client.post(CREATE_USER_URL, payload)
        self.assertEqual(res.status_code, HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
    def test_is_authenticated(self):
        """
        Test 
        """
        UtilityFunctions.create_user(**payload)
        res = self.client.post(LOGIN_USER_URL, payload)

        res = self.client.get(CHECK_USER_URL)
        self.assertTrue(res.data['user'])

        self.client.post(LOGOUT_USER_URL)
        res = self.client.get(CHECK_USER_URL)
        self.assertFalse(res.data['user'])
Exemplo n.º 4
0
    def test_get_profile(self):
        """
        Test getting user data
        """

        self.user = UtilityFunctions.create_user(**payload)
        self.client.force_authenticate(self.user)

        res = self.client.get(GET_USER_URL)
        self.assertEqual(res.status_code, HTTP_200_OK)

        serializer = UserSerializer(self.user)
        self.assertEqual(res.data, serializer.data)
Exemplo n.º 5
0
    def test_change_password(self):
        """
        Test change password.
        """
        self.user = UtilityFunctions.create_user(**payload)
        self.client.force_authenticate(self.user)

        chnge_pwd_payload = {
            'new_password': '******',
            'old_password': payload['password']
        }

        res = self.client.put(CHANGE_PWD_URL, chnge_pwd_payload)

        res = self.client.post(LOGOUT_USER_URL)

        new_payload = {
            'email': '*****@*****.**',
            'password': '******'
        }

        res = self.client.post(LOGIN_USER_URL, new_payload)
        self.assertEqual(res.status_code, HTTP_200_OK)
Exemplo n.º 6
0
 def has_object_permission(self, request, view, obj):
     return UtilityFunctions.check_client_ip(request)