コード例 #1
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_default_repr(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'default': uri}):

            assert repr(db.engine) == repr(db.engine['default'])
コード例 #2
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_repr(self):
        from alchemist import db

        config = {'default': 'sqlite:///:memory:'}
        with settings(self.app, DATABASES=config), self.app.app_context():
            text = '<Session(bind=%r)>' % db.engine['default']
            assert repr(db.session) == text
コード例 #3
0
    def test_missing(self):
        from alchemist import db, exceptions

        with settings(self.app):

            with raises(exceptions.ImproperlyConfigured):
                db.engine['default']
コード例 #4
0
    def test_default_repr(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'default': uri}):

            assert repr(db.engine) == repr(db.engine['default'])
コード例 #5
0
ファイル: test_app.py プロジェクト: concordusapps/alchemist
    def test_component(self):
        self.app = Flask('alchemist.tests.a')
        with settings(self.app, COMPONENTS=['alchemist.tests.a.b']):
            alchemist.configure(self.app)

            assert self.app.config.get('B_SETTING', 1)
            assert self.app.config.get('A_SETTING', 5)
コード例 #6
0
    def test_repr(self):
        from alchemist import db

        config = {'default': 'sqlite:///:memory:'}
        with settings(self.app, DATABASES=config), self.app.app_context():
            text = '<Session(bind=%r)>' % db.engine['default']
            assert repr(db.session) == text
コード例 #7
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_lookup(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'default': uri}):

            assert 'connect' in dir(db.engine)
コード例 #8
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_missing(self):
        from alchemist import db, exceptions

        with settings(self.app):

            with raises(exceptions.ImproperlyConfigured):
                db.engine['default']
コード例 #9
0
    def test_lookup(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'default': uri}):

            assert 'connect' in dir(db.engine)
コード例 #10
0
ファイル: test_app.py プロジェクト: shuyunqi/alchemist
    def test_component(self):
        self.app = Flask('alchemist.tests.a')
        with settings(self.app, COMPONENTS=['alchemist.tests.a.b']):
            alchemist.configure(self.app)

            assert self.app.config.get('B_SETTING', 1)
            assert self.app.config.get('A_SETTING', 5)
コード例 #11
0
    def test_default(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'default': uri}):

            assert db.engine.url.drivername == 'sqlite'
            assert db.engine.url.database == ':memory:'
コード例 #12
0
    def test_missing_database(self):
        from alchemist import db, exceptions

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'other': uri}):

            with raises(exceptions.ImproperlyConfigured):
                db.engine['default']
コード例 #13
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_missing_database(self):
        from alchemist import db, exceptions

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'other': uri}):

            with raises(exceptions.ImproperlyConfigured):
                db.engine['default']
コード例 #14
0
    def test_alternative(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'other': uri}):

            assert db.engine['other'].url.drivername == 'sqlite'
            assert db.engine['other'].url.database == ':memory:'
コード例 #15
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_alternative(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'other': uri}):

            assert db.engine['other'].url.drivername == 'sqlite'
            assert db.engine['other'].url.database == ':memory:'
コード例 #16
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_default(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'default': uri}):

            assert db.engine.url.drivername == 'sqlite'
            assert db.engine.url.database == ':memory:'
コード例 #17
0
ファイル: test_app.py プロジェクト: concordusapps/alchemist
    def test_missing_project(self):
        """
        Should succeed and not raise if the project does not contain
        a settings file.
        """

        self.app = Flask('alchemist')
        with settings(self.app):
            alchemist.configure(self.app)
コード例 #18
0
ファイル: test_app.py プロジェクト: shuyunqi/alchemist
    def test_missing_project(self):
        """
        Should succeed and not raise if the project does not contain
        a settings file.
        """

        self.app = Flask('alchemist')
        with settings(self.app):
            alchemist.configure(self.app)
コード例 #19
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_usage(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'default': uri}):

            with contextlib.closing(db.engine.connect()) as connection:

                result = connection.execute("BEGIN")
                assert isinstance(result, ResultProxy)
