<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_django-watchman
------------

Tests for `django-watchman` views module.
"""

import json
import unittest

from mock import patch

from watchman import views


class TestWatchman(unittest.TestCase):

    def setUp(self):
        pass

    @patch('watchman.views.check_databases')
    def test_response_content_type_json(self, patched_check_databases):
        patched_check_databases.return_value = []
        response = views.status('')
        self.assertEqual(response['Content-Type'], 'application/json')

    @patch('watchman.views.check_databases')
    def test_response_contains_expected_checks(self, patched_check_databases):
        expected_checks = ['databases']
        patched_check_databases.return_value = []
        response = views.status('')
        content = json.loads(response.content)
        self.assertItemsEqual(expected_checks, content.keys())

    def tearDown(self):
        pass<commit_msg>Test exception handling in `check_database`<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_django-watchman
------------

Tests for `django-watchman` views module.
"""

import json
import unittest

from mock import patch

from watchman import views


class TestWatchman(unittest.TestCase):

    def setUp(self):
        pass

    @patch('watchman.views.check_databases')
    def test_response_content_type_json(self, patched_check_databases):
        patched_check_databases.return_value = []
        response = views.status('')
        self.assertEqual(response['Content-Type'], 'application/json')

    @patch('watchman.views.check_databases')
    def test_response_contains_expected_checks(self, patched_check_databases):
        expected_checks = ['databases']
        patched_check_databases.return_value = []
        response = views.status('')
        content = json.loads(response.content)
        self.assertItemsEqual(expected_checks, content.keys())

    def test_check_database_handles_exception(self):
        response = views.check_database('foo')
        self.assertFalse(response['foo']['ok'])
        self.assertEqual(response['foo']['error'], "The connection foo doesn't exist")

    def tearDown(self):
        pass
{'fraction_non_alphanumeric': 0.12433155080213903, 'fraction_numerical': 0.00089126559714795, 'mean_word_length': 3.6098562628336754, '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': '4398300', 'n_tokens_mistral': 662, 'n_tokens_neox': 643, 'n_words': 118}