<commit_before>from flask.ext.testing import TestCase
from project import create_app as app_factory
from project.extensions import db
from project.fixtures import load_fixtures


class ProjectTestCase(TestCase):
    """
    Base class for all tests in project
    """

    # noinspection PyAttributeOutsideInit
    def create_app(self):
        self.app = app_factory()
        with self.app.app_context():
            db.create_all()
            load_fixtures(self.app.config['FIXTURES_DIR'])
        return self.app

    # noinspection PyPep8Naming
    def tearDown(self):
        """
        Drop it all!

        DO NOT FORGET TO CALL THIS METHOD WHEN OVERRIDING
        """
        with self.app.app_context():
            db.drop_all()<commit_msg>Added function for logging in tests Added csrf disabler (as a context manager)<commit_after>from flask import url_for
from flask.ext.testing import TestCase
from project import create_app as app_factory
from project.extensions import db
from project.fixtures import load_fixtures
from project.models import User


class DisableCsrf:
    def __init__(self, app):
        self.app = app

    def __enter__(self):
        self.app.config['WTF_CSRF_ENABLED'] = False

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.app.config['WTF_CSRF_ENABLED'] = True


class ProjectTestCase(TestCase):
    """
    Base class for all tests in project
    """
    def log_in(self):
        user = User.query.get(1)
        # assume that login is equal to password
        credentials = {"login": user.login, "password": <PASSWORD>}
        with DisableCsrf(self.app):
            self.client.post(url_for("auth.login"), data=credentials)

    # noinspection PyAttributeOutsideInit
    def create_app(self):
        self.app = app_factory()
        with self.app.app_context():
            db.create_all()
            load_fixtures(self.app.config['FIXTURES_DIR'])
        return self.app

    # noinspection PyPep8Naming
    def tearDown(self):
        """
        Drop it all!

        DO NOT FORGET TO CALL THIS METHOD WHEN OVERRIDING
        """
        with self.app.app_context():
            db.drop_all()
{'fraction_non_alphanumeric': 0.0879222582137899, 'fraction_numerical': 0.0013882461823229986, 'mean_word_length': 2.67687074829932, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, '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': '4083286', 'n_tokens_mistral': 651, 'n_tokens_neox': 624, 'n_words': 173}