<commit_before>import unittest
import json
import os
from mooch.app import app

FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "fixtures")

class Test_GithubHook(unittest.TestCase):

    def setUp(self):
        self.app = app.test_client()

    def get_json(self, path, **params):
        response = self.app.get(path, query_string=params)
        self.assertEqual(response.status_code, 200,
                "Server unexpectedly returned %s.  Response: \n\n%s" %
                (response.status_code, response.data))
        try:
            return json.loads(response.data)
        except ValueError:
            self.fail(u"`%s` returned malfored JSON!\n%s" %
                    (path, response.data[:200]))

    def post_json(self, path, data, **params):
        data = json.dumps(data)
        headers = [('Content-Type', 'application/json')]
        return self.app.post(path, data=data, headers=headers)

    def test_should_store_last_commit_time(self):

        # When issuing Github POST request
        payload = json.load(open(os.path.join(FIXTURES_DIR, "github-hook.json")))
        self.post_json("/hooks/github", payload)<commit_msg>Tests refactor<commit_after>import unittest
import json
import os
from mooch.app import app

FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "fixtures")


class MoochTest(unittest.TestCase):

    def setUp(self):
        self.app = app.test_client()

    def get_json(self, path, **params):
        response = self.app.get(path, query_string=params)
        self.assertEqual(response.status_code, 200,
                "Server unexpectedly returned %s.  Response: \n\n%s" %
                (response.status_code, response.data))
        try:
            return json.loads(response.data)
        except ValueError:
            self.fail(u"`%s` returned malfored JSON!\n%s" %
                    (path, response.data[:200]))

    def post_json(self, path, data, **params):
        data = json.dumps(data)
        headers = [('Content-Type', 'application/json')]
        return self.app.post(path, data=data, headers=headers)


class Test_GithubHook(MoochTest):

    def test_should_store_last_commit_time(self):

        # When issuing Github POST request
        payload = json.load(open(os.path.join(FIXTURES_DIR, "github-hook.json")))
        self.post_json("/hooks/github", payload)
{'fraction_non_alphanumeric': 0.1256388415672913, 'fraction_numerical': 0.005110732538330494, 'mean_word_length': 2.819512195121951, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2042912', 'n_tokens_mistral': 754, 'n_tokens_neox': 722, 'n_words': 148}