from django.urls import reverse
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
from rest_framework import status


class AccountsTest(APITestCase):
    def setUp(self):
        # We want to go ahead and originally create a user.
        self.test_user = User.objects.create_user(
            'testuser', 'test@example.com', 'testpassword')

        # URL for creating an account.
        self.create_url = reverse('account-create')

        def test_create_user(self):
            """
            Ensure we can create a new user and a valid token is created with it.
            """
            data = {
                    'email': 'foobar@example.com',
                    'password': 'somepassword'
                    }

            response = self.client.post(self.create_url , data, format='json')
            user = User.objects.latest('id')
            ...
            token = Token.objects.get(user=user)
            self.assertEqual(response.data['token'], token.key)