def create_app(): """ Creates the flask app, loading blueprints and the configuration. :return: flask app :rtype: Flask """ init_logging() app = Flask(__name__) app.register_blueprint(v1.section) app.register_blueprint(v2.section) app.register_blueprint(crane.section) app.register_error_handler(exceptions.HTTPError, app_util.http_error_handler) config.load(app) # in case the config says that debug mode is on, we need to adjust the # log level set_log_level(app) data.start_monitoring_data_dir(app) search.load_config(app) logging.getLogger(__name__).info('application initialized') return app
def test_demo_config(self): config.load(self.app) self.assertTrue(self.app.config.get('DEBUG') is True) configured_gsa_url = self.app.config.get(config.SECTION_GSA, {}).get(config.KEY_URL) self.assertEqual(configured_gsa_url, 'http://pulpproject.org/search')
def create_app(): """ Creates the flask app, loading blueprints and the configuration. :return: flask app :rtype: Flask """ init_logging() app = CraneFlask(__name__) app.register_blueprint(v1.section) app.register_blueprint(v2.section) app.register_blueprint(crane.section) app.register_error_handler(exceptions.HTTPError, app_util.http_error_handler) config.load(app) # in case the config says that debug mode is on, we need to adjust the # log level set_log_level(app) data.start_monitoring_data_dir(app) search.load_config(app) logging.getLogger(__name__).info('application initialized') return app
def test_demo_config(self, mock_get): config.load(self.app) self.assertTrue(self.app.config.get('DEBUG') is True) configured_gsa_url = self.app.config.get(config.SECTION_GSA, {}).get(config.KEY_URL) self.assertEqual(configured_gsa_url, 'http://pulpproject.org/search')
def test_defaults(self, mock_get): """ test that when no config options are specified, default values get used. """ config.load(self.app) self.assertTrue(self.app.config.get('DEBUG') is False) self.assertEqual(self.app.config.get(config.KEY_DATA_DIR), '/var/lib/crane/metadata/') self.assertEqual(self.app.config.get(config.KEY_ENDPOINT), '') self.assertEqual(self.app.config.get(config.KEY_DATA_POLLING_INTERVAL), 60) configured_gsa_url = self.app.config.get(config.SECTION_GSA, {}).get(config.KEY_URL) self.assertEqual(configured_gsa_url, '')
def test_defaults(self): """ test that when no config options are specified, default values get used. """ config.load(self.app) self.assertTrue(self.app.config.get('DEBUG') is False) self.assertEqual(self.app.config.get(config.KEY_DATA_DIR), '/var/lib/crane/metadata/') self.assertEqual(self.app.config.get(config.KEY_ENDPOINT), '') self.assertTrue(self.app.config.get(config.KEY_SC_ENABLE) is False) self.assertEqual(self.app.config.get(config.KEY_SC_CONTENT_DIR_V1), '/var/www/pub/docker/v1/web/') self.assertEqual(self.app.config.get(config.KEY_SC_CONTENT_DIR_V2), '/var/www/pub/docker/v2/web/') self.assertEqual(self.app.config.get(config.KEY_DATA_POLLING_INTERVAL), 60) configured_gsa_url = self.app.config.get(config.SECTION_GSA, {}).get(config.KEY_URL) self.assertEqual(configured_gsa_url, '') configured_solr_url = self.app.config.get(config.SECTION_SOLR, {}).get(config.KEY_URL) self.assertEqual(configured_solr_url, '')
def test_debug_env_variable_wrong_case(self): config.load(self.app) self.assertTrue(self.app.config.get('DEBUG') is True)
def test_debug_env_variable_false(self): config.load(self.app) self.assertTrue(self.app.config.get('DEBUG') is False)
def test_default_config_path_doesnt_exist(self): config.load(self.app)
def test_gsa_url(self): config.load(self.app) self.assertEqual(self.app.config.get(config.SECTION_GSA, {}).get(config.KEY_URL), 'http://foo/bar')
def test_debug_env_variable_true(self): config.load(self.app) self.assertTrue(self.app.config.get('DEBUG') is True)
def test_gsa_url(self): config.load(self.app) self.assertEqual( self.app.config.get(config.SECTION_GSA, {}).get(config.KEY_URL), 'http://foo/bar')
def test_serve_content_no_content_path(self, mock_error, mock_path): config.load(self.app) # make sure an error was logged and serve content is disabled self.assertEqual(mock_error.call_count, 1) self.assertTrue(self.app.config.get(config.KEY_SC_ENABLE) is False)
def test_serve_content(self, mock_error, mock_path): config.load(self.app) self.assertEqual(mock_error.call_count, 0) self.assertTrue(self.app.config.get(config.KEY_SC_ENABLE) is True)