-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat: Optimizely factory added #325
Conversation
optimizely/config_manager.py
Outdated
@@ -196,7 +196,7 @@ def __init__( | |||
self.datafile_url = self.get_datafile_url( | |||
sdk_key, url, url_template or self.DATAFILE_URL_TEMPLATE | |||
) | |||
self.set_update_interval(update_interval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are not supposed to change method name.
optimizely/config_manager.py
Outdated
""" Helper method to set frequency at which datafile has to be polled and ProjectConfig updated. | ||
|
||
Args: | ||
update_interval: Time in seconds after which to update datafile. | ||
""" | ||
|
||
logger = optimizely_logger.adapt_logger(optimizely_logger.NoOpLogger()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to assign new logger.
optimizely/config_manager.py
Outdated
if update_interval is None: | ||
update_interval = enums.ConfigManager.DEFAULT_UPDATE_INTERVAL | ||
self.logger.debug('Setting config update interval to default value {}.'.format(update_interval)) | ||
logger.debug('Setting config update interval to default value {}.'.format(update_interval)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this line.
This reverts commit e696f1c.
optimizely/optimizely_factory.py
Outdated
@@ -0,0 +1,180 @@ | |||
# Copyright 2016-2021, Optimizely |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change the header year to 2021 only as this file is created in this year
optimizely/optimizely_factory.py
Outdated
""" | ||
|
||
if isinstance(flush_interval, bool): | ||
logger.error('Flush interval is invalid, setting to default flush interval # {0}'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid logging and validation here as there should be logging and validation already done somewhere in SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine to have some major validation here.
optimizely/optimizely_factory.py
Outdated
logger: Optional LoggerInterface Provides a log method to log messages. | ||
""" | ||
|
||
if isinstance(batch_size, bool): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need this condition.
optimizely/optimizely_factory.py
Outdated
BatchEventProcessor._DEFAULT_BATCH_SIZE)) | ||
return | ||
|
||
if not batch_size > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we use else
or else if
optimizely/optimizely_factory.py
Outdated
return OptimizelyFactory.max_event_batch_size | ||
|
||
@staticmethod | ||
def set_flush_interval(flush_interval, logger=optimizely_logger.NoOpLogger().logger): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above comments.
tests/test_optimizely_factory.py
Outdated
optimizely_instance = OptimizelyFactory.default_instance('sdk_key') | ||
self.assertIsInstance(optimizely_instance.config_manager, PollingConfigManager) | ||
|
||
def test_default_instance_should_create_config_manager_when_polling_interval_and_blocking_timeout_are_set_valid( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shorten the name of func
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions and clarifications
optimizely/optimizely_factory.py
Outdated
@staticmethod | ||
def default_instance_with_config_manager(config_manager): | ||
return Optimizely( | ||
None, None, None, None, None, None, None, config_manager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None, None, None, None, None, None, None, config_manager | |
config_manager=config_manager |
tests/test_optimizely_factory.py
Outdated
# validate through validator | ||
self.assertTrue(validator.is_config_manager_valid(CustomConfigManager())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the point of validating one defined for test?
optimizely/optimizely_factory.py
Outdated
blocking_timeout = None | ||
|
||
@staticmethod | ||
def set_batch_size(batch_size, logger=optimizely_logger.NoOpLogger().logger): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passing a logger to set a parameter sounds weird. Can't remove all these validation with logging here since those parameters are validated again in event_processor.
optimizely/optimizely_factory.py
Outdated
config_manager = PollingConfigManager(**config_manager_options) | ||
|
||
optimizely = Optimizely( | ||
datafile, None, logger, error_handler, None, None, sdk_key, config_manager, notification_center |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we include "BatchEventProcessor" as a part of this factory method as a common configuration?
optimizely/optimizely_factory.py
Outdated
def set_batch_size(batch_size, logger=optimizely_logger.NoOpLogger().logger): | ||
""" Convenience method for setting the maximum number of events contained within a batch. | ||
Args: | ||
batch_size: Sets size of EventQueue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to lower case: event_queue.
I couldn't find class EentQueue in the sdk. Unless I missed smth
optimizely/optimizely_factory.py
Outdated
""" Convenience method for setting the maximum number of events contained within a batch. | ||
Args: | ||
batch_size: Sets size of EventQueue. | ||
logger: Optional LoggerInterface Provides a log method to log messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: ----> loger interface.
Otherwise it may hint to a class which doesn't exist
Also lover case "provides"
optimizely/optimizely_factory.py
Outdated
""" Convenience method for setting the maximum time interval in milliseconds between event dispatches. | ||
Args: | ||
flush_interval: Time interval between event dispatches. | ||
logger: Optional LoggerInterface Provides a log method to log messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use lower case "logging interface", and lower case "provides"
optimizely/optimizely_factory.py
Outdated
def default_instance(sdk_key, datafile=None): | ||
""" Returns a new optimizely instance.. | ||
Args: | ||
sdk_key: Required String uniquely identifying the fallback datafile corresponding to project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lower case "string". Python doesn't have static typing
optimizely/optimizely_factory.py
Outdated
|
||
""" Returns a new optimizely instance. | ||
if max_event_batch_size and max_event_flush_interval are None then default batch_size and flush_interval | ||
will be used to setup batchEventProcessor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to "BatchEventProcessor"
optimizely/optimizely_factory.py
Outdated
By default nothing would be logged. | ||
error_handler: Optional ErrorHandlerInterface which provides a handle_error method to handle exceptions. | ||
By default all exceptions will be suppressed. | ||
skip_json_validation: Optional Boolean param to skip JSON schema validation of the provided datafile. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lower case boolean
optimizely/optimizely_factory.py
Outdated
error_handler: Optional ErrorHandlerInterface which provides a handle_error method to handle exceptions. | ||
By default all exceptions will be suppressed. | ||
skip_json_validation: Optional Boolean param to skip JSON schema validation of the provided datafile. | ||
user_profile_service: Optional UserProfileServiceInterface Provides methods to store and retrieve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserProfileService interface
provides
optimizely/optimizely_factory.py
Outdated
skip_json_validation: Optional Boolean param to skip JSON schema validation of the provided datafile. | ||
user_profile_service: Optional UserProfileServiceInterface Provides methods to store and retrieve | ||
user profiles. | ||
config_manager: Optional ConfigManagerInterface Responds to 'config' method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConfigManager interface
responds
tests/test_optimizely_factory.py
Outdated
self.event_dispatcher = EventDispatcher() | ||
self.user_profile_service = UserProfileService() | ||
|
||
def test_default_instance_should_create_config_manager_when_sdk_key_is_given(self, _): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use double underscore in test name after the main part of the test name. In All tests. For example:
- test_default_instance__should_create_config_manager_when_sdk_key_is_given
- test_default_instance__should_create_config_set_default_values_when_polling_int_and_blocking_time_invalid
- etc
This is for consistency with other test names. Double underscore clarifies the specifics of the test in the second part of the test name, so it's nice to have that double underscore mark.
tests/test_optimizely_factory.py
Outdated
self.assertEqual(optimizely_instance.config_manager.update_interval, 40) | ||
self.assertEqual(optimizely_instance.config_manager.blocking_timeout, 5) | ||
|
||
def test_default_instance_should_create_config_set_default_values_when_polling_int_and_blocking_time_invalid( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double underscore test_default_instance__...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
5ab1aa1
to
5e13d7b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* polling interval updated * Revert "polling interval updated" This reverts commit e696f1c. * Create optimizely_factory.py * linting fixed * whitespaced removed * comments addressed and unit tests added * comments addressed * comments addressed
Summary
optimizely_factory.py
file added containingOptimizelyFactory
class.test_optimizely_factory.py
file added intests/
for test cases.Test plan