def test_update_sentry_logging_ignore_sentry(self): logging_dict = default_logging_dict('rororo', 'tests') logging_dict['loggers']['rororo']['ignore_sentry'] = True update_sentry_logging(logging_dict, TEST_SENTRY_DSN) self.assertNotIn('sentry', logging_dict['loggers']['rororo']['handlers']) self.assertIn('sentry', logging_dict['loggers']['tests']['handlers'])
def test_update_sentry_logging_empty_dsn(self): empty = choice((False, None, "")) logging_dict = default_logging_dict("rororo") update_sentry_logging(logging_dict, empty, "rororo") self.assertNotIn("sentry", logging_dict["handlers"]) self.assertNotIn("sentry", logging_dict["loggers"]["rororo"]["handlers"])
def test_update_sentry_logging_empty_dsn(): empty = choice((False, None, "")) logging_dict = default_logging_dict("rororo") update_sentry_logging(logging_dict, empty, "rororo") assert "sentry" not in logging_dict["handlers"] assert "sentry" not in logging_dict["loggers"]["rororo"]["handlers"]
def create_app(argv: List[str] = None) -> web.Application: """Create aiohttp applicaiton for OpenAPI 3 Schema. The ``petstore-expanded.yaml`` schema taken from OpenAPI 3 Specification examples directory and used inside the app without modifications besides changing default server URL to use. As pets storage is a simple list, it will be cleared on each application shutdown. This aiohttp application is ready to be run as: .. code-block:: bash python -m aiohttp.web petstore.app:create_app After application is running, feel free to use Swagger UI to check the results. The OpenAPI schema will be available at: http://localhost:8080/api/openapi.yaml To ensure that Swagger UI been able to make requests to the PetStore example app CORS headers allowed for all requests. **Please, avoid enabling CORS headers for all requests at production.** """ # Setup logging setup_logging( default_logging_dict("aiohttp", "aiohttp_middlewares", "petstore", "rororo"), remove_root_handlers=True, ) # Create new aiohttp application with CORS & error middlewares app = web.Application(middlewares=( # CORS middleware should be the first one as it ensures that every # aiohttp response use proper CORS headers cors_middleware(allow_all=True), # It's good practice to enable error middleware right after the # CORS one to catch as many errors as possible error_middleware(default_handler=views.error), )) # Create the "storage" for the pets app["pets"] = [] # Setup OpenAPI schema support for aiohttp application setup_openapi( # Where first param is an application instance app, # Second is path to OpenAPI 3 Schema Path(__file__).parent / "petstore-expanded.yaml", # And after list of operations views.operations, # Need to add route prefix if server URL in OpenAPI schema ended with # a path, like "http://localhost:8080/api" route_prefix="/api", ) return app
def test_update_sentry_logging_empty_dsn(self): empty = choice((False, None, '')) logging_dict = default_logging_dict('rororo') update_sentry_logging(logging_dict, empty, 'rororo') self.assertNotIn('sentry', logging_dict['handlers']) self.assertNotIn('sentry', logging_dict['loggers']['rororo']['handlers'])
def test_default_logging_dict(self): logging_dict = default_logging_dict("rororo") self.assertEqual(logging_dict["filters"]["ignore_errors"]["()"], IgnoreErrorsFilter) self.assertEqual(len(logging_dict["formatters"]), 2) self.assertIn("default", logging_dict["formatters"]) self.assertIn("naked", logging_dict["formatters"]) self.assertEqual(len(logging_dict["handlers"]), 2) self.assertIn("stdout", logging_dict["handlers"]) self.assertEqual(logging_dict["handlers"]["stdout"]["level"], "DEBUG") self.assertIn("stderr", logging_dict["handlers"]) self.assertEqual(logging_dict["handlers"]["stderr"]["level"], "WARNING") self.assertEqual(len(logging_dict["loggers"]), 1) self.assertIn("rororo", logging_dict["loggers"]) self.assertEqual(logging_dict["loggers"]["rororo"]["handlers"], ["stdout", "stderr"]) self.assertEqual(logging_dict["loggers"]["rororo"]["level"], "INFO")
def test_default_logging_dict(): logging_dict = default_logging_dict("rororo") assert logging_dict["filters"]["ignore_errors"]["()"] == IgnoreErrorsFilter assert len(logging_dict["formatters"]) == 2 assert "default" in logging_dict["formatters"] assert "naked" in logging_dict["formatters"] assert len(logging_dict["handlers"]) == 2 assert "stdout" in logging_dict["handlers"] assert logging_dict["handlers"]["stdout"]["level"] == "DEBUG" assert "stderr" in logging_dict["handlers"] assert logging_dict["handlers"]["stderr"]["level"] == "WARNING" assert len(logging_dict["loggers"]) == 1 assert "rororo" in logging_dict["loggers"] assert logging_dict["loggers"]["rororo"]["handlers"] == [ "stdout", "stderr", ] assert logging_dict["loggers"]["rororo"]["level"] == "INFO"
def test_default_logging_dict(self): logging_dict = default_logging_dict('rororo') self.assertEqual(logging_dict['filters']['ignore_errors']['()'], IgnoreErrorsFilter) self.assertEqual(len(logging_dict['formatters']), 2) self.assertIn('default', logging_dict['formatters']) self.assertIn('naked', logging_dict['formatters']) self.assertEqual(len(logging_dict['handlers']), 2) self.assertIn('stdout', logging_dict['handlers']) self.assertEqual(logging_dict['handlers']['stdout']['level'], 'DEBUG') self.assertIn('stderr', logging_dict['handlers']) self.assertEqual(logging_dict['handlers']['stderr']['level'], 'WARNING') self.assertEqual(len(logging_dict['loggers']), 1) self.assertIn('rororo', logging_dict['loggers']) self.assertEqual(logging_dict['loggers']['rororo']['handlers'], ['stdout', 'stderr']) self.assertEqual(logging_dict['loggers']['rororo']['level'], 'INFO')
def test_update_sentry_logging_empty_loggers(self): logging_dict = default_logging_dict("rororo", "tests") update_sentry_logging(logging_dict, TEST_SENTRY_DSN) self.assertIn("sentry", logging_dict["loggers"]["rororo"]["handlers"]) self.assertIn("sentry", logging_dict["loggers"]["tests"]["handlers"])
def test_update_sentry_logging_kwargs(self): logging_dict = default_logging_dict('rororo') update_sentry_logging(logging_dict, TEST_SENTRY_DSN, key='value') self.assertEqual(logging_dict['handlers']['sentry']['key'], 'value')
def test_update_sentry_logging_empty_loggers(self): logging_dict = default_logging_dict('rororo', 'tests') update_sentry_logging(logging_dict, TEST_SENTRY_DSN) self.assertIn('sentry', logging_dict['loggers']['rororo']['handlers']) self.assertIn('sentry', logging_dict['loggers']['tests']['handlers'])
def test_default_logging_dict_multiple_loggers(self): logging_dict = default_logging_dict('rororo', 'tests') self.assertEqual(len(logging_dict['loggers']), 2) self.assertIn('rororo', logging_dict['loggers']) self.assertIn('tests', logging_dict['loggers'])
def test_setup_logging_remove_root_handlers(remove, expected): logging.basicConfig(level="INFO") assert len(logging.root.handlers) == 1 setup_logging(default_logging_dict("rororo"), remove_root_handlers=remove) assert len(logging.root.handlers) == expected
def test_update_sentry_logging_missed_logger(self): logging_dict = default_logging_dict("rororo") update_sentry_logging(logging_dict, TEST_SENTRY_DSN, "rororo", "does-not-exist")
def test_update_sentry_logging_ignore_sentry(): logging_dict = default_logging_dict("rororo", "tests") logging_dict["loggers"]["rororo"]["ignore_sentry"] = True update_sentry_logging(logging_dict, TEST_SENTRY_DSN) assert "sentry" not in logging_dict["loggers"]["rororo"]["handlers"] assert "sentry" in logging_dict["loggers"]["tests"]["handlers"]
def test_default_logging_dict_keyword_arguments(self): logging_dict = default_logging_dict('rororo', level='DEBUG') self.assertEqual(logging_dict['loggers']['rororo']['level'], 'DEBUG')
def test_update_sentry_logging_overwrite_level(self): logging_dict = default_logging_dict('rororo') update_sentry_logging(logging_dict, TEST_SENTRY_DSN, level='INFO') self.assertEqual(logging_dict['handlers']['sentry']['level'], 'INFO')
def test_update_sentry_logging_missed_logger(self): logging_dict = default_logging_dict('rororo') update_sentry_logging(logging_dict, TEST_SENTRY_DSN, 'rororo', 'does-not-exist')
def test_update_sentry_logging_ignore_sentry(self): logging_dict = default_logging_dict("rororo", "tests") logging_dict["loggers"]["rororo"]["ignore_sentry"] = True update_sentry_logging(logging_dict, TEST_SENTRY_DSN) self.assertNotIn("sentry", logging_dict["loggers"]["rororo"]["handlers"]) self.assertIn("sentry", logging_dict["loggers"]["tests"]["handlers"])
def test_update_sentry_logging_kwargs(self): logging_dict = default_logging_dict("rororo") update_sentry_logging(logging_dict, TEST_SENTRY_DSN, key="value") self.assertEqual(logging_dict["handlers"]["sentry"]["key"], "value")
def test_update_sentry_logging_overwrite_level(): logging_dict = default_logging_dict("rororo") update_sentry_logging(logging_dict, TEST_SENTRY_DSN, level="INFO") assert logging_dict["handlers"]["sentry"]["level"] == "INFO"
def test_setup_logging(): setup_logging(default_logging_dict("rororo"))
def test_default_logging_dict_keyword_arguments(): logging_dict = default_logging_dict("rororo", level="DEBUG") assert logging_dict["loggers"]["rororo"]["level"] == "DEBUG"
def test_default_logging_dict_keyword_arguments(self): logging_dict = default_logging_dict("rororo", level="DEBUG") self.assertEqual(logging_dict["loggers"]["rororo"]["level"], "DEBUG")
def test_default_logging_dict_multiple_loggers(self): logging_dict = default_logging_dict("rororo", "tests") self.assertEqual(len(logging_dict["loggers"]), 2) self.assertIn("rororo", logging_dict["loggers"]) self.assertIn("tests", logging_dict["loggers"])
def test_default_logging_dict_multiple_loggers(): logging_dict = default_logging_dict("rororo", "tests") assert len(logging_dict["loggers"]) == 2 assert "rororo" in logging_dict["loggers"] assert "tests" in logging_dict["loggers"]
def test_update_sentry_logging_empty_loggers(): logging_dict = default_logging_dict("rororo", "tests") update_sentry_logging(logging_dict, TEST_SENTRY_DSN) assert "sentry" in logging_dict["loggers"]["rororo"]["handlers"] assert "sentry" in logging_dict["loggers"]["tests"]["handlers"]
def test_update_sentry_logging_missed_logger(): logging_dict = default_logging_dict("rororo") update_sentry_logging(logging_dict, TEST_SENTRY_DSN, "rororo", "does-not-exist")
def test_update_sentry_logging_kwargs(): logging_dict = default_logging_dict("rororo") update_sentry_logging(logging_dict, TEST_SENTRY_DSN, key="value") assert logging_dict["handlers"]["sentry"]["key"] == "value"