Example #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'})
Example #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'})
Example #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()
Example #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])
Example #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])
Example #6
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])
Example #7
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])
Example #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
Example #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])
Example #10
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()
Example #11
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])
Example #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()
Example #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()
Example #14
0
 def setup_class(cls):
     '''setup - create clean execution context by resetting database '''
     LOG.info("######## setup_class: %r" % cls)
     SetupCommand('setup-app').run([config['__file__']])
     from linotp.lib.config import refreshConfig
     refreshConfig()
     return
Example #15
0
def setUpPackage():
    '''
    setUpPackage is called before each test package / class

    this hook is used to re-initialize the database
    '''
    SetupCommand('setup-app').run([config['__file__']])
    return
Example #16
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"})
Example #17
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'})
Example #18
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'})
Example #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 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()
Example #20
0
    def setup_class(cls):
        '''setup - create clean execution context by resetting database '''
        LOG.info("######## setup_class: %r" % cls)
        SetupCommand('setup-app').run([config['__file__']])
        from linotp.lib.config import refreshConfig
        refreshConfig()

        # provide the info of environment we are running in
        cls.env['pylons'] = LooseVersion(
            pkg_resources.get_distribution('pylons').version)
        TestController.run_state = 0
        return
Example #21
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()
Example #22
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()
Example #23
0
def setUpPackage():
    # Invoke websetup with the current config file
    SetupCommand('setup-app').run([config['__file__']])
    
    u1 = bluechips.model.User(u'root', u'Charlie Root', True)
    u1.email = u'*****@*****.**'
    u1.password = u'charliepass'
    u2 = bluechips.model.User(u'ben', u'Ben Bitdiddle', True)
    u3 = bluechips.model.User(u'gotta', u'Gotta Lisp', True)
    u4 = bluechips.model.User(u'rich', u'Rich Scheme', True)

    for u in (u1, u2, u3, u4):
        meta.Session.add(u)
    meta.Session.commit()
Example #24
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()
Example #25
0
from paste.deploy import appconfig
from projectname.config.environment import load_environment

here_dir = os.path.dirname(__file__)
conf_dir = os.path.dirname(os.path.dirname(here_dir))

test_file = os.path.join(conf_dir, 'test.ini')
conf = appconfig('config:' + test_file)
config = load_environment(conf.global_conf, conf.local_conf)

if SQLAtesting:
    engine = engine_from_config(config, 'sqlalchemy.')
    init_model(engine)

# Invoke websetup with the current config file
SetupCommand('setup-app').run([test_file])

environ = {}


class TestController(TestCase):
    def __init__(self, *args, **kwargs):
        wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
        config = wsgiapp.config
        pylons.app_globals._push_object(config['pylons.app_globals'])
        pylons.config._push_object(config)

        # Initialize a translator for tests that utilize i18n
        translator = _get_translator(pylons.config.get('lang'))
        pylons.translator._push_object(translator)
This module initializes the application via ``websetup`` (`paster
setup-app`) and provides the base testing objects.
"""
from unittest import TestCase

from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from pylons import url
from routes.util import URLGenerator
from webtest import TestApp

import pylons.test

__all__ = ['environ', 'url', 'TestController']

# Invoke websetup with the current config file
SetupCommand('setup-app').run(['test.ini'])

environ = {}


class TestController(TestCase):
    def __init__(self, *args, **kwargs):
        wsgiapp = pylons.test.pylonsapp
        config = wsgiapp.application.config
        self.config = config
        self.app = TestApp(wsgiapp)
        self.g = self.config['pylons.app_globals']
        url._push_object(URLGenerator(config['routes.map'], environ))
        TestCase.__init__(self, *args, **kwargs)
Example #27
0
This module initializes the application via ``websetup`` (`paster
setup-app`) and provides the base testing objects.
"""
from unittest import TestCase

from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from pylons import config, url
from routes.util import URLGenerator
from webtest import TestApp

import pylons.test

__all__ = ['environ', 'url', 'TestController']

# Invoke websetup with the current config file
SetupCommand('setup-app').run([config['__file__']])

environ = {}


class TestController(TestCase):
    def __init__(self, *args, **kwargs):
        if pylons.test.pylonsapp:
            wsgiapp = pylons.test.pylonsapp
        else:
            wsgiapp = loadapp('config:%s' % config['__file__'])
        self.app = TestApp(wsgiapp)
        url._push_object(URLGenerator(config['routes.map'], environ))
        TestCase.__init__(self, *args, **kwargs)
Example #28
0
"""
# Import pylons modules
from pylons import url
from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from routes.util import URLGenerator
# Import system modules
from unittest import TestCase
from webtest import TestApp
import simplejson
# Import custom modules
import pylons.test

__all__ = ['environ', 'url', 'TestController', 'adjust']
# Invoke websetup with the current config file
SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])
environ = {}


class TestController(TestCase):
    def __init__(self, *args, **kwargs):
        wsgiapp = pylons.test.pylonsapp
        config = wsgiapp.config
        self.app = TestApp(wsgiapp)
        url._push_object(URLGenerator(config['routes.map'], environ))
        TestCase.__init__(self, *args, **kwargs)

    def assertEqualJSON(self, response, isOk):
        'Assert response JSON'
        responseData = simplejson.loads(response.body)
        print responseData
Example #29
0
 def setup_class(cls):
     '''setup - create clean execution context by resetting database '''
     LOG.info("######## setup_class: %r" % cls)
     SetupCommand('setup-app').run([config['__file__']])
     return
Example #30
0
def setup_app():
    test_file = path.join(config.here, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])
Example #31
0
def setup_package():
    _setup_package()
    # Invoke websetup with the current config file
    SetupCommand('setup-app').run([config['__file__']])
Example #32
0
command.

This module initializes the application via ``websetup`` (`paster
setup-app`) and provides the base testing objects.
"""
from unittest import TestCase

from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from pylons import url
from routes.util import URLGenerator
from webtest import TestApp

import pylons.test

__all__ = ["environ", "url", "TestController"]

# Invoke websetup with the current config file
SetupCommand("setup-app").run([pylons.test.pylonsapp.config["__file__"]])

environ = {}


class TestController(TestCase):
    def __init__(self, *args, **kwargs):
        wsgiapp = pylons.test.pylonsapp
        config = wsgiapp.config
        self.app = TestApp(wsgiapp)
        url._push_object(URLGenerator(config["routes.map"], environ))
        TestCase.__init__(self, *args, **kwargs)