def test_empty_drf2(self): serializer = JSONWebTokenSerializer() expected = { 'username': '' } self.assertEqual(serializer.data, expected)
def test_create(self): serializer = JSONWebTokenSerializer(data=self.data) is_valid = serializer.is_valid() token = serializer.object['token'] decoded_payload = utils.jwt_decode_handler(token) self.assertTrue(is_valid) self.assertEqual(decoded_payload['username'], self.username)
def test_required_fields(self): serializer = JSONWebTokenSerializer(data={}) is_valid = serializer.is_valid() expected_error = { 'username': ['This field is required.'], 'password': ['This field is required.'] } self.assertFalse(is_valid) self.assertEqual(serializer.errors, expected_error)
def test_invalid_credentials(self): self.data['password'] = '******' serializer = JSONWebTokenSerializer(data=self.data) is_valid = serializer.is_valid() expected_error = { 'non_field_errors': ['Unable to login with provided credentials.'] } self.assertFalse(is_valid) self.assertEqual(serializer.errors, expected_error)
def test_disabled_user(self): self.user.is_active = False self.user.save() serializer = JSONWebTokenSerializer(data=self.data) is_valid = serializer.is_valid() expected_error = { 'non_field_errors': ['User account is disabled.'] } self.assertFalse(is_valid) self.assertEqual(serializer.errors, expected_error)