def test_app_with_log_config(self): log_conf = tempfile.NamedTemporaryFile(delete=False) log_conf.write('version: 1'.encode('utf-8')) log_conf.close() app = create_app(LOG_CONF_PATH=log_conf.name) self.assertIsNotNone(app) os.remove(log_conf.name)
def test_init_db(self): # must wait with import until setUp has been called from marvin.management import init_db app = create_app() with patch('marvin.management.app', app): init_db() self.assertTrue(os.path.exists('../nonexistent.db'))
def _pre_setup(self): super(TestCaseWithTempDB, self)._pre_setup() test_config = os.environ.get('MARVIN_TEST_CONFIG', path.abspath(path.join(path.dirname(__file__), 'test_config.py'))) os.environ['MARVIN_CONFIG_FILE'] = test_config self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.create_all()
def test_error_handler_500(self): log_conf = tempfile.NamedTemporaryFile(delete=False) log_conf.write('version: 1'.encode('utf-8')) log_conf.close() # test both API and blueprint error handlers for url, patchpoint in [('/', 'marvin.views.stats.stats_main'), ('/movies', 'marvin.views.movies.AllMoviesView.get')]: logger = MagicMock() # pylint: disable=multiple-statements with patch('marvin.utils._logger', logger), patch(patchpoint, lambda s: 1/0): app = create_app( TESTING=False, LOG_CONF_PATH=log_conf.name, ) response = app.test_client().get(url) self.assert_status(response, 500) self.assertEqual(len(logger.exception.mock_calls), 1) os.remove(log_conf.name)
def test_app_with_missing_log_config(self): # pylint: disable=no-self-use create_app()
def test_create_app_both(self): app = create_app(self.config_file.name, EXTRA_PARAM='baz') self.assertEqual(app.config['OTHER_CONFIG'], 'bar') self.assertEqual(app.config['EXTRA_PARAM'], 'baz')
def test_create_app_with_config_file(self): app = create_app(self.config_file.name) self.assertEqual(app.config['OTHER_CONFIG'], 'bar')
def test_create_app(self): app = create_app(MY_CONFIG_VALUE='foo') self.assertEqual(app.config['MY_CONFIG_VALUE'], 'foo')