def test_db_config(self): """Assert creating the application configures the scoped session.""" # Assert the scoped session is not bound. self.assertRaises(UnboundExecutionError, Session.get_bind) Session.remove() app.create({'DB_URL': 'sqlite://'}) self.assertEqual('sqlite://', str(Session().get_bind().url))
def test_db_config(self): """Assert creating the application configures the scoped session.""" # Assert the scoped session is not bound. self.assertRaises(UnboundExecutionError, Session.get_bind) Session.remove() app.create( {"DB_URL": "sqlite://", "SOCIAL_AUTH_USER_MODEL": "anitya.db.models.User"} ) self.assertEqual("sqlite://", str(Session().get_bind().url))
def test_db_config(self): """Assert creating the application configures the scoped session.""" # Assert the scoped session is not bound. self.assertRaises(UnboundExecutionError, Session.get_bind) Session.remove() app.create({ 'DB_URL': 'sqlite://', 'SOCIAL_AUTH_USER_MODEL': 'anitya.db.models.User', }) self.assertEqual('sqlite://', str(Session().get_bind().url))
def test_email_config(self): """Assert a SMTPHandler is added to the anitya logger when ``EMAIL_ERRORS=True``.""" config = { "DB_URL": "sqlite://", "SOCIAL_AUTH_USER_MODEL": "anitya.db.models.User", "EMAIL_ERRORS": True, "SMTP_SERVER": "smtp.example.com", "ADMIN_EMAIL": "*****@*****.**", } anitya_logger = logging.getLogger("anitya") anitya_logger.handlers = [] app.create(config) self.assertEqual(1, len(anitya_logger.handlers)) self.assertEqual("smtp.example.com", anitya_logger.handlers[0].mailhost) self.assertEqual(["*****@*****.**"], anitya_logger.handlers[0].toaddrs)
def test_email_config(self): """Assert a SMTPHandler is added to the anitya logger when ``EMAIL_ERRORS=True``.""" config = { 'DB_URL': 'sqlite://', 'EMAIL_ERRORS': True, 'SMTP_SERVER': 'smtp.example.com', 'ADMIN_EMAIL': '*****@*****.**', } anitya_logger = logging.getLogger('anitya') anitya_logger.handlers = [] app.create(config) self.assertEqual(1, len(anitya_logger.handlers)) self.assertEqual('smtp.example.com', anitya_logger.handlers[0].mailhost) self.assertEqual(['*****@*****.**'], anitya_logger.handlers[0].toaddrs)
def setUp(self): """Set a basic test environment. This simply starts recording a VCR on start-up and stops on tearDown. """ self.config = config.config.copy() self.config['TESTING'] = True self.flask_app = app.create(self.config) cwd = os.path.dirname(os.path.realpath(__file__)) my_vcr = vcr.VCR(cassette_library_dir=os.path.join( cwd, 'request-data/'), record_mode='once') self.vcr = my_vcr.use_cassette(self.id()) self.vcr.__enter__() self.addCleanup(self.vcr.__exit__, None, None, None)
def setUp(self): """Set a basic test environment. This simply starts recording a VCR on start-up and stops on tearDown. """ self.config = config.config.copy() self.config["TESTING"] = True self.flask_app = app.create(self.config) cwd = os.path.dirname(os.path.realpath(__file__)) my_vcr = vcr.VCR( cassette_library_dir=os.path.join(cwd, "request-data/"), record_mode="once" ) self.vcr = my_vcr.use_cassette(self.id()) self.vcr.__enter__() self.addCleanup(self.vcr.__exit__, None, None, None)
def setUp(self): """Set a basic test environment. This simply starts recording a VCR on start-up and stops on tearDown. """ self.config = config.config.copy() self.config["TESTING"] = True self.flask_app = app.create(self.config) cwd = os.path.dirname(os.path.realpath(__file__)) my_vcr = vcr.VCR( cassette_library_dir=os.path.join(cwd, "request-data/"), record_mode="once", decode_compressed_response=True, ) self.vcr = my_vcr.use_cassette( self.id(), filter_headers=[("Authorization", "bearer foobar")] ) self.vcr.__enter__() self.addCleanup(self.vcr.__exit__, None, None, None)
def setUp(self): """Set a basic test environment. This simply starts recording a VCR on start-up and stops on tearDown. """ mock_oidc = mock.patch( 'anitya.authentication.oidc', OpenIDConnect(credentials_store=flask.session), ) mock_oidc.start() self.addCleanup(mock_oidc.stop) mock_oid = mock.patch('anitya.authentication.oid', OpenID()) mock_oid.start() self.addCleanup(mock_oid.stop) self.flask_app = app.create(config.config) cwd = os.path.dirname(os.path.realpath(__file__)) my_vcr = vcr.VCR( cassette_library_dir=os.path.join(cwd, 'request-data/'), record_mode='once') self.vcr = my_vcr.use_cassette(self.id()) self.vcr.__enter__() self.addCleanup(self.vcr.__exit__, None, None, None)
def test_default_config(self): """Assert when no configuration is provided, :data:`anitya.config.config` is used.""" application = app.create() for key in anitya_config: self.assertEqual(anitya_config[key], application.config[key])
#!/usr/bin/env python # -*- coding: utf-8 -*- """ An instance of the Flask application. This is intended to be run with the Flask CLI for development purposes only:: $ export ANITYA_WEB_CONFIG=<config_file> $ export FLASK_DEBUG=1 $ export FLASK_APP=<this_file> $ flask run --host 0.0.0.0 --port 5000 """ from anitya.app import create app = create()
#!/usr/bin/python from anitya import app as application app = application.create()