|
@@ -4,6 +4,8 @@ from django.contrib.auth import get_user_model
|
|
from django.core.urlresolvers import reverse
|
|
from django.core.urlresolvers import reverse
|
|
from django.test import TestCase
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
+from misago.users.models import Ban, BAN_USERNAME
|
|
|
|
+
|
|
|
|
|
|
class AuthenticateAPITests(TestCase):
|
|
class AuthenticateAPITests(TestCase):
|
|
def test_api_invalid_credentials(self):
|
|
def test_api_invalid_credentials(self):
|
|
@@ -32,9 +34,6 @@ class AuthenticateAPITests(TestCase):
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
- response = self.client.get(reverse('misago:index'))
|
|
|
|
- self.assertEqual(response.status_code, 200)
|
|
|
|
-
|
|
|
|
response = self.client.get(reverse('misago:api:auth_user'))
|
|
response = self.client.get(reverse('misago:api:auth_user'))
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
@@ -44,8 +43,49 @@ class AuthenticateAPITests(TestCase):
|
|
|
|
|
|
def test_api_signin_banned(self):
|
|
def test_api_signin_banned(self):
|
|
"""login api fails to sign banned user in"""
|
|
"""login api fails to sign banned user in"""
|
|
- raise NotImplemented("TODO: test_api_signin_banned")
|
|
|
|
|
|
+ User = get_user_model()
|
|
|
|
+ User.objects.create_user('Bob', 'bob@test.com', 'Pass.123')
|
|
|
|
+
|
|
|
|
+ ban = Ban.objects.create(check_type=BAN_USERNAME,
|
|
|
|
+ banned_value='bob',
|
|
|
|
+ user_message='You are tragically banned.')
|
|
|
|
+
|
|
|
|
+ response = self.client.post(
|
|
|
|
+ reverse('misago:api:login'),
|
|
|
|
+ data={'username': 'Bob', 'password': 'Pass.123'})
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+
|
|
|
|
+ response_json = json.loads(response.content)
|
|
|
|
+ self.assertEqual(response_json['code'], 'banned')
|
|
|
|
+ self.assertEqual(response_json['detail']['message']['plain'],
|
|
|
|
+ ban.user_message)
|
|
|
|
+ self.assertEqual(response_json['detail']['message']['html'],
|
|
|
|
+ '<p>%s</p>' % ban.user_message)
|
|
|
|
+
|
|
|
|
+ def test_api_signin_inactive_admin(self):
|
|
|
|
+ """login api fails to sign admin-activated user in"""
|
|
|
|
+ User = get_user_model()
|
|
|
|
+ User.objects.create_user('Bob', 'bob@test.com', 'Pass.123',
|
|
|
|
+ requires_activation=1)
|
|
|
|
+
|
|
|
|
+ response = self.client.post(
|
|
|
|
+ reverse('misago:api:login'),
|
|
|
|
+ data={'username': 'Bob', 'password': 'Pass.123'})
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
+
|
|
|
|
+ response_json = json.loads(response.content)
|
|
|
|
+ self.assertEqual(response_json['code'], 'inactive_user')
|
|
|
|
+
|
|
|
|
+ def test_api_signin_inactive_user(self):
|
|
|
|
+ """login api fails to sign user-activated user in"""
|
|
|
|
+ User = get_user_model()
|
|
|
|
+ User.objects.create_user('Bob', 'bob@test.com', 'Pass.123',
|
|
|
|
+ requires_activation=2)
|
|
|
|
+
|
|
|
|
+ response = self.client.post(
|
|
|
|
+ reverse('misago:api:login'),
|
|
|
|
+ data={'username': 'Bob', 'password': 'Pass.123'})
|
|
|
|
+ self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
- def test_api_signin_inactive(self):
|
|
|
|
- """login api fails to sign inactive user in"""
|
|
|
|
- raise NotImplemented("TODO: test_api_signin_inactive")
|
|
|
|
|
|
+ response_json = json.loads(response.content)
|
|
|
|
+ self.assertEqual(response_json['code'], 'inactive_admin')
|