<commit_before>import hmac
import hashlib
import json
import os

import mock

from django.core.urlresolvers import reverse
from django.test import TestCase
from django.conf import settings
from django.core import mail
from django.contrib.auth import get_user_model

from headsupper.base.models import Project, Payload


sample_dir = os.path.dirname(__file__)

samples = {
    'first-line': os.path.join(sample_dir, 'sample-first-line.json'),
    'tagged': os.path.join(sample_dir, 'sample-tagged.json'),
}

TAGGED_RESPONSE = json.load(open(os.path.join(sample_dir, 'tags.json')))
COMMITS_RESPONSE = json.load(open(os.path.join(sample_dir, 'commits.json')))


class Response(object):
    def __init__(self, content=None, status_code=200, headers=None):
        self.content = content
        self.status_code = status_code
        self.headers = headers or {}

    def json(self):
        return self.content

    def iter_content(self, chunk_size=1024):
        increment = 0
        while True:
            chunk = self.content[increment: increment + chunk_size]
            increment += chunk_size
            if not chunk:
                break
            yield chunk


class Tests(TestCase):

    @classmethod
    def setUpClass(cls):
        super(Tests, cls).setUpClass()
        settings.GITHUB_API_ROOT = 'https://api-example'

        cls.user = get_user_model().objects.create(username='peterbe')

    url = reverse('home')

    def _send(self, sample, secret=None):
        headers = {}
        with open(samples[sample]) as f:
            payload = f.read()
            if secret:
                signature = 'sha1=' + hmac.new(
                    secret.encode('utf-8'),
                    payload,
                    hashlib.sha1
                ).hexdigest()
                headers['HTTP_X_HUB_SIGNATURE'] = signature
            return self.client.post(
                self.url,
                content_type='application/json',
                data=payload,
                **headers
            )

    def test_view_home(self):<commit_msg>test fix<commit_after>import hmac
import hashlib
import json
import os

import mock

from django.core.urlresolvers import reverse
from django.test import TestCase
from django.conf import settings
from django.core import mail
from django.contrib.auth import get_user_model

from headsupper.base.models import Project, Payload


sample_dir = os.path.dirname(__file__)

samples = {
    'first-line': os.path.join(sample_dir, 'sample-first-line.json'),
    'tagged': os.path.join(sample_dir, 'sample-tagged.json'),
}

TAGGED_RESPONSE = json.load(open(os.path.join(sample_dir, 'tags.json')))
COMMITS_RESPONSE = json.load(open(os.path.join(sample_dir, 'commits.json')))


class Response(object):
    def __init__(self, content=None, status_code=200, headers=None):
        self.content = content
        self.status_code = status_code
        self.headers = headers or {}

    def json(self):
        return self.content

    def iter_content(self, chunk_size=1024):
        increment = 0
        while True:
            chunk = self.content[increment: increment + chunk_size]
            increment += chunk_size
            if not chunk:
                break
            yield chunk


class Tests(TestCase):

    @classmethod
    def setUpClass(cls):
        super(Tests, cls).setUpClass()
        settings.GITHUB_API_ROOT = 'https://api-example'

        cls.user = get_user_model().objects.create(username='peterbe')

    url = reverse('base:home')

    def _send(self, sample, secret=None):
        headers = {}
        with open(samples[sample]) as f:
            payload = f.read()
            if secret:
                signature = 'sha1=' + hmac.new(
                    secret.encode('utf-8'),
                    payload,
                    hashlib.sha1
                ).hexdigest()
                headers['HTTP_X_HUB_SIGNATURE'] = signature
            return self.client.post(
                self.url,
                content_type='application/json',
                data=payload,
                **headers
            )

    def test_view_home(self):
{'fraction_non_alphanumeric': 0.10499515033947623, 'fraction_numerical': 0.00533462657613967, 'mean_word_length': 2.2429245283018866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6701048', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1181, 'n_words': 260}