<commit_before>import os
import random

import pybossa.web as web
import pybossa.model as model
from pybossa.core import db

_here = os.path.dirname(__file__)
web.app.config['TESTING'] = True
web.app.config['SQLALCHEMY_DATABASE_URI'] = web.app.config['SQLALCHEMY_DATABASE_TEST_URI']
#engine = model.create_engine(web.app.config['SQLALCHEMY_DATABASE_URI'])
#model.set_engine(engine)

class Fixtures:
    fullname = u'<NAME>'
    fullname2 = u'<NAME>'
    email_addr = u'<EMAIL>'
    email_addr2 = u'<EMAIL>'
    name = u'tester'
    name2 = u'tester-2'
    api_key = 'tester'
    api_key_2 = 'tester-2'
    app_name = u'test-app'
    password = u'<PASSWORD>'

    @classmethod
    def create(cls,sched='default'):
        user,user2 = Fixtures.create_users()

        info = {
            'total': 150,
            'long_description': 'hello world',
            'task_presenter': 'TaskPresenter',
            'sched': sched
            }

        app = Fixtures.create_app(info)
        app.owner = user

        db.session.add(user)
        db.session.commit()
        db.session.add(user2)
        db.session.commit()
        db.session.add(app)

        task_info = {
            'n_answers': 10,
            'question': 'My random question',
            'url': 'my url'
            }
        task_run_info = {
            'answer': u'annakarenina'
            }

        # Create the task and taskruns for the first app
        for i in range (0,10):
             task, task_run = Fixtures.create_task_and_run(task_info, task_run_info, app, user,i)
             db.session.add_all([task, task_run])
        db.session.commit()
        db.session.remove()

    @classmethod
    def create_2(cls,sched='default'):
        user,user2 = Fixtures.create_users()

        info = {
            'total': 150,
            'long_description': 'hello world',
            'task_presenter': 'TaskPresenter',
            'sched': sched
            }
        
        app = Fixtures.create_app(info)
        app.owner = user

        db.session.add_all([user, user2, app])

        task_info = {
            'n_answers': 10,
            'question': 'My random question',
            'url': 'my url'
            }
        task_run_info = {
            'answer': u'annakarenina'
            }

        # Create the task and taskruns for the first app
        task, task_run = Fixtures.create_task_and_run(task_info, task_run_info, app, user,1)
        db.session.add_all([task, task_run])

        db.session.commit()
        db.session.remove()


    @classmethod
    def create_users(cls):
        user = model.User(
                email_addr = cls.email_addr, 
                name = cls.name, 
                passwd_hash = <PASSWORD>.password,
                fullname = cls.fullname, 
                api_key = cls.api_key)

        user2 = model.User(
                email_addr = cls.email_addr2, 
                name = cls.name2, 
                passwd_hash = cls.password + "2",
                fullname = cls.fullname2, 
                api_key=cls.api_key_2)
        
        return user,user2

    @classmethod
    def create_app(cls,info):
        app = model.App(
                name = u'My New App',
                short_name = cls.app_name,
                description = u'description',
                hidden = 0,
                info = info
            )
        return app

    @classmethod
    def create_task_and_run(cls,task_info, task_run_info, app, user, order):
        task = model.Task(app_id = 1, state = '0', info = task_info)
        task.app = app
        # Taskruns will be assigned randomly to a signed user or an anonymous one
        if random.randint(0,1) == 1:
            task_run = model.TaskRun(
                    app_id = 1, 
                    task_id = 1, 
                    user_id = 1, 
                    info = task_run_info)
            task_run.user = user
        else:
            task_run = model.TaskRun(
                    app_id = 1, 
                    task_id = 1, 
                    user_ip = '127.0.0.%s' % order, 
                    info = task_run_info)
        task_run.task = task
        return task,task_run <commit_msg>Set csrf to false while testing<commit_after>import os
import random

import pybossa.web as web
import pybossa.model as model
from pybossa.core import db

