Пример #1
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'])
Пример #2
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
Пример #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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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
    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