Esempio n. 1
0
def setup_basic_test(config=None, app_name=DFL_APP_NAME):
    '''
    Create clean environment for running tests, includes mongodb connection with "mim" (mongo-in-memory) and sample
    data created.

    A lightweight alternative is setup_config_test which doesn't bootstrap app data.
    '''
    try:
        conf_dir = tg.config.here
    except AttributeError:
        conf_dir = os.getcwd()
    test_file = os.path.join(conf_dir, get_config_file(config))
    """
    # setup our app, from TG quickstart example:
    from tg.util import Bunch
    from gearbox.commands.setup_app import SetupAppCommand
    cmd = SetupAppCommand(Bunch(options=Bunch(verbose_level=1)), Bunch())
    cmd.run(Bunch(config_file='config:{}'.format(test_file), section_name=None))
    """
    # setup our app without depending on gearbox (we still depend on Paste anyway)
    # uses [paste.app_install] entry point which call our setup_app()
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    ew.TemplateEngine.initialize({})

    # remove unnecessary bootstrap tasks, e.g. search indexing
    M.MonQTask.query.remove({'state': 'ready'})
Esempio n. 2
0
def setup_basic_test(config=None, app_name=DFL_APP_NAME):
    '''
    Create clean environment for running tests, includes mongodb connection with "mim" (mongo-in-memory) and sample
    data created.

    A lightweight alternative is setup_config_test which doesn't bootstrap app data.
    '''
    try:
        conf_dir = tg.config.here
    except AttributeError:
        conf_dir = os.getcwd()
    test_file = os.path.join(conf_dir, get_config_file(config))
    """
    # setup our app, from TG quickstart example:
    from tg.util import Bunch
    from gearbox.commands.setup_app import SetupAppCommand
    cmd = SetupAppCommand(Bunch(options=Bunch(verbose_level=1)), Bunch())
    cmd.run(Bunch(config_file='config:{}'.format(test_file), section_name=None))
    """
    # setup our app without depending on gearbox (we still depend on Paste anyway)
    # uses [paste.app_install] entry point which call our setup_app()
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    ew.TemplateEngine.initialize({})

    # remove unnecessary bootstrap tasks, e.g. search indexing
    M.MonQTask.query.remove({'state': 'ready'})
Esempio n. 3
0
def setUpModule():
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#main_without_authn',
                      relative_to=conf_dir)
    global app
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # Prepare authz test data
    subm_100 = model.Submission(id=100, filename=u'subm_100', source=u'subm_100',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc1').one(),
        language=model.Language.query.first())
    subm_101 = model.Submission(id=101, filename=u'subm_101', source=u'subm_101',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc2').one(),
        language=model.Language.query.first())
    subm_102 = model.Submission(id=102, filename=u'subm_102', source=u'subm_102',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studente1').one(),
        language=model.Language.query.first())
    model.DBSession.add_all((subm_100, subm_101, subm_102))
    transaction.commit()
Esempio n. 4
0
    def setUp(self):
        wsgiapp = loadapp('config:test.ini#%s' % self.application_under_test,
                          relative_to='.')
        self.app = TestApp(wsgiapp)

        # Setting it up:
        test_file = os.path.abspath('test.ini')
        cmd = SetupCommand('setup-app')
        cmd.run([test_file])
Esempio n. 5
0
    def setUp(self):
        wsgiapp = loadapp('config:test.ini#%s' % self.application_under_test,
                          relative_to='.')
        self.app = TestApp(wsgiapp)

        # Setting it up:
        test_file = os.path.abspath('test.ini')
        cmd = SetupCommand('setup-app')
        cmd.run([test_file])
Esempio n. 6
0
 def setUp(self):
     """Method called by nose before running each test"""
     # Loading the application:
     conf_dir = config.here
     wsgiapp = loadapp("config:test.ini#%s" % self.application_under_test, relative_to=conf_dir)
     self.app = TestApp(wsgiapp)
     # Setting it up:
     test_file = path.join(conf_dir, "test.ini")
     cmd = SetupCommand("setup-app")
     cmd.run([test_file])
Esempio n. 7
0
 def setUp(self):
     # Loading the application:
     conf_dir = config.here
     wsgiapp = loadapp('config:test.ini#%s' % self.application_under_test,
                       relative_to=conf_dir)
     self.app = TestApp(wsgiapp)
     # Setting it up:
     test_file = path.join(conf_dir, 'test.ini')
     cmd = SetupCommand('setup-app')
     cmd.run([test_file])
