from rest_framework.test import APIClient, APITestCase

from core.models import UserAccount


class AuthTests(APITestCase):

    @classmethod
    def setUpTestData(cls):
        cls.credentials = {'username': 'user', 'password': 'p'}
        cls.user = UserAccount.objects.create(
            username=cls.credentials['username'])
        cls.user.set_password(cls.credentials['password'])
        cls.user.save()
        cls.client = APIClient()

    def test_get_token(self):
        response = self.client.post('/api/get-token/', self.credentials)
        self.assertContains(response, 'token')

    def test_refresh_token(self):
        token = self.client.post('/api/get-token/', self.credentials).data
        response = self.client.post('/api/refresh-token/', token)
        self.assertContains(response, 'token')