Example #1
0
 def _makeRequest(self):
     request = testing.DummyRequest()
     request.remote_addr = '127.0.0.1'
     request.user_agent = 'TestBrowser/1.0'
     request.referrer = 'http://www.example.com/foo'
     testing.setUp(request=request)
     return request
Example #2
0
 def setUp(self):
     self.config = testing.setUp()
     self.regis = Registry()
     self.regis.register_provider(trees)
     config = testing.setUp()
     config.add_route('home', 'foo')
     config.add_settings(settings)
Example #3
0
 def setup_method(self, _):
     testing.setUp(
         settings={
             "default_locale_name": "fr",
             "default_max_age": 1000,
         }
     )
Example #4
0
    def setUp(self):
        import tempfile
        import os.path
        self.tmpdir = tempfile.mkdtemp()
        dbpath = os.path.join( self.tmpdir, 'test.db')
        uri = 'file://' + dbpath
        settings = {'zodbconn.uri': uri,
                    'substanced.secret': 'sosecret',
                    'substanced.initial_login': '******',
                    'substanced.initial_password': '******',
                    'pyramid.includes': [
                        'substanced',
                        'pyramid_chameleon',
                        'pyramid_layout',
                        'pyramid_mailer.testing', # have to be after substanced to override the mailer
                        'pyramid_tm',
                        'dace',
                        'pontus',
        ]}

        app = main({}, **settings)
        self.db = app.registry._zodb_databases['']
        request = DummyRequest()
        testing.setUp(registry=app.registry, request=request)
        self.app = root_factory(request)
        request.root = self.app
        from webtest import TestApp
        self.testapp = TestApp(app)
        self.request = request
        import time; time.sleep(2)
Example #5
0
 def setUp(self):
     testing.setUp()
     self.config = testing.setUp()
     from webhook import main
     app = main.main({})
     from webtest import TestApp
     self.testapp = TestApp(app)
Example #6
0
 def setUp(self):
     from pyramid.paster import get_app
     from bookie.tests import BOOKIE_TEST_INI
     app = get_app(BOOKIE_TEST_INI, 'main')
     from webtest import TestApp
     self.testapp = TestApp(app)
     testing.setUp()
Example #7
0
 def setUp(self):
     testing.setUp()
     self.engine = create_engine('sqlite:///:memory:')
     self.session = sessionmaker(bind=self.engine)()
     Base.metadata.create_all(self.engine)
     self.request = testing.DummyRequest()
     self.request.db = self.session
Example #8
0
    def setUp(self):

        print ('TEST setup')
        self.config = testing.setUp()
        from sqlalchemy import create_engine

        engine = create_engine(settings['sqlalchemy.url'])
        from .Models import (
            Base, ObservationDynProp,
            ProtocoleType,
            ProtocoleType_ObservationDynProp,
            ObservationDynPropValue,
            Observation
            )

        self.engine = create_engine(settings['sqlalchemy.url'])
        self.config = testing.setUp()
        # self.engine = create_engine(settings['sqlalchemy.url'])
        self.connection = self.engine.connect()
        self.trans = self.connection.begin()

        DBSession.configure(bind=self.connection)
        self.DBSession = DBSession()

        Base.session = self.DBSession
Example #9
0
    def test_should_renew_session_on_invalidate(self):
        settings = {'pyramid.includes': '\n  pyramid_kvs.testing',
                    'kvs.session': """{"kvs": "mock",
                                       "key_name": "SessionId",
                                       "session_type": "cookie",
                                       "codec": "json",
                                       "key_prefix": "cookie::",
                                       "ttl": 20}"""}
        testing.setUp(settings=settings)
        factory = SessionFactory(settings)
        MockCache.cached_data = {
            b'cookie::chocolate': '{"stuffing": "chocolate"}'
        }
        request = testing.DummyRequest(cookies={'SessionId': 'chocolate'})
        session = factory(request)

        # Ensure session is initialized
        self.assertEqual(session['stuffing'], 'chocolate')
        # Invalidate session
        session.invalidate()
        # session is invalidated
        self.assertFalse('stuffing' in session)
        # ensure it can be reused immediately
        session['stuffing'] = 'macadamia'
        self.assertEqual(session['stuffing'], 'macadamia')
        testing.tearDown()
