from django.test import TestCase
from django.contrib.auth.models import User

from rest_framework_jwt.serializers import JSONWebTokenSerializer
from rest_framework_jwt import utils


class JSONWebTokenSerializerTests(TestCase):
    def setUp(self):
        self.email = 'jpueblo@example.com'
        self.username = 'jpueblo'
        self.password = 'password'
        self.user = User.objects.create_user(
            self.username, self.email, self.password)

        self.data = {
            'username': self.username,
            'password': self.password
        }

    def test_empty(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_invalid_credentials(self):
        self.data['password'] = 'wrong'
        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)

    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)

@@ -3,34 +3,135 @@
 om d
-jango.test import TestCase
+istutils.version import StrictVersion%0A%0Aimport rest_framework%0Afrom django.test import TestCase%0Afrom django.utils import unittest
 %0Afro
@@ -277,16 +277,129 @@
 utils%0A%0A%0A
+drf2 = rest_framework.VERSION %3C StrictVersion('3.0.0')%0Adrf3 = rest_framework.VERSION %3E= StrictVersion('3.0.0')%0A%0A%0A
 class JS
@@ -787,22 +787,344 @@
     
-def test_empty
+@unittest.skipUnless(drf2, 'not supported in this version')%0A    def test_empty_drf2(self):%0A        serializer = JSONWebTokenSerializer()%0A        expected = %7B%0A            'username': ''%0A        %7D%0A%0A        self.assertEqual(serializer.data, expected)%0A%0A    @unittest.skipUnless(drf3, 'not supported in this version')%0A    def test_empty_drf3
 (sel
@@ -1186,32 +1186,32 @@
    expected = %7B%0A
-
             'use
@@ -1212,32 +1212,61 @@
   'username': ''
+,%0A            'password': '',
 %0A        %7D%0A%0A    

Fix tests to maintain compatibility