'Make sure only staff members can log in.
Successful posts to the login page will redirect to the original url.
Unsuccessful attempts will continue to render the login page with
a 200 status code.'

def test_login(self):

    login_url = ('%s?next=%s' % (reverse('admin:login'), reverse('admin:index')))
    response = self.client.get(self.index_url)
    self.assertRedirects(response, login_url)
    login = self.client.post(login_url, self.super_login)
    self.assertRedirects(login, self.index_url)
    self.assertFalse(login.context)
    self.client.get(reverse('admin:logout'))
    response = self.client.get(self.index_url)
    self.assertEqual(response.status_code, 302)
    login = self.client.post(login_url, self.super_email_login)
    self.assertContains(login, ERROR_MESSAGE)
    login = self.client.post(login_url, self.super_email_bad_login)
    self.assertContains(login, ERROR_MESSAGE)
    new_user = User(username='jondoe', password='secret', email='super@example.com')
    new_user.save()
    login = self.client.post(login_url, self.super_email_login)
    self.assertContains(login, ERROR_MESSAGE)
    response = self.client.get(self.index_url)
    self.assertEqual(response.status_code, 302)
    login = self.client.post(login_url, self.adduser_login)
    self.assertRedirects(login, self.index_url)
    self.assertFalse(login.context)
    self.client.get(reverse('admin:logout'))
    response = self.client.get(self.index_url)
    self.assertEqual(response.status_code, 302)
    login = self.client.post(login_url, self.changeuser_login)
    self.assertRedirects(login, self.index_url)
    self.assertFalse(login.context)
    self.client.get(reverse('admin:logout'))
    response = self.client.get(self.index_url)
    self.assertEqual(response.status_code, 302)
    login = self.client.post(login_url, self.deleteuser_login)
    self.assertRedirects(login, self.index_url)
    self.assertFalse(login.context)
    self.client.get(reverse('admin:logout'))
    response = self.client.get(self.index_url)
    self.assertEqual(response.status_code, 302)
    login = self.client.post(login_url, self.joepublic_login)
    self.assertEqual(login.status_code, 200)
    self.assertContains(login, ERROR_MESSAGE)
    response = self.client.get(self.index_url)
    self.assertEqual(response.status_code, 302)
    login = self.client.post(login_url, self.no_username_login)
    self.assertEqual(login.status_code, 200)
    self.assertFormError(login, 'form', 'username', ['This    field    is    required.'])
