<commit_before>from django.test import TestCase
from django.test.client import RequestFactory
from django.contrib.auth.models import User
from oauth2_consumer.handlers.bearer import BearerHandler
from oauth2_consumer.models import AuthorizationToken, Client, Scope


class TestBearerHandler(TestCase):
    
    def setUp(self):
        self.oclient = Client(name="Test Client", access_host="http://localhost/")
        self.oclient.save()
        
        self.scope = Scope(short_name="test", full_name="Test Scope", description="Scope for testing")
        self.scope.save()
        
        self.user = User(username="Test", password="<PASSWORD>", email="<EMAIL>")
        self.user.save()
        
        self.at = AuthorizationToken(client=self.oclient, user=self.user)
        self.at.save()
        self.at.scope = [self.scope]
        self.at.save()
        
        self.rt = self.at.generate_refresh_token()
        
        self.token = self.rt.generate_access_token()
        
        self.handler = BearerHandler()
        
        self.factory = RequestFactory()

    def test_access_token(self):
        request = self.factory.get("/")
        
        token = self.handler.access_token(self.token.token, request)
        
        self.assertEqual(token, self.token)
        
        token = self.handler.access_token("invalid", request)
        
        self.assertEqual(token, None)<commit_msg>Added test for handler authentication<commit_after>from django.test import TestCase
from django.test.client import RequestFactory
from django.contrib.auth.models import User
from oauth2_consumer.handlers.bearer import BearerHandler
from oauth2_consumer.models import AuthorizationToken, Client, Scope


class TestBearerHandler(TestCase):
    
    def setUp(self):
        self.oclient = Client(name="Test Client", access_host="http://localhost/")
        self.oclient.save()
        
        self.scope = Scope(short_name="test", full_name="Test Scope", description="Scope for testing")
        self.scope.save()
        
        self.user = User(username="Test", password="<PASSWORD>", email="<EMAIL>")
        self.user.save()
        
        self.at = AuthorizationToken(client=self.oclient, user=self.user)
        self.at.save()
        self.at.scope = [self.scope]
        self.at.save()
        
        self.rt = self.at.generate_refresh_token()
        
        self.token = self.rt.generate_access_token()
        
        self.handler = BearerHandler()
        
        self.factory = RequestFactory()

    def test_access_token(self):
        request = self.factory.get("/")
        
        token = self.handler.access_token(self.token.token, request)
        
        self.assertEqual(token, self.token)
        
        token = self.handler.access_token("invalid", request)
        
        self.assertEqual(token, None)
    
    def test_authenticate(self):
        request = self.factory.get("/")
        
        user = self.handler.authenticate(self.token.token, request)
        
        self.assertEqual(user, self.user)
        
        user = self.handler.authenticate("invalid", request)
        
        self.assertEqual(user, None)
{'fraction_non_alphanumeric': 0.11230283911671925, 'fraction_numerical': 0.0012618296529968455, 'mean_word_length': 2.4355362946912242, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3286003', 'n_tokens_mistral': 905, 'n_tokens_neox': 886, 'n_words': 163}