Skip to content

Commit

Permalink
change ab_test to accept a list of ConversionTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
kohlmeier committed Oct 20, 2011
1 parent bad6d51 commit d4ecdb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion gae_bingo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ def ab_test(canonical_name, alternative_params = None, conversion_name = None, c
# Handle multiple conversions for a single experiment by just quietly
# creating multiple experiments for each conversion
conversion_names = conversion_name if type(conversion_name) == list else [conversion_name]
conversion_types = conversion_type if type(conversion_type) == list else [conversion_type] * len(conversion_names)

for i, conversion_name in enumerate(conversion_names):
if len(conversion_names) != len(conversion_types):
# we were called improperly with mismatched lists lengths.. default everything to Binary
conversion_types = [ConversionTypes.Binary] * len(conversion_names)

for i, (conversion_name, conversion_type) in enumerate(zip(conversion_names,conversion_types)):
unique_experiment_name = canonical_name if i == 0 else "%s (%s)" % (canonical_name, i + 1)

exp, alts = create_experiment_and_alternatives(
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def participate_in_crocodiles(self):

def participate_in_hippos(self):
# Multiple conversions test
return ab_test("hippos", conversion_type=ConversionTypes.Counting)
return ab_test("hippos", conversion_name=["hippos_binary", "hippos_counting"], conversion_type=[ConversionTypes.Binary, ConversionTypes.Counting])

def convert_in(self):
bingo(self.request.get("conversion_name"))
Expand Down
9 changes: 6 additions & 3 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ def run_tests():
# Test an experiment with a Counting type conversion by converting multiple times for a single user
assert(test_response("participate_in_hippos") in [True, False])
for i in range(0, 5):
assert(test_response("convert_in", {"conversion_name": "hippos"}, use_last_cookies=True) == True)
assert(test_response("convert_in", {"conversion_name": "hippos_binary"}, use_last_cookies=True) == True)
assert(test_response("convert_in", {"conversion_name": "hippos_counting"}, use_last_cookies=True) == True)
dict_conversions_server = test_response("count_conversions_in", {"experiment_name": "hippos"})
assert(1 == reduce(lambda a, b: a + b, map(lambda key: dict_conversions_server[key], dict_conversions_server)))
dict_conversions_server = test_response("count_conversions_in", {"experiment_name": "hippos (2)"})
assert(5 == reduce(lambda a, b: a + b, map(lambda key: dict_conversions_server[key], dict_conversions_server)))

# Participate in experiment D (weight alternatives), keeping track of alternative returned count.
Expand All @@ -179,14 +182,14 @@ def run_tests():
assert(dict_alternatives.get("b", 0) < dict_alternatives.get("c", 0))

# Check experiments count
assert(test_response("count_experiments") == 6)
assert(test_response("count_experiments") == 7)

# Test persist and load from DS
assert(test_response("persist") == True)
assert(test_response("flush_memcache") == True)

# Check experiments and converion counts remain after persist and memcache flush
assert(test_response("count_experiments") == 6)
assert(test_response("count_experiments") == 7)

dict_conversions_server = test_response("count_conversions_in", {"experiment_name": "chimpanzees (2)"})
assert(expected_conversions == reduce(lambda a, b: a + b, map(lambda key: dict_conversions_server[key], dict_conversions_server)))
Expand Down

0 comments on commit d4ecdb8

Please sign in to comment.