Example #10
0
 def test_cookie(self):
     settings = {'pyramid.includes': '\n  pyramid_kvs.testing',
                 'kvs.session': """{"kvs": "mock",
                                    "key_name": "SessionId",
                                    "session_type": "cookie",
                                    "codec": "json",
                                    "key_prefix": "cookie::",
                                    "ttl": 20}"""}
     testing.setUp(settings=settings)
     factory = SessionFactory(settings)
     MockCache.cached_data = {
         b'cookie::chocolate': '{"anotherkey": "another val"}'
     }
     self.assertEqual(factory.session_class, CookieSession)
     request = testing.DummyRequest(cookies={'SessionId': 'chocolate'})
     session = factory(request)
     client = session.client
     self.assertIsInstance(client, MockCache)
     self.assertEqual(client._serializer.dumps, serializer.json.dumps)
     self.assertEqual(client.ttl, 20)
     self.assertEqual(client.key_prefix, b'cookie::')
     self.assertEqual(session['anotherkey'], 'another val')
     self.assertEqual(request.response_callbacks,
                      deque([session.save_session]))
     testing.tearDown()
Example #11
0
 def setUp(self):
     from pyramid import testing
     from lasco.models import DBSession
     from lasco.models import initialize_sql
     testing.setUp()
     initialize_sql(TESTING_DB)
     self.session = DBSession
Example #12
0
def test_backup(dbsession, ini_settings):
    """Execute backup script with having our settings content."""

    f = NamedTemporaryFile(delete=False)
    temp_fname = f.name
    f.close()

    ini_settings["websauna.backup_script"] = "websauna.tests:backup_script.bash"
    ini_settings["backup_test.filename"] = temp_fname

    # We have some scoping issues with the dbsession here, make sure we close transaction at the end of the test
    with transaction.manager:

        init = get_init(dict(__file__=ini_settings["_ini_file"]), ini_settings)
        init.run()

        testing.setUp(registry=init.config.registry)

        # Check we have faux AWS variable to export
        secrets = get_secrets(get_current_registry())
        assert "aws.access_key_id" in secrets

        try:

            # This will run the bash script above
            backup_site()

            # The result should be generated here
            assert os.path.exists(temp_fname)
            contents = io.open(temp_fname).read()

            # test-secrets.ini, AWS access key
            assert contents.strip() == "foo"
        finally:
            testing.tearDown()
Example #13
0
    def test_user_view(self):
        """
        test the user_view view

        if a user with user_id from URL exists,

        """
        from c3sar.views.user import user_view
        request = testing.DummyRequest()
        request.matchdict['user_id'] = '1'
        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        instance = self._makeUser()
        self.dbsession.add(instance)
        # one more user
        instance2 = self._makeUser2()
        self.dbsession.add(instance2)
        self.dbsession.flush()

        result = user_view(request)

        # test: view returns a dict containing a user
        self.assertEquals(result['user'].username, instance.username)

        request = testing.DummyRequest()
        request.matchdict['user_id'] = '2'
        self.config = testing.setUp(request=request)
        result = user_view(request)
Example #14
0
    def test_user_edit_view_no_matchdict(self):
        """
        user edit view -- matchdict test & redirect

        if matchdict is invalid, expect redirect
        """
        from c3sar.views.user import user_edit
        request = testing.DummyRequest()
        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        instance = self._makeUser()
        self.dbsession.add(instance)
        self.dbsession.flush()
        result = user_edit(request)

        # test: a redirect is triggered iff no matchdict
        self.assertTrue(isinstance(result, HTTPFound), 'no redirect seen')
        self.assertTrue('not_found' in str(result.headers),
                        'not redirecting to not_found')

        # and one more with faulty matchdict
        request = testing.DummyRequest()
        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        request.matchdict['user_id'] = 'foo'
        result = user_edit(request)
        # test: a redirect is triggered iff matchdict faulty
        self.assertTrue(isinstance(result, HTTPFound), 'no redirect seen')
        self.assertTrue('not_found' in str(result.headers),
                        'not redirecting to not_found')
Example #15
0
    def setUp(self):
        EPUBMixInTestCase.setUp(self)
        testing.setUp(settings=self.settings)
        init_db(self.db_conn_str)

        # Assign API keys for testing
        self.set_up_api_keys()
Example #16
0
 def setUp(self):
     """Setup Tests"""
     from pyramid.paster import get_app
     app = get_app('test.ini', 'main')
     from webtest import TestApp
     self.testapp = TestApp(app)
     testing.setUp()
Example #17
0
 def _makeRequest(self, **kwargs):
     """:rtype: pyramid.request.Request"""
     from pyramid.registry import Registry
     registry = Registry()
     registry.settings = {'app.timezone': 'Asia/Bangkok'}
     testing.setUp(registry=registry)
     return testing.DummyRequest(**kwargs)
