<commit_before># coding: utf-8

from flask.ext.testing import TestCase
from flask import current_app, abort
from app import dbsql


class ErrorsTestCase(TestCase):

    def setUp(self):
        dbsql.create_all()

    def create_app(self):
        return current_app

    def tearDown(self):
        dbsql.session.remove()
        dbsql.drop_all()

    @current_app.route('/forbidden')
    def forbidden_page():
        abort(403)

    @current_app.route('/page_not_found')
    def page_not_found():
        abort(404)

    @current_app.route('/internal_server_error')
    def internal_server_error():
        1 // 0

    def test_forbidden(self):
        response = self.client.get('/forbidden')
        self.assert_403(response)
        self.assertEqual('text/html; charset=utf-8', response.content_type)
        self.assert_template_used("errors/403.html")

    def test_page_not_found(self):
        response = self.client.get('/page_not_found')
        self.assert_404(response)
        self.assertEqual('text/html; charset=utf-8', response.content_type)
        self.assert_template_used("errors/404.html")

    def test_internal_server_error(self):
        current_app.config['DEBUG'] = False
        current_app.config['PROPAGATE_EXCEPTIONS'] = False
        response = self.client.get('/internal_server_error')
        self.assert_500(response)
        self.assertEqual('text/html; charset=utf-8', response.content_type)
        self.assert_template_used("errors/500.html")<commit_msg>Agregados tests restantes para main.errors<commit_after># coding: utf-8

from flask.ext.testing import TestCase
from flask import current_app, abort
from app import dbsql


class ErrorsTestCase(TestCase):

    def setUp(self):
        dbsql.create_all()

    def create_app(self):
        return current_app

    def tearDown(self):
        dbsql.session.remove()
        dbsql.drop_all()

    @current_app.route('/forbidden')
    def forbidden_page():
        abort(403)

    @current_app.route('/page_not_found')
    def page_not_found():
        abort(404)

    @current_app.route('/internal_server_error')
    def internal_server_error():
        1 // 0

    def test_forbidden(self):
        response = self.client.get('/forbidden')
        self.assert_403(response)
        self.assertEqual('text/html; charset=utf-8', response.content_type)
        self.assert_template_used("errors/403.html")

    def test_forbidden_json(self):
        response = self.client.get('/forbidden',
                                   headers={'Accept': 'application/json'})
        self.assert_403(response)
        self.assertEqual('application/json', response.content_type)
        self.assertEquals(response.json, {'error': 'forbidden'})

    def test_page_not_found(self):
        response = self.client.get('/page_not_found')
        self.assert_404(response)
        self.assertEqual('text/html; charset=utf-8', response.content_type)
        self.assert_template_used("errors/404.html")

    def test_page_not_found_json(self):
        response = self.client.get('/page_not_found',
                                   headers={'Accept': 'application/json'})
        self.assert_404(response)
        self.assertEqual('application/json', response.content_type)
        self.assertEquals(response.json, {'error': 'not found'})

    def test_internal_server_error(self):
        current_app.config['DEBUG'] = False
        current_app.config['PROPAGATE_EXCEPTIONS'] = False
        response = self.client.get('/internal_server_error')
        self.assert_500(response)
        self.assertEqual('text/html; charset=utf-8', response.content_type)
        self.assert_template_used("errors/500.html")

    def test_internal_server_error_json(self):
        current_app.config['DEBUG'] = False
        current_app.config['PROPAGATE_EXCEPTIONS'] = False
        response = self.client.get('/internal_server_error',
                                   headers={'Accept': 'application/json'})
        self.assert_500(response)
        self.assertEqual('application/json', response.content_type)
        self.assertEquals(response.json, {'error': 'internal server error'})
{'fraction_non_alphanumeric': 0.11936339522546419, 'fraction_numerical': 0.01663853387991319, 'mean_word_length': 3.0271844660194174, '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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3712304', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1211, 'n_words': 192}