Skip to content

[FSSDK-8478] fix: make client odp methods private #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions optimizely/optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(
self.config_manager = StaticConfigManager(**config_manager_options)

self.odp_manager: OdpManager
self.setup_odp(self.config_manager.get_sdk_key())
self._setup_odp(self.config_manager.get_sdk_key())

self.event_builder = event_builder.EventBuilder()
self.decision_service = decision_service.DecisionService(self.logger, user_profile_service)
Expand Down Expand Up @@ -1292,7 +1292,7 @@ def _decide_for_keys(
decisions[key] = decision
return decisions

def setup_odp(self, sdk_key: Optional[str]) -> None:
def _setup_odp(self, sdk_key: Optional[str]) -> None:
"""
- Make sure odp manager is instantiated with provided parameters or defaults.
- Set up listener to update odp_config when datafile is updated.
Expand Down Expand Up @@ -1352,14 +1352,14 @@ def _update_odp_config_on_datafile_update(self) -> None:
config.all_segments
)

def identify_user(self, user_id: str) -> None:
def _identify_user(self, user_id: str) -> None:
if not self.is_valid:
self.logger.error(enums.Errors.INVALID_OPTIMIZELY.format('identify_user'))
return

self.odp_manager.identify_user(user_id)

def fetch_qualified_segments(self, user_id: str, options: Optional[list[str]] = None) -> Optional[list[str]]:
def _fetch_qualified_segments(self, user_id: str, options: Optional[list[str]] = None) -> Optional[list[str]]:
if not self.is_valid:
self.logger.error(enums.Errors.INVALID_OPTIMIZELY.format('fetch_qualified_segments'))
return None
Expand Down
4 changes: 2 additions & 2 deletions optimizely/optimizely_user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
] = {}

if self.client and identify:
self.client.identify_user(user_id)
self.client._identify_user(user_id)

class OptimizelyDecisionContext:
""" Using class with attributes here instead of namedtuple because
Expand Down Expand Up @@ -327,7 +327,7 @@ def fetch_qualified_segments(
A boolean value indicating if the fetch was successful.
"""
def _fetch_qualified_segments() -> bool:
segments = self.client.fetch_qualified_segments(self.user_id, options or []) if self.client else None
segments = self.client._fetch_qualified_segments(self.user_id, options or []) if self.client else None
self.set_qualified_segments(segments)
success = segments is not None

Expand Down
3 changes: 2 additions & 1 deletion tests/test_notification_center_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def test_remove_notification_center(self):
mock_send.assert_called_once()
mock_send.reset_mock()

self.assertIn(notification_center, _NotificationCenterRegistry._notification_centers.values())
_NotificationCenterRegistry.remove_notification_center(sdk_key)
self.assertNotIn(notification_center, _NotificationCenterRegistry._notification_centers)
self.assertNotIn(notification_center, _NotificationCenterRegistry._notification_centers.values())

revised_datafile = copy.deepcopy(self.config_dict_with_audience_segments)
revised_datafile['revision'] = str(int(revised_datafile['revision']) + 1)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -5143,7 +5143,7 @@ def test_user_context_invalid_user_id(self):
def test_send_identify_event__when_called_with_odp_enabled(self):
mock_logger = mock.Mock()
client = optimizely.Optimizely(json.dumps(self.config_dict_with_audience_segments), logger=mock_logger)
with mock.patch.object(client, 'identify_user') as identify:
with mock.patch.object(client, '_identify_user') as identify:
client.create_user_context('user-id')

identify.assert_called_once_with('user-id')
Expand Down
6 changes: 3 additions & 3 deletions tests/test_user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ def test_none_client_should_not_fail(self):
def test_send_identify_event_when_user_context_created(self):
mock_logger = mock.Mock()
client = optimizely.Optimizely(json.dumps(self.config_dict_with_audience_segments), logger=mock_logger)
with mock.patch.object(client, 'identify_user') as identify:
with mock.patch.object(client, '_identify_user') as identify:
OptimizelyUserContext(client, mock_logger, 'user-id')

identify.assert_called_once_with('user-id')
Expand All @@ -2024,13 +2024,13 @@ def test_send_identify_event_when_user_context_created(self):
def test_identify_is_skipped_with_decisions(self):
mock_logger = mock.Mock()
client = optimizely.Optimizely(json.dumps(self.config_dict_with_features), logger=mock_logger)
with mock.patch.object(client, 'identify_user') as identify:
with mock.patch.object(client, '_identify_user') as identify:
user_context = OptimizelyUserContext(client, mock_logger, 'user-id')

identify.assert_called_once_with('user-id')
mock_logger.error.assert_not_called()

with mock.patch.object(client, 'identify_user') as identify:
with mock.patch.object(client, '_identify_user') as identify:
user_context.decide('test_feature_in_rollout')
user_context.decide_all()
user_context.decide_for_keys(['test_feature_in_rollout'])
Expand Down