def test_user_login_fail(self):
        form = LoginForm({'username': '******', 'password': '******'})
        ret_val = form.is_valid()
        self.assertFalse(ret_val)

        # Validate the error
        err = form.errors.as_data()['__all__'][0]
        self.assertEqual(err.message, "Username / Password not valid")
Example #2
0
def login(request):
    state = "Please log in below..."
    if request.POST:
        form = LoginForm(request.POST)
        if form.is_valid():
            return redirect("index")
        else:
            state = "Your username and/or password were incorrect."
    return render(request, "login.html", {"state": state, "form": LoginForm()})
 def test_user_login_fail_pwd(self):
     form = LoginForm({'username': '******', 'password': '******'})
     self.assertFalse(form.is_valid())
 def test_user_login_valid(self):
     form = LoginForm({'username': '******', 'password': '******'})
     self.assertTrue(form.is_valid())