from django.test import TestCase
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from rest_framework.authtoken.models import Token


class UserTest(TestCase):
    def setUp(self):
        self.test_user = User.objects.create_user('username', 'test@test.com', 'password')
        self.test_user.save()

    def test_user_has_token(self):
        try:
            token = Token.objects.get(user=self.test_user)
            self.assertFalse(token is None)
        except ObjectDoesNotExist:
            self.assertTrue(False)

from django.test import TestCase
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token
from nose.tools import assert_false


class UserTest(TestCase):
    def setUp(self):
        self.test_user = User.objects.create_user('username', 'test@test.com', 'password')
        self.test_user.save()

    def test_user_has_token(self):
        token = Token.objects.get(user=self.test_user)
        assert_false(token is None)

Use nose test tools for the user test
Use nose test tools for the user test

  from django.test import TestCase
  from django.contrib.auth.models import User
- from django.core.exceptions import ObjectDoesNotExist
  from rest_framework.authtoken.models import Token
+ from nose.tools import assert_false
  
  
  class UserTest(TestCase):
      def setUp(self):
          self.test_user = User.objects.create_user('username', 'test@test.com', 'password')
          self.test_user.save()
  
      def test_user_has_token(self):
-         try:
-             token = Token.objects.get(user=self.test_user)
+         token = Token.objects.get(user=self.test_user)
-             self.assertFalse(token is None)
+         assert_false(token is None)
-         except ObjectDoesNotExist:
-             self.assertTrue(False)
  
Use nose test tools for the user test
## Code Before:
from django.test import TestCase
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from rest_framework.authtoken.models import Token


class UserTest(TestCase):
    def setUp(self):
        self.test_user = User.objects.create_user('username', 'test@test.com', 'password')
        self.test_user.save()

    def test_user_has_token(self):
        try:
            token = Token.objects.get(user=self.test_user)
            self.assertFalse(token is None)
        except ObjectDoesNotExist:
            self.assertTrue(False)

## Instruction:
Use nose test tools for the user test
## Code After:
from django.test import TestCase
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token
from nose.tools import assert_false


class UserTest(TestCase):
    def setUp(self):
        self.test_user = User.objects.create_user('username', 'test@test.com', 'password')
        self.test_user.save()

    def test_user_has_token(self):
        token = Token.objects.get(user=self.test_user)
        assert_false(token is None)