Esempio n. 8
0
def setup_app(application): 
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#%s' % application,
                      relative_to=conf_dir)
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])
    return app
Esempio n. 9
0
def setUpModule():
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#main_without_authn',
                      relative_to=conf_dir)
    global app
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])
Esempio n. 10
0
 def setUp(self):
     """Method called by nose before running each test"""
     # Loading the application:
     conf_dir = config.here
     wsgiapp = loadapp(
         "config:test.ini#%s" % self.application_under_test, relative_to=conf_dir
     )
     self.app = TestApp(wsgiapp)
     # Setting it up:
     test_file = path.join(conf_dir, "test.ini")
     cmd = SetupCommand("setup-app")
     cmd.run([test_file])
Esempio n. 11
0
def setUpModule():
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#main_without_authn',
                      relative_to=conf_dir)
    global app
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # Prepare authz test data
    subm_100 = model.Submission(
        id=100,
        filename=u'subm_100',
        source=u'subm_100',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc1').one(),
        language=model.Language.query.first(),
        judgement=model.Judgement(
            tutor=model.User.query.filter_by(user_name='tutor1').one(),
            corrected_source=u'subm-100',
            comment=u'Good good',
            annotations={1: 'No no no'},
            grade=3.14))
    model.DBSession.add(subm_100)
    subm_101 = model.Submission(
        id=101,
        filename=u'subm_101',
        source=u'subm_101',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc2').one(),
        language=model.Language.query.first())
    model.DBSession.add(subm_101)
    subm_102 = model.Submission(
        id=102,
        filename=u'subm_102',
        source=u'subm_102',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studente1').one(),
        language=model.Language.query.first())
    model.DBSession.add(subm_102)
    subm_103 = model.Submission(
        id=103,
        filename=u'subm_103',
        source=u'subm_103',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studente1').one(),
        language=model.Language.query.first(),
        public=True)
    model.DBSession.add(subm_103)
    transaction.commit()
Esempio n. 12
0
def setup_basic_test(config=None, app_name=DFL_APP_NAME):
    '''Create clean environment for running tests'''
    try:
        conf_dir = tg.config.here
    except AttributeError:
        conf_dir = os.getcwd()
    ew.TemplateEngine.initialize({})
    test_file = os.path.join(conf_dir, get_config_file(config))
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # run all tasks, e.g. indexing from bootstrap operations
    while M.MonQTask.run_ready('setup'):
        ThreadLocalORMSession.flush_all()
Esempio n. 13
0
def setup_basic_test(config=None, app_name=DFL_APP_NAME):
    '''Create clean environment for running tests'''
    try:
        conf_dir = tg.config.here
    except AttributeError:
        conf_dir = os.getcwd()
    ew.TemplateEngine.initialize({})
    test_file = os.path.join(conf_dir, get_config_file(config))
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # run all tasks, e.g. indexing from bootstrap operations
    while M.MonQTask.run_ready('setup'):
        ThreadLocalORMSession.flush_all()
Esempio n. 14
0
def setup_basic_test(config=None, app_name=DFL_APP_NAME):
    '''
    Create clean environment for running tests.

    A lightweight alternative is setup_config_test which doesn't bootstrap app data.
    '''
    try:
        conf_dir = tg.config.here
    except AttributeError:
        conf_dir = os.getcwd()
    test_file = os.path.join(conf_dir, get_config_file(config))
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])
    ew.TemplateEngine.initialize({})

    # remove unnecessary bootstrap tasks, e.g. search indexing
    M.MonQTask.query.remove({'state': 'ready'})
Esempio n. 15
0
def setup_basic_test(config=None, app_name=DFL_APP_NAME):
    """
    Create clean environment for running tests.

    A lightweight alternative is setup_config_test which doesn't bootstrap app data.
    """
    try:
        conf_dir = tg.config.here
    except AttributeError:
        conf_dir = os.getcwd()
    test_file = os.path.join(conf_dir, get_config_file(config))
    cmd = SetupCommand("setup-app")
    cmd.run([test_file])
    ew.TemplateEngine.initialize({})

    # remove unnecessary bootstrap tasks, e.g. search indexing
    M.MonQTask.query.remove({"state": "ready"})
