diff --git a/bugsnag/__init__.py b/bugsnag/__init__.py index 38716463..5a74a852 100644 --- a/bugsnag/__init__.py +++ b/bugsnag/__init__.py @@ -13,7 +13,9 @@ add_metadata_tab, clear_request_config, notify, auto_notify, before_notify, start_session, auto_notify_exc_info, logger, leave_breadcrumb, - add_on_breadcrumb, remove_on_breadcrumb) + add_on_breadcrumb, remove_on_breadcrumb, + add_feature_flag, add_feature_flags, + clear_feature_flag, clear_feature_flags) __all__ = ('Client', 'Event', 'Configuration', 'RequestConfiguration', 'configuration', 'configure', 'configure_request', @@ -22,4 +24,5 @@ 'auto_notify_exc_info', 'Notification', 'logger', 'BreadcrumbType', 'Breadcrumb', 'Breadcrumbs', 'OnBreadcrumbCallback', 'leave_breadcrumb', 'add_on_breadcrumb', - 'remove_on_breadcrumb', 'FeatureFlag') + 'remove_on_breadcrumb', 'FeatureFlag', 'add_feature_flag', + 'add_feature_flags', 'clear_feature_flag', 'clear_feature_flags') diff --git a/bugsnag/legacy.py b/bugsnag/legacy.py index b61c7318..df793db4 100644 --- a/bugsnag/legacy.py +++ b/bugsnag/legacy.py @@ -1,8 +1,9 @@ -from typing import Dict, Any, Tuple, Type, Optional +from typing import Dict, Any, Tuple, Type, Optional, Union, List import types import sys from bugsnag.breadcrumbs import BreadcrumbType, OnBreadcrumbCallback +from bugsnag.feature_flags import FeatureFlag from bugsnag.configuration import RequestConfiguration from bugsnag.client import Client @@ -160,3 +161,22 @@ def _auto_leave_breadcrumb( type: BreadcrumbType ) -> None: default_client._auto_leave_breadcrumb(message, metadata, type) + + +def add_feature_flag( + name: Union[str, bytes], + variant: Union[None, str, bytes] = None +) -> None: + default_client.add_feature_flag(name, variant) + + +def add_feature_flags(feature_flags: List[FeatureFlag]) -> None: + default_client.add_feature_flags(feature_flags) + + +def clear_feature_flag(name: Union[str, bytes]) -> None: + default_client.clear_feature_flag(name) + + +def clear_feature_flags() -> None: + default_client.clear_feature_flags() diff --git a/tests/test_client.py b/tests/test_client.py index b4bd28c8..0caffcfe 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -37,6 +37,7 @@ def setUp(self): install_sys_hook=False) self.client.clear_feature_flags() + legacy.clear_feature_flags() # Initialisation @@ -1564,6 +1565,55 @@ def test_feature_flags_can_be_cleared(self): assert self.client.feature_flags == [] + def test_feature_flags_can_be_added_individually_with_legacy_client(self): + legacy.add_feature_flag('one') + legacy.add_feature_flag('two', 'a') + legacy.add_feature_flag('three', None) + + assert legacy.default_client.feature_flags == [ + FeatureFlag('one'), + FeatureFlag('two', 'a'), + FeatureFlag('three') + ] + + def test_feature_flags_can_be_added_in_bulk_with_legacy_client(self): + legacy.add_feature_flags([ + FeatureFlag('a', '1'), + FeatureFlag('b'), + FeatureFlag('c', '3') + ]) + + assert legacy.default_client.feature_flags == [ + FeatureFlag('a', '1'), + FeatureFlag('b'), + FeatureFlag('c', '3') + ] + + def test_feature_flags_can_be_removed_with_legacy_client(self): + legacy.add_feature_flags([ + FeatureFlag('a', '1'), + FeatureFlag('b'), + FeatureFlag('c', '3') + ]) + + legacy.clear_feature_flag('b') + + assert legacy.default_client.feature_flags == [ + FeatureFlag('a', '1'), + FeatureFlag('c', '3') + ] + + def test_feature_flags_can_be_cleared_with_legacy_client(self): + legacy.add_feature_flags([ + FeatureFlag('a', '1'), + FeatureFlag('b'), + FeatureFlag('c', '3') + ]) + + legacy.clear_feature_flags() + + assert legacy.default_client.feature_flags == [] + def test_feature_flags_are_included_in_payload(self): self.client.add_feature_flags([ FeatureFlag('a', '1'),