Example #1
0
 def test_user_logined_visit(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = self.client.session
     sessionManager.setLogin("test_admin")
     response = c.get(url_login, follow=True)
     self.assertRedirects(response, url_index)
Example #2
0
 def test_admin_visit_index(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = c.session
     sessionManager.setLogin('test_admin')
     response = c.get(url_index_admin)
     self.assertEqual(response.status_code, 200)
     self.assertTemplateUsed(response, 'AdminIndex.html')
Example #3
0
 def test_customer_logout(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = self.client.session
     sessionManager.setLogin('test_customer')
     response = c.get(url_logout, follow=True)
     self.assertRedirects(response, url_index)
     session = self.client.session
     self.assertEqual('Offline', session.get("LoginStatus"))
Example #4
0
def login(request):
    sessionManager = SessionManager(request)
    if request.method == 'POST':
        loginForm = LoginForm(request.POST)
        if loginForm.is_valid():
            username = loginForm.cleaned_data.get('username')
            password = loginForm.cleaned_data.get('password')
            user = Customer.objects.get(username=username)
            sessionManager.setLogin(username)
            return HttpResponseRedirect(url_index_logined)
    else:
        if sessionManager.isLogined():
            return HttpResponseRedirect(url_index)
        else:
            loginForm = LoginForm()
    return render(request, 'loginUI.html', {'loginForm': loginForm})
Example #5
0
 def test_ChangePassword_successChange(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = self.client.session
     sessionManager.setLogin('test_customer')
     response = c.post(url_change_password, {
         'oldPassword': '******',
         'newPassword': '******',
         'confirmPassword': "******"
     },
                       follow=True)
     self.assertRedirects(response, url_login)
     response = c.post('/login/', {
         'username': '******',
         'password': '******'
     },
                       follow=True)
     self.assertRedirects(response, url_index_customer)
     session = self.client.session
     self.assertEqual("test_customer", session.get("Username"))
     self.assertEqual("Online", session.get("LoginStatus"))