Example #18
0
 def test_thumbor_filter_without_security_key(self):
     testing.setUp(settings={
         'thumbor.security_key': None,
     })
     self.assertEqual(
         thumbor_filter({}, 'image', 25, 25), '')
     self.assertEqual(
         thumbor_filter({}, 'image', 25), '')
Example #19
0
def test_pyramid():
    from tests.pyramid_app import revision, config
    from pyramid import testing
    testing.setUp(config.registry)
    r = testing.DummyRequest()
    result = revision(r)
    assert result.status_code == 200
    testing.tearDown()
Example #20
0
    def setUp(self):
        # from katfud import main
        # app = main({}, **{'katfud.conf_file': 'conf.yml', 'katfud.non_pi': True})
        testing.setUp()

        import katfud.runtime as runtime

        self.test_runtime = runtime._Runtime(os.path.join(os.path.dirname(__file__), 'runtime_test.yml'))
Example #21
0
 def setUp(self):  # noqa
     from pyramid import testing
     testing.setUp(
         settings={
             "default_locale_name": "fr",
             "default_max_age": 1000,
         }
     )
Example #22
0
 def setUp(self):  # noqa
     from pyramid import testing
     testing.setUp(
         settings={
             'default_locale_name': 'fr',
             'default_max_age': 1000,
         }
     )
Example #23
0
 def setUp(self):
     """Setup Transaction"""
     testing.setUp()
     self.testapp.post("/login",
                       {"username":"******",
                        "password":"******",
                        "submit":""})
     self.session = meta.Session()
Example #24
0
 def setUp(self):
     self.config = testing.setUp()
     self.regis = Registry()
     self.regis.register_provider(trees)
     config = testing.setUp()
     config.add_route('home', 'foo')
     config.add_settings(settings)
     self.request = testing.DummyRequest()
     self.request.data_managers = {'skos_manager': None, 'conceptscheme_manager': None, 'audit_manager': None}
Example #25
0
 def setUp(self):
     settings = {
         'sqlalchemy.url': 'sqlite://',
         'domain': 'example.com',
     }
     app = main({}, **settings)
     self.app = TestApp(app)
     testing.setUp(settings=settings)
     initTestingDB()
Example #26
0
    def test_track_add_license_submit_cc_generic(self):
        """ track add license & submit: cc-by generic"""
        from c3sar.views.track import track_add_license
        # add a track
        track1 = self._makeTrack()
        self.dbsession.add(track1)
        self.dbsession.flush()

        request = testing.DummyRequest(
            post={'form.submitted': True,
                  u'cc_js_want_cc_license': u'sure',
                  u'cc_js_share': u'1',
                  u'cc_js_remix': u'',
                  u'cc_js_jurisdiction': u'generic',
                  u'cc_js_result_uri':
                      u'http://creativecommons.org/licenses/by/3.0/',
                  u'cc_js_result_img':
                      u'http://i.creativecommons.org/l/by/3.0/88x31.png',
                  u'cc_js_result_name':
                      u'Creative Commons Attribution 3.0 Unported',
                  })
        request.matchdict['track_id'] = 1
        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        result = track_add_license(request)

        if DEBUG:  # pragma: no cover
            pp.pprint(result)

        # check for redirect
        self.assertTrue(isinstance(result, HTTPFound), "no redirect")
        # redirect goes to track/view/1
        self.assertTrue('track/view/1' in result.headerlist[2][1],
                        "no redirect")

        from c3sar.models import Track
        the_track = Track.get_by_track_id(1)
        the_license = the_track.license[0]
        self.assertEquals(the_license.id, 1,
                          "wrong id: should be the only one in database")
        self.assertEquals(the_license.img,
                          u'http://i.creativecommons.org/l/by/3.0/88x31.png',
                          "wrong license img")
        self.assertEquals(the_license.uri,
                          u'http://creativecommons.org/licenses/by/3.0/',
                          "wrong license uri")
        self.assertEquals(
            the_license.name,
            u'Creative Commons Attribution 3.0 Unported',
            "wrong license name")

        # and now let's go to track/view/1
        from c3sar.views.track import track_view
        request = testing.DummyRequest()
        request.matchdict['track_id'] = 1
        self.config = testing.setUp(request=request)
        result = track_view(request)
Example #27
0
def setup_sqlalchemy():
        global DBTrans
        global _DBSession

        testing.setUp(settings=settings)

        engine = engine_from_config(settings, prefix='backend.sqla.')
        connection = engine.connect()
        DBTrans = connection.begin()
        _DBSession = sessionmaker(bind=connection)()
