<commit_before>import requests
from coreapi import Client
from coreapi.auth import TokenAuthentication


from rest_framework import status
from rest_framework.test import APITestCase
from rest_framework.test import APIClient
from rest_framework.test import CoreAPIClient
from rest_framework.test import RequestsClient
from rest_framework.reverse import reverse
from rest_framework.authtoken.models import Token

from django.contrib.auth.models import User
from django.conf import settings

class TokenTests(APITestCase):
    def setUp(self):
        self.user = User.objects.create_user(username='john',
                                        password='<PASSWORD>')
        self.token = Token.objects.get(user=self.user)

    def test_get_token(self):

        url = '/timeside/api-token-auth/'
        client = APIClient()
        auth = {'username':'john', 'password':'<PASSWORD>'}
        token_request = client.post(url, data=auth)
        self.assertEqual(token_request.status_code,200)
        self.assertEqual(token_request.json()['token'],self.token.key)


    def test_token_auth(self):
        client = APIClient()
        users_request = client.get('/timeside/api/users/',format='json')
        self.assertEqual(users_request.status_code,401)
        client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
        users_request_auth = client.get('/timeside/api/users/',format='json')
        self.assertEqual(users_request_auth.status_code,200)
        data = users_request_auth.json()
        usernames = []
        for user in data:
            usernames.append(user['username'])
        self.assertIn(self.user.username, usernames)
<commit_msg>remove usefull import in test_token<commit_after>import requests
from coreapi import Client
from coreapi.auth import TokenAuthentication


from rest_framework import status
from rest_framework.test import APITestCase
from rest_framework.test import APIClient
from rest_framework.reverse import reverse
from rest_framework.authtoken.models import Token

from django.contrib.auth.models import User
from django.conf import settings

class TokenTests(APITestCase):
    def setUp(self):
        self.user = User.objects.create_user(username='john',
                                        password='<PASSWORD>')
        self.token = Token.objects.get(user=self.user)

    def test_get_token(self):

        url = '/timeside/api-token-auth/'
        client = APIClient()
        auth = {'username':'john', 'password':'<PASSWORD>'}
        token_request = client.post(url, data=auth)
        self.assertEqual(token_request.status_code,200)
        self.assertEqual(token_request.json()['token'],self.token.key)


    def test_token_auth(self):
        client = APIClient()
        users_request = client.get('/timeside/api/users/',format='json')
        self.assertEqual(users_request.status_code,401)
        client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
        users_request_auth = client.get('/timeside/api/users/',format='json')
        self.assertEqual(users_request_auth.status_code,200)
        data = users_request_auth.json()
        usernames = []
        for user in data:
            usernames.append(user['username'])
        self.assertIn(self.user.username, usernames)

{'fraction_non_alphanumeric': 0.1046831955922865, 'fraction_numerical': 0.005509641873278237, 'mean_word_length': 3.398384925975774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '111189', 'n_tokens_mistral': 930, 'n_tokens_neox': 920, 'n_words': 178}