Coverage for webapp/store_api.py: 100%
20 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-18 22:11 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-18 22:11 +0000
1import requests
2from canonicalwebteam.store_api.devicegw import DeviceGW
3from canonicalwebteam.store_api.publishergw import PublisherGW
4from webapp.observability.utils import trace_function
7def decorate_all_methods(decorator, cls):
8 class WrappedClass(cls):
9 pass
11 for attr_name in dir(cls):
12 # ignore private and special methods like __init__ etc.
13 if attr_name.startswith("__"):
14 continue
15 attr = getattr(cls, attr_name)
16 # only decorate callable attributes (these are mostly API calls)
17 if callable(attr):
18 setattr(WrappedClass, attr_name, decorator(attr))
20 return WrappedClass
23TracedPubilsherGW = decorate_all_methods(trace_function, PublisherGW)
24TracedDeviceGW = decorate_all_methods(trace_function, DeviceGW)
27request_session = requests.Session()
28publisher_gateway = TracedPubilsherGW("charm", request_session)
29device_gateway = TracedDeviceGW("charm", request_session)
30device_gateway_sbom = TracedDeviceGW("sbom", request_session)