Example #28
0
    def setUp(self):
        from pyramid.paster import get_app
        app = get_app(BOOKIE_TEST_INI, 'main')
        from webtest import TestApp
        self.testapp = TestApp(app)
        testing.setUp()

        global API_KEY
        res = DBSession.execute("SELECT api_key FROM users WHERE username = '******'").fetchone()
        API_KEY = res['api_key']
Example #29
0
File: tests.py Project: lslaz1/karl
    def setUp(self):
        testing.setUp()

        class MockGSSError(Exception):
            pass

        patcher = mock.patch('karl.security.kerberos_auth.kerberos')
        self.kerberos = patcher.start()
        self.kerberos.GSSError = MockGSSError
        self.addCleanup(patcher.stop)
Example #30
0
def pyramid_request(request, init):
    """Get a gold of pyramid.testing.DummyRequest object."""
    from pyramid import testing

    testing.setUp(registry=init.config.registry)
    def teardown():
        testing.tearDown()

    request.addfinalizer(teardown)

    _request = testing.DummyRequest()
    return _request
Example #31
0
 def setUp(self):
     testing.setUp()
Example #32
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.registry.settings['push.solr_uri'] = 'foo'
     # Create an in-memory instance of the root
     self.root = Root()
     self.root.shared = SharedItems()
Example #33
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.include("mimosa")
Example #34
0
 def setUp(self):
     self.session = init_db()
     self.config = testing.setUp()
Example #35
0
 def setUp(self):
     from pyramid.paster import get_app
     app = get_app('test.ini', 'main')
     from webtest import TestApp
     self.testapp = TestApp(app)
     testing.setUp()
Example #36
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     DBSession.configure(bind=engine)
Example #37
0
 def setUp(self):
     self.config = testing.setUp()
     _initTestingDB()
Example #38
0
 def setUp(self):
     self.config = testing.setUp(autocommit=False)
     _ctx = self.config._ctx
     if _ctx is None:  # pragma: no cover ; will never be true under 1.2a5+
         self.config._ctx = self.config._make_context()
Example #39
0
 def setUp(self):
     registry = Dummy()
     self.config = testing.setUp(registry=registry)
Example #40
0
 def test_it_config(self):
     config = testing.setUp()
     try:
         config.include('pyramid_tm')
     finally:
         testing.tearDown()
Example #41
0
 def setUp(self):
     request = DummyRequest()
     self.config = setUp(request=request)
     self.config.include('pyramid_chameleon')
Example #42
0
 def setUp(self):
     super(TestContentViews, self).setUp()
     request = DummyRequest()
     self.config = testing.setUp(request=request)
     self.config.include('pyramid_chameleon')
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with uniittest_with_sqlite
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
Example #44
0
 def setUp(self):
     self.config = testing.setUp()
Example #45
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.include('arche.catalog')
Example #46
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.scan('voteit.core.models.invite_ticket')
     self.config.scan('voteit.core.views.components.email')
     self.config.include('pyramid_mailer.testing')
Example #47
0
 def setUp(self):
     super(TestFunctionalContentViews, self).setUp()
     request = DummyRequest()
     self.config = testing.setUp(request=request)
Example #48
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.include('pyramid_jinja2')
 def setUp(self):
     self.config = testing.setUp()
     self.config.include(
         'voteit.core.testing_helpers.register_security_policies')
     self.config.include('voteit.core.testing_helpers.register_workflows')
Example #50
0
 def setUp(self):
     self.config = testing.setUp()
     from . import includeme
     includeme(self.config)
Example #51
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.include('cornice')
     self.config.add_route('noservice', '/noservice')
     self.config.scan('tests.test_cors')
     self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
Example #52
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.registry.content = mock.Mock()
     from . import includeme
     includeme(self.config)
Example #53
0
 def setUp(self):
     self.config = testing.setUp()
     from zope.deprecation import __show__
     __show__.off()
Example #54
0
 def setUp(self):
     self.config = testing.setUp(autocommit=False)
     self.config.include('pyramid_tm')
Example #55
0
 def setUp(self):
     self.config = pyramid_testing.setUp(settings=self.settings)
Example #56
0
 def setUp(self):
     self.pm = ProseMaker()
     self.config = testing.setUp()
Example #57
0
 def _get_config(self):
     """Mock Pyramid config object.
     """
     config = testing.setUp()
     config.add_settings(self.settings)
     return config
Example #58
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.include('pyramid_chameleon')
Example #59
0
 def _callFUT(self, **kw):
     from pyramid.testing import setUp
     return setUp(**kw)
Example #60
0
 def setUp(self):
     self.session = _initTestingDB()
     self.config = testing.setUp()