Esempio n. 16
0
def setup_basic_test(config=None, app_name=DFL_APP_NAME):
    '''
    Create clean environment for running tests, includes mongodb connection with "mim" (mongo-in-memory) and sample
    data created.

    A lightweight alternative is setup_config_test which doesn't bootstrap app data.
    '''
    try:
        conf_dir = tg.config.here
    except AttributeError:
        conf_dir = os.getcwd()
    test_file = os.path.join(conf_dir, get_config_file(config))
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])
    ew.TemplateEngine.initialize({})

    # remove unnecessary bootstrap tasks, e.g. search indexing
    M.MonQTask.query.remove({'state': 'ready'})
Esempio n. 17
0
def setUpModule():
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#main_without_authn',
                      relative_to=conf_dir)
    global app
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # Prepare nullable=True test data
    u = model.User(id=0,
                   user_name='empty',
                   email_address='empty',
                   display_name=None,
                   created=None)
    e = model.Course(id=0,
                     name='Empty',
                     _url='empty',
                     description=None,
                     enabled=True)
    s = model.Sheet(id=0,
                    name='Empty',
                    sheet_id='0',
                    event=e,
                    description=None)
    a = model.Assignment(id=0,
                         name='Empty',
                         assignment_id='0',
                         sheet=s,
                         description=None,
                         timeout=None)
    ss = model.Submission(id=0,
                          user=u,
                          assignment=a,
                          filename=None,
                          source=None,
                          language=None)
    j = model.Judgement(id=0, submission=ss, tutor=u)
    model.DBSession.add_all((u, e, a, s, ss, j))
    transaction.commit()
Esempio n. 18
0
def setUpModule():
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#main_without_authn',
                      relative_to=conf_dir)
    global app
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # Prepare nullable=True test data
    u = model.User(id=0, user_name='empty', email_address='empty', display_name=None, created=None)
    e = model.Course(id=0, name='Empty', _url='empty', description=None, enabled=True)
    s = model.Sheet(id=0, name='Empty', sheet_id='0', event=e, description=None)
    a = model.Assignment(id=0, name='Empty', assignment_id='0', sheet=s, description=None, timeout=None)
    ss = model.Submission(id=0, user=u, assignment=a, filename=None, source=None, language=None)
    j = model.Judgement(id=0, submission=ss, tutor=u)
    model.DBSession.add_all((u, e, a, s, ss, j))
    transaction.commit()
Esempio n. 19
0
def setUpModule():
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#main_without_authn',
                      relative_to=conf_dir)
    global app
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # Prepare authz test data
    subm_100 = model.Submission(id=100, filename=u'subm_100', source=u'subm_100',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc1').one(),
        language=model.Language.query.first(),
        judgement=model.Judgement(
            tutor=model.User.query.filter_by(user_name='tutor1').one(),
            corrected_source=u'subm-100', comment=u'Good good',
            annotations={1: 'No no no'}, grade=3.14))
    model.DBSession.add(subm_100)
    subm_101 = model.Submission(id=101, filename=u'subm_101', source=u'subm_101',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc2').one(),
        language=model.Language.query.first())
    model.DBSession.add(subm_101)
    subm_102 = model.Submission(id=102, filename=u'subm_102', source=u'subm_102',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studente1').one(),
        language=model.Language.query.first())
    model.DBSession.add(subm_102)
    subm_103 = model.Submission(id=103, filename=u'subm_103', source=u'subm_103',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studente1').one(),
        language=model.Language.query.first(),
        public=True)
    model.DBSession.add(subm_103)
    transaction.commit()
Esempio n. 20
0
def setUpModule():
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#main_without_authn',
                      relative_to=conf_dir)
    global app
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # Prepare authz test data
    subm_100 = model.Submission(
        id=100,
        filename=u'subm_100',
        source=u'subm_100',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc1').one(),
        language=model.Language.query.first())
    subm_101 = model.Submission(
        id=101,
        filename=u'subm_101',
        source=u'subm_101',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc2').one(),
        language=model.Language.query.first())
    subm_102 = model.Submission(
        id=102,
        filename=u'subm_102',
        source=u'subm_102',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studente1').one(),
        language=model.Language.query.first())
    model.DBSession.add_all((subm_100, subm_101, subm_102))
    transaction.commit()
Esempio n. 21
0
def setup_app():
    test_file = path.join(config.here, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])