_here = os.path.dirname(__file__)
web.app.config['TESTING'] = True
web.app.config['CSRF_ENABLED'] = False
web.app.config['SQLALCHEMY_DATABASE_URI'] = web.app.config['SQLALCHEMY_DATABASE_TEST_URI']
#engine = model.create_engine(web.app.config['SQLALCHEMY_DATABASE_URI'])
#model.set_engine(engine)

class Fixtures:
    fullname = u'T Tester'
    fullname2 = u'T Tester 2'
    email_addr = u'<EMAIL>'
    email_addr2 = u'<EMAIL>'
    name = u'tester'
    name2 = u'tester-2'
    api_key = 'tester'
    api_key_2 = 'tester-2'
    app_name = u'test-app'
    password = u'<PASSWORD>'

    @classmethod
    def create(cls,sched='default'):
        user,user2 = Fixtures.create_users()

        info = {
            'total': 150,
            'long_description': 'hello world',
            'task_presenter': 'TaskPresenter',
            'sched': sched
            }

        app = Fixtures.create_app(info)
        app.owner = user

        db.session.add(user)
        db.session.commit()
        db.session.add(user2)
        db.session.commit()
        db.session.add(app)

        task_info = {
            'n_answers': 10,
            'question': 'My random question',
            'url': 'my url'
            }
        task_run_info = {
            'answer': u'annakarenina'
            }

        # Create the task and taskruns for the first app
        for i in range (0,10):
             task, task_run = Fixtures.create_task_and_run(task_info, task_run_info, app, user,i)
             db.session.add_all([task, task_run])
        db.session.commit()
        db.session.remove()

    @classmethod
    def create_2(cls,sched='default'):
        user,user2 = Fixtures.create_users()

        info = {
            'total': 150,
            'long_description': 'hello world',
            'task_presenter': 'TaskPresenter',
            'sched': sched
            }

        app = Fixtures.create_app(info)
        app.owner = user

        db.session.add_all([user, user2, app])

        task_info = {
            'n_answers': 10,
            'question': 'My random question',
            'url': 'my url'
            }
        task_run_info = {
            'answer': u'annakarenina'
            }

        # Create the task and taskruns for the first app
        task, task_run = Fixtures.create_task_and_run(task_info, task_run_info, app, user,1)
        db.session.add_all([task, task_run])

        db.session.commit()
        db.session.remove()


    @classmethod
    def create_users(cls):
        user = model.User(
                email_addr = cls.email_addr,
                name = cls.name,
                passwd_hash = cls.password,
                fullname = cls.fullname,
                api_key = cls.api_key)

        user2 = model.User(
                email_addr = cls.email_addr2,
                name = cls.name2,
                passwd_hash = cls.password + "2",
                fullname = cls.fullname2,
                api_key=cls.api_key_2)

        return user,user2

    @classmethod
    def create_app(cls,info):
        app = model.App(
                name = u'My New App',
                short_name = cls.app_name,
                description = u'description',
                hidden = 0,
                info = info
            )
        return app

    @classmethod
    def create_task_and_run(cls,task_info, task_run_info, app, user, order):
        task = model.Task(app_id = 1, state = '0', info = task_info)
        task.app = app
        # Taskruns will be assigned randomly to a signed user or an anonymous one
        if random.randint(0,1) == 1:
            task_run = model.TaskRun(
                    app_id = 1,
                    task_id = 1,
                    user_id = 1,
                    info = task_run_info)
            task_run.user = user
        else:
            task_run = model.TaskRun(
                    app_id = 1,
                    task_id = 1,
                    user_ip = '127.0.0.%s' % order,
                    info = task_run_info)
        task_run.task = task
        return task,task_run
{'fraction_non_alphanumeric': 0.10484350827085565, 'fraction_numerical': 0.011543496370343924, 'mean_word_length': 1.6303599374021909, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '597901', 'n_tokens_mistral': 2721, 'n_tokens_neox': 2585, 'n_words': 550}