# Path: bugsnag/configuration.py
# class RequestConfiguration:
#     """
#     Per-request Bugsnag configuration settings.
#     """
# 
#     @classmethod
#     def get_instance(cls):
#         """
#         Get this thread's instance of the RequestConfiguration.
#         """
# 
#         try:
#             instance = _request_info.get()
#         except LookupError:
#             instance = None
# 
#         if instance is None:
#             instance = RequestConfiguration()
#             _request_info.set(instance)  # type: ignore
# 
#         return instance
# 
#     @classmethod
#     def clear(cls):
#         """
#         Clear this thread's instance of the RequestConfiguration.
#         """
#         _request_info.set(None)
# 
#     def __init__(self):
#         self.context = None
#         self.grouping_hash = None
#         self.user = {}
#         self.metadata = {}
# 
#         # legacy fields
#         self.user_id = None
#         self.extra_data = {}
#         self.request_data = {}
#         self.environment_data = {}
#         self.session_data = {}
# 
#     def get(self, name) -> Any:
#         """
#         Get a single configuration option
#         """
#         return getattr(self, name)
# 
#     def configure(self, **options):
#         """
#         Set one or more configuration settings.
#         """
#         for name, value in options.items():
#             setattr(self, name, value)
# 
#         return self
# 
#     @property
#     def meta_data(self) -> Any:
#         warnings.warn('RequestConfiguration.meta_data has been renamed to ' +
#                       '"metadata"', DeprecationWarning)
#         return self.metadata


import asyncio
import bugsnag
from unittest import IsolatedAsyncioTestCase
from bugsnag.configuration import RequestConfiguration



class AsyncRequestTest(IsolatedAsyncioTestCase):
    """
    Test the RequestConfiguration plumbing, which underpins the integrations'
    handling of request-specific data in async contexts
    """
    async def test_async_task_metadata(self):
        bugsnag.configure_request(wins={'total': 3, 'last': 2})

        async def coro():
            bugsnag.configure_request(wins={'total': 1, 'last': 1})

        asyncio.ensure_future(coro())
        data = RequestConfiguration.get_instance().wins

        assert data['total'] == 3
        assert data['last'] == 2

    async def test_async_context_storage(self):
        async def slow_crash():
            bugsnag.configure_request(local_data={'apples': 1})
            await asyncio.sleep(1)

# Path: bugsnag/configuration.py
# class RequestConfiguration:
#     """
#     Per-request Bugsnag configuration settings.
#     """
# 
#     @classmethod
#     def get_instance(cls):
#         """
#         Get this thread's instance of the RequestConfiguration.
#         """
# 
#         try:
#             instance = _request_info.get()
#         except LookupError:
#             instance = None
# 
#         if instance is None:
#             instance = RequestConfiguration()
#             _request_info.set(instance)  # type: ignore
# 
#         return instance
# 
#     @classmethod
#     def clear(cls):
#         """
#         Clear this thread's instance of the RequestConfiguration.
#         """
#         _request_info.set(None)
# 
#     def __init__(self):
#         self.context = None
#         self.grouping_hash = None
#         self.user = {}
#         self.metadata = {}
# 
#         # legacy fields
#         self.user_id = None
#         self.extra_data = {}
#         self.request_data = {}
#         self.environment_data = {}
#         self.session_data = {}
# 
#     def get(self, name) -> Any:
#         """
#         Get a single configuration option
#         """
#         return getattr(self, name)
# 
#     def configure(self, **options):
#         """
#         Set one or more configuration settings.
#         """
#         for name, value in options.items():
#             setattr(self, name, value)
# 
#         return self
# 
#     @property
#     def meta_data(self) -> Any:
#         warnings.warn('RequestConfiguration.meta_data has been renamed to ' +
#                       '"metadata"', DeprecationWarning)
#         return self.metadata


# Path: tests/integrations/test_async_request.py
import asyncio
import bugsnag
from unittest import IsolatedAsyncioTestCase
from bugsnag.configuration import RequestConfiguration




class AsyncRequestTest(IsolatedAsyncioTestCase):
    """
    Test the RequestConfiguration plumbing, which underpins the integrations'
    handling of request-specific data in async contexts
    """
    async def test_async_task_metadata(self):
        bugsnag.configure_request(wins={'total': 3, 'last': 2})

        async def coro():
            bugsnag.configure_request(wins={'total': 1, 'last': 1})

        asyncio.ensure_future(coro())
        data = RequestConfiguration.get_instance().wins

        assert data['total'] == 3
        assert data['last'] == 2

    async def test_async_context_storage(self):
        async def slow_crash():
            bugsnag.configure_request(local_data={'apples': 1})
            await asyncio.sleep(1)

            data = RequestConfiguration.get_instance().local_data