Skip to content

Commit

Permalink
Add feature flag API to legacy.py
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed Aug 9, 2023
1 parent bf2a5ef commit b4772cc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
7 changes: 5 additions & 2 deletions bugsnag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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')
22 changes: 21 additions & 1 deletion bugsnag/legacy.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
50 changes: 50 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setUp(self):
install_sys_hook=False)

self.client.clear_feature_flags()
legacy.clear_feature_flags()

# Initialisation

Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit b4772cc

Please sign in to comment.