示例#1
0
    def test_unit_login_username_notExist(self):
        """
        This test case is for when a user tries to login with username
        that does not exists. Then, LogInForm.login_process should return
        None.
        """

        with patch('user_auth.auth_forms.forms') as forms:
            forms.CharField = MagicMock(return_value="username")
            forms.CharField = MagicMock(return_value="password")
            ins = LogInForm()
            ins.cleaned_data = MagicMock(return_value="cleanddata")
            with patch('user_auth.auth_forms.authenticate') as authenticate:
                authenticate.return_value = None
                request = MagicMock()
                ret = ins.login_process(request)
                self.assertTrue(authenticate.called)
                self.assertTrue(not ret)
示例#2
0
    def test_unit_loginform(self):
        """
        This is unit test for LogInForm.

        """

        with patch('user_auth.auth_forms.forms') as form:
            form.CharField = MagicMock(return_value="charfiled")
            with patch('user_auth.auth_forms.authenticate') as authenticate:
                ins = LogInForm()
                ins.cleaned_data = MagicMock(return_value=None)
                authenticate.return_value = MagicMock()
                authenticate.return_value.is_active = True
                with patch('user_auth.auth_forms.login') as login:
                    login.return_value = None
                    request = MagicMock()
                    ins.login_process(request)

                    # asserts.
                    self.assertTrue(login.called)
                    self.assertTrue(authenticate.called)