Skip to content

Commit

Permalink
Issue #2944 - Address review feedback.
Browse files Browse the repository at this point in the history
Co-Authored-By: Karl Dubost <[email protected]>
  • Loading branch information
Mike Taylor and Karl Dubost committed Oct 8, 2019
1 parent 6fbfaa1 commit fba6b97
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
24 changes: 13 additions & 11 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,22 @@ def update_status_config(milestones_content):


def get_variation_from_env(envvar_value):
"""Return a tuple with variation data from the specific environment
variable key.
"""Convert a string to a tuple of integers.
Raise an exception if the passed in envvar doesn't look something
like: '0 100'
Raise an exception if the passed envvar_value doesn't follow this pattern:
'0 100'
This is currently used for defining the variation data of the A/B
experiment regarding the multi-steps form.
"""
try:
# We want to create a tuple of integers from a string containing
# integers. Anything else should throw.
rv = tuple(int(x) for x in envvar_value.strip().split(' '))
if (len(rv) is not 2):
raise Exception('The format is incorrect. Expected "{int} {int}"?')
rv = tuple(int(x) for x in envvar_value.strip().split())
if (len(rv) != 2):
raise ValueError('The format is incorrect. Expected "{int} {int}"')
except Exception as e:
print("Something went wrong: {0}".format(e))
print("Something went wrong with AB test configuration: {0}".format(e))
raise e
return rv

Expand Down Expand Up @@ -221,9 +223,9 @@ def get_variation_from_env(envvar_value):

# Get AB experiment variation values from the environement.
# By default, it will serve v1 100% of the time.
FORM_V1_VARIATION = os.environ.get('FORM_V1_VARIATION') or '0 100'
FORM_V2_VARIATION = os.environ.get('FORM_V2_VARIATION') or '100 100'
EXP_MAX_AGE = os.environ.get('EXP_MAX_AGE', None)
FORM_V1_VARIATION = os.environ.get('FORM_V1_VARIATION', '0 100')
FORM_V2_VARIATION = os.environ.get('FORM_V2_VARIATION', '100 100')
EXP_MAX_AGE = int(os.environ.get('EXP_MAX_AGE', 0))

# AB testing config
AB_EXPERIMENTS = {
Expand Down
2 changes: 1 addition & 1 deletion docs/ab-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You can enable/disable AB testing support by configuring the following environme
`FORM_V2_VARIATION`: expects a string of the format '{int} {int}'
`EXP_MAX_AGE`: expects a number which defines when the experiment cookie expires

These are read by the `config.AB_EXPERIMENT` dictionary in `__init__.py` and converted to a tuple.
These are read by the `config.AB_EXPERIMENT` dictionary in `./config/__init__.py` and converted to a tuple.
This will configure flask to set cookies to responses. For example, setting the variables to the following:

```
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def test_update_status_config(self):
self.assertEqual(actual, expected)

def test_get_variation_from_env(self):
"""Make sure it doesn't blow up when it shouldn't, and does when
it should.
"""
Check the conversion from string to tuples of two int.
"""
self.assertRaises(Exception, get_variation_from_env, 'a b')
self.assertRaises(Exception, get_variation_from_env, 'None')
Expand Down

0 comments on commit fba6b97

Please sign in to comment.