Skip to content

Commit 036c8db

Browse files
committed
TT-98 fix: refactor comments made by Roberto
1 parent f3e7109 commit 036c8db

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export MS_CLIENT_ID=
2020
export MS_SCOPE=
2121
export MS_SECRET=
2222
export MS_ENDPOINT=
23+
export AZURE_APP_CONFIGURATION_CONNECTION_STRING=

commons/feature_toggles/feature_toggle_manager.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
from azure.appconfiguration import AzureAppConfigurationClient
55

66

7-
class MSConfig:
7+
class FeatureToggleConfig:
88
def check_variables_are_defined():
9-
auth_variables = ['AZURE_APP_CONFIGURATION_CONNECTION_STRING']
10-
for var in auth_variables:
11-
if var not in os.environ:
12-
raise EnvironmentError(
13-
"{} is not defined in the environment".format(var)
9+
azure_app_variable = 'AZURE_APP_CONFIGURATION_CONNECTION_STRING'
10+
if azure_app_variable not in os.environ:
11+
raise EnvironmentError(
12+
"{} is not defined in the environment".format(
13+
azure_app_variable
1414
)
15+
)
1516

1617
check_variables_are_defined()
1718
AZURE_APP_CONFIGURATION_CONNECTION_STRING = os.environ.get(
@@ -20,12 +21,13 @@ def check_variables_are_defined():
2021

2122

2223
class FeatureToggleManager:
23-
def __init__(self, key: str, label: str = None, config=MSConfig):
24+
def __init__(
25+
self, key: str, label: str = None, config=FeatureToggleConfig
26+
):
2427
self.key = key
2528
self.label = label
2629
self.config = config
2730
self.client = self.get_azure_app_configuration_client()
28-
self.configuration = {}
2931

3032
def get_azure_app_configuration_client(self):
3133
connection_str = self.config.AZURE_APP_CONFIGURATION_CONNECTION_STRING
@@ -37,14 +39,16 @@ def get_azure_app_configuration_client(self):
3739

3840
def get_configuration(self, key: str, label: str):
3941
configuration = self.client.get_configuration_setting(
40-
key=f".appconfig.featureflag/{self.key}", label=self.label
42+
key=f".appconfig.featureflag/{key}", label=label
4143
)
4244

4345
return configuration
4446

4547
def get_data_configuration(self):
46-
self.configuration = self.get_configuration(self.key, self.label)
47-
result = json.loads(self.configuration.value)
48+
feature_data_configuration = self.get_configuration(
49+
self.key, self.label
50+
)
51+
result = json.loads(feature_data_configuration.value)
4852

4953
return result
5054

tests/commons/feature_toggles/feature_toggles_manager_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pytest import mark
44

55

6-
def mock_payload(enabled, user):
6+
def mock_feature_toggle_config_response(enabled, user):
77
return {
88
"id": "test-feature-toggle",
99
"description": "Feature Toggle test Backend",
@@ -54,8 +54,10 @@ def test_if_is_toggle_enabled_for_user(
5454
):
5555
current_user_email_mock.return_value = currrent_user_email
5656
feature_toggle_manager = FeatureToggleManager("test-feature-toggle")
57-
feature_toggle_manager.get_data_configuration.return_value = mock_payload(
58-
is_toggle_enabled, user_email_enabled
57+
feature_toggle_manager.get_data_configuration.return_value = (
58+
mock_feature_toggle_config_response(
59+
is_toggle_enabled, user_email_enabled
60+
)
5961
)
6062

6163
assert (

time_tracker_api/time_entries/time_entries_namespace.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,6 @@ def get(self):
268268
return time_entries_dao.get_lastest_entries_by_project(conditions={})
269269

270270

271-
@ns.route('/feature-toggles')
272-
class FeaturesToggles(Resource):
273-
@ns.doc('feature_toggle_tests')
274-
@ns.marshal_list_with(time_entry)
275-
@ns.response(HTTPStatus.NOT_FOUND, 'No time entries found')
276-
def get(self):
277-
"""Test Feature Toggles"""
278-
featureTest = FeatureToggleManager("ui-list-test-users")
279-
test = featureTest.is_toggle_enabled_for_user()
280-
if test:
281-
return time_entries_dao.get_lastest_entries_by_project(
282-
conditions={}
283-
)
284-
else:
285-
conditions = attributes_filter.parse_args()
286-
return time_entries_dao.get_all(conditions=conditions)
287-
288-
289271
@ns.route('/<string:id>')
290272
@ns.response(HTTPStatus.NOT_FOUND, 'This time entry does not exist')
291273
@ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format')

0 commit comments

Comments
 (0)