コード例 #20
0
    def test_usage(self):
        from alchemist import db

        uri = 'sqlite:///:memory:'
        with settings(self.app, DATABASES={'default': uri}):

            with contextlib.closing(db.engine.connect()) as connection:

                result = connection.execute("BEGIN")
                assert isinstance(result, ResultProxy)
コード例 #21
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_shell_sqlite3(self):
        from alchemist import db

        with settings(self.app, DATABASES={'default': 'sqlite:///:memory:'}):

            target = mock.MagicMock()
            with mock.patch('os.execvp', target):
                db.shell()

            target.assert_called_with('sqlite3', ['sqlite3', ':memory:'])
コード例 #22
0
    def test_shell_sqlite3(self):
        from alchemist import db

        with settings(self.app, DATABASES={'default': 'sqlite:///:memory:'}):

            target = mock.MagicMock()
            with mock.patch('os.execvp', target):
                db.shell()

            target.assert_called_with('sqlite3', ['sqlite3', ':memory:'])
コード例 #23
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_expanded(self):
        from alchemist import db

        config = {
            'engine': 'sqlite',
            'name': 'name',
        }

        with settings(self.app, DATABASES={'default': config}):

            assert db.engine.url.drivername == 'sqlite'
コード例 #24
0
    def test_expanded(self):
        from alchemist import db

        config = {
            'engine': 'sqlite',
            'name': 'name',
        }

        with settings(self.app, DATABASES={'default': config}):

            assert db.engine.url.drivername == 'sqlite'
コード例 #25
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_shell_mysql(self):
        from alchemist import db

        uri = 'mysql+oursql://user:pass@host:55/name'
        with settings(self.app, DATABASES={'default': uri}):

            target = mock.MagicMock()
            with mock.patch('os.execvp', target):
                db.shell()

            target.assert_called_with('mysql', [
                'mysql', '--user=user', '--password=pass',
                '--host=host', '--port=55', 'name'])
コード例 #26
0
ファイル: test_app.py プロジェクト: shuyunqi/alchemist
    def test_project_as_component(self):
        """
        Should not merge the project settings in twice even if
        it is listed in the COMPONENTS array.
        """

        self.app = Flask('alchemist.tests.a')
        components = ['alchemist.tests.a.b', 'alchemist.tests.a']
        with settings(self.app, COMPONENTS=components):
            alchemist.configure(self.app)

            assert self.app.config.get('B_SETTING', 1)
            assert self.app.config.get('A_SETTING', 5)
コード例 #27
0
ファイル: test_app.py プロジェクト: concordusapps/alchemist
    def test_project_as_component(self):
        """
        Should not merge the project settings in twice even if
        it is listed in the COMPONENTS array.
        """

        self.app = Flask('alchemist.tests.a')
        components = ['alchemist.tests.a.b', 'alchemist.tests.a']
        with settings(self.app, COMPONENTS=components):
            alchemist.configure(self.app)

            assert self.app.config.get('B_SETTING', 1)
            assert self.app.config.get('A_SETTING', 5)
コード例 #28
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_shell_mysql_socket(self):
        from alchemist import db

        uri = ('mysql+oursql://user:pass@localhost/name?'
               'unix_socket=/some/file/over/there.socket')
        with settings(self.app, DATABASES={'default': uri}):

            target = mock.MagicMock()
            with mock.patch('os.execvp', target):
                db.shell()

            target.assert_called_with('mysql', [
                'mysql', '--user=user', '--password=pass',
                '--socket=/some/file/over/there.socket', 'name'])
コード例 #29
0
    def test_shell_mysql(self):
        from alchemist import db

        uri = 'mysql+oursql://user:pass@host:55/name'
        with settings(self.app, DATABASES={'default': uri}):

            target = mock.MagicMock()
            with mock.patch('os.execvp', target):
                db.shell()

            target.assert_called_with('mysql', [
                'mysql', '--user=user', '--password=pass', '--host=host',
                '--port=55', 'name'
            ])
コード例 #30
0
    def test_shell_mysql_socket(self):
        from alchemist import db

        uri = ('mysql+oursql://user:pass@localhost/name?'
               'unix_socket=/some/file/over/there.socket')
        with settings(self.app, DATABASES={'default': uri}):

            target = mock.MagicMock()
            with mock.patch('os.execvp', target):
                db.shell()

            target.assert_called_with('mysql', [
                'mysql', '--user=user', '--password=pass',
                '--socket=/some/file/over/there.socket', 'name'
            ])
コード例 #31
0
ファイル: test_app.py プロジェクト: concordusapps/alchemist
    def test_project_env(self):
        """
        Should override settings from the file specified in the
        <project>_SETTINGS_MODULE environ variable.
        """

        filename = path.join(path.dirname(__file__), '../a/b/settings.py')
        os.environ['TESTS_A_SETTINGS_MODULE'] = filename

        self.app = Flask('alchemist.tests.a')
        with settings(self.app):
            alchemist.configure(self.app)

            assert self.app.config.get('B_SETTING', 1)
            assert self.app.config.get('A_SETTING', 5)

        del os.environ['TESTS_A_SETTINGS_MODULE']
コード例 #32
0
ファイル: test_app.py プロジェクト: shuyunqi/alchemist
    def test_project_env(self):
        """
        Should override settings from the file specified in the
        <project>_SETTINGS_MODULE environ variable.
        """

        filename = path.join(path.dirname(__file__), '../a/b/settings.py')
        os.environ['TESTS_A_SETTINGS_MODULE'] = filename

        self.app = Flask('alchemist.tests.a')
        with settings(self.app):
            alchemist.configure(self.app)

            assert self.app.config.get('B_SETTING', 1)
            assert self.app.config.get('A_SETTING', 5)

        del os.environ['TESTS_A_SETTINGS_MODULE']
コード例 #33
0
    def test_override(self):
        config = {
            'SERVER_HOST': 'app.me',
            'SERVER_PORT': 5000,
            'SERVER_RELOAD': False,
            'SERVER_PROCESSES': 10,
            'SERVER_THREADED': True,
            'SERVER_DEBUG': False
        }

        with test.settings(self.app, **config):
            target = self._run(['run'])
            target.assert_called_with(self.app,
                                      passthrough_errors=False,
                                      host=config['SERVER_HOST'],
                                      port=config['SERVER_PORT'],
                                      use_reloader=config['SERVER_RELOAD'],
                                      use_debugger=config['SERVER_DEBUG'],
                                      processes=config['SERVER_PROCESSES'],
                                      threaded=config['SERVER_THREADED'])
コード例 #34
0
    def test_override(self):
        config = {
            'SERVER_HOST': 'app.me',
            'SERVER_PORT': 5000,
            'SERVER_RELOAD': False,
            'SERVER_PROCESSES': 10,
            'SERVER_THREADED': True,
            'SERVER_DEBUG': False
        }

        with test.settings(self.app, **config):
            target = self._run(['run'])
            target.assert_called_with(
                self.app, passthrough_errors=False,
                host=config['SERVER_HOST'],
                port=config['SERVER_PORT'],
                use_reloader=config['SERVER_RELOAD'],
                use_debugger=config['SERVER_DEBUG'],
                processes=config['SERVER_PROCESSES'],
                threaded=config['SERVER_THREADED'])
コード例 #35
0
ファイル: test_app.py プロジェクト: concordusapps/alchemist
    def test_project(self):
        self.app = Flask('alchemist.tests.a')
        with settings(self.app):
            alchemist.configure(self.app)

            assert self.app.config.get('A_SETTING', 1)
コード例 #36
0
ファイル: test_app.py プロジェクト: shuyunqi/alchemist
    def test_project(self):
        self.app = Flask('alchemist.tests.a')
        with settings(self.app):
            alchemist.configure(self.app)

            assert self.app.config.get('A_SETTING', 1)
コード例 #37
0
ファイル: test_db.py プロジェクト: concordusapps/alchemist
    def test_acquire_default(self):
        from alchemist import db

        config = {'default': 'sqlite:///:memory:'}
        with settings(self.app, DATABASES=config), self.app.app_context():
            assert db.session
コード例 #38
0
    def test_acquire_default(self):
        from alchemist import db

        config = {'default': 'sqlite:///:memory:'}
        with settings(self.app, DATABASES=config), self.app.app_context():
            assert db.session