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

        with settings(self.app):

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

        with settings(self.app):

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