<commit_before>import hashlib
import hmac
import json

from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.core.urlresolvers import reverse
from django.http import HttpRequest, HttpResponse
from django.test import TestCase, override_settings

from buildservice.models import Repository
from buildservice.utils import decorators
from buildservice.utils.testing import create_user_token


def view(request):
    return HttpResponse(request.body)


view_token = decorators.oauth_token_required(view)
view_signature = decorators.signature_required(view)
view_anonymous = decorators.anonymous_user_required(view)
view_json = decorators.require_json(view)
view_api_key = decorators.require_api_key(view)


@override_settings(GITHUB_HOOK_SECRET='ssssecret', BUILDSERVICE_API_KEY='Key')
class DecoratorsTestCase(TestCase):

    def setUp(self):
        self.user = get_user_model().objects.create_user(username='vvv', password='<PASSWORD>')

    def test_oauth_token_required_anonymous(self):
        req = HttpRequest()
        req.user = AnonymousUser()
        resp = view_token(req)
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.url, reverse('oauth_login'))
<commit_msg>fix test_decorators<commit_after>import hashlib
import hmac
import json

from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.core.urlresolvers import reverse
from django.http import HttpRequest, HttpResponse
from django.test import TestCase, override_settings

from buildservice.models import Repository
from buildservice.utils import decorators
from buildservice.utils.testing import create_user_token


def view(request):
    return HttpResponse(str(request))


view_token = decorators.oauth_token_required(view)
view_signature = decorators.signature_required(view)
view_anonymous = decorators.anonymous_user_required(view)
view_json = decorators.require_json(view)
view_api_key = decorators.require_api_key(view)


@override_settings(GITHUB_HOOK_SECRET='ssssecret', BUILDSERVICE_API_KEY='Key')
class DecoratorsTestCase(TestCase):

    def setUp(self):
        self.user = get_user_model().objects.create_user(username='vvv', password='<PASSWORD>')

    def test_oauth_token_required_anonymous(self):
        req = HttpRequest()
        req.user = AnonymousUser()
        resp = view_token(req)
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.url, reverse('oauth_login'))

{'fraction_non_alphanumeric': 0.08287073750991276, 'fraction_numerical': 0.0023790642347343376, 'mean_word_length': 5.950413223140496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5314499', 'n_tokens_mistral': 759, 'n_tokens_neox': 738, 'n_words': 151}