Exemple #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'])
Exemple #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
Exemple #3
0
    def test_missing(self):
        from alchemist import db, exceptions

        with settings(self.app):

            with raises(exceptions.ImproperlyConfigured):
                db.engine['default']
Exemple #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'])
Exemple #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)
Exemple #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
Exemple #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)
Exemple #8
0
    def test_missing(self):
        from alchemist import db, exceptions

        with settings(self.app):

            with raises(exceptions.ImproperlyConfigured):
                db.engine['default']
Exemple #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)
Exemple #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)
Exemple #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:'
Exemple #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']
Exemple #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']
Exemple #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:'
Exemple #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:'
Exemple #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:'
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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:'])
Exemple #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:'])
Exemple #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'
Exemple #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'
Exemple #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'])
Exemple #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)
Exemple #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)
Exemple #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'])
Exemple #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'
            ])
Exemple #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'
            ])
Exemple #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']
Exemple #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']
Exemple #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'])
    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'])
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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