Skip to content

Commit

Permalink
🖊️ Added gt, lt, exact, exists tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oakbani committed Oct 24, 2018
1 parent a5e054c commit a6447ff
Showing 1 changed file with 258 additions and 1 deletion.
259 changes: 258 additions & 1 deletion tests/helpers_tests/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ def test_evaluate_assumes__OR_operator__when_first_item_in_array_not_recognized_
lambda a: False
))


browserConditionSafari = ['browser_type', 'safari', 'custom_attribute', 'exact']
booleanCondition = ['is_firefox', True, 'custom_attribute', 'exact']
integerCondition = ['num_users', 10, 'custom_attribute', 'exact']
Expand Down Expand Up @@ -335,6 +334,264 @@ def test_evaluate__returns_null__when_condition_has_an_invalid_match_property(se

self.assertIsNone(evaluator.evaluate(0))

exists_condition_list = [['input_value', None, 'custom_attribute', 'exists']]

def test_exists__returns_false__when_no_user_provided_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exists_condition_list, {}
)

self.assertStrictFalse(evaluator.evaluate(0))

def test_exists__returns_false__when_user_provided_value_is_null(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exists_condition_list, {'input_value': None}
)

self.assertStrictFalse(evaluator.evaluate(0))

def test_exists__returns_true__when_user_provided_value_is_string(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exists_condition_list, {'input_value': 'hi'}
)

self.assertStrictTrue(evaluator.evaluate(0))

def test_exists__returns_true__when_user_provided_value_is_number(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exists_condition_list, {'input_value': 10}
)

self.assertStrictTrue(evaluator.evaluate(0))

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exists_condition_list, {'input_value': 10.0}
)

self.assertStrictTrue(evaluator.evaluate(0))

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exists_condition_list, {'input_value': 10L}
)

self.assertStrictTrue(evaluator.evaluate(0))

def test_exists__returns_true__when_user_provided_value_is_boolean(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exists_condition_list, {'input_value': False}
)

self.assertStrictTrue(evaluator.evaluate(0))

exact_string_condition_list = [['favorite_constellation', 'Lacerta', 'custom_attribute', 'exact']]

def test_exact_string__returns_true__when_user_provided_value_is_equal_to_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_string_condition_list, {'favorite_constellation': 'Lacerta'}
)

self.assertStrictTrue(evaluator.evaluate(0))

def test_exact_string__returns_false__when_user_provided_value_is_not_equal_to_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_string_condition_list, {'favorite_constellation': 'The Big Dipper'}
)

self.assertStrictFalse(evaluator.evaluate(0))

def test_exact_string__returns_null__when_user_provided_value_is_different_type_from_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_string_condition_list, {'favorite_constellation': False}
)

self.assertIsNone(evaluator.evaluate(0))

def test_exact_string__returns_null__when_no_user_provided_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_string_condition_list, {}
)

self.assertIsNone(evaluator.evaluate(0))

exact_number_condition_list = [['lasers_count', 9000, 'custom_attribute', 'exact']]

def test_exact_number__returns_true__when_user_provided_value_is_equal_to_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_number_condition_list, {'lasers_count': 9000}
)

self.assertStrictTrue(evaluator.evaluate(0))

def test_exact_number__returns_false__when_user_provided_value_is_not_equal_to_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_number_condition_list, {'lasers_count': 8000}
)

self.assertStrictFalse(evaluator.evaluate(0))

def test_exact_number__returns_null__when_user_provided_value_is_different_type_from_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_number_condition_list, {'lasers_count': 'hi'}
)

self.assertIsNone(evaluator.evaluate(0))

def test_exact_number__returns_null__when_no_user_provided_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_number_condition_list, {}
)

self.assertIsNone(evaluator.evaluate(0))

exact_bool_condition_list = [['did_register_user', False, 'custom_attribute', 'exact']]

def test_exact_bool__returns_true__when_user_provided_value_is_equal_to_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_bool_condition_list, {'did_register_user': False}
)

self.assertStrictTrue(evaluator.evaluate(0))

def test_exact_bool__returns_false__when_user_provided_value_is_not_equal_to_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_bool_condition_list, {'did_register_user': True}
)

self.assertStrictFalse(evaluator.evaluate(0))

def test_exact_bool__returns_null__when_user_provided_value_is_different_type_from_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_bool_condition_list, {'did_register_user': 0}
)

self.assertIsNone(evaluator.evaluate(0))

def test_exact_bool__returns_null__when_no_user_provided_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.exact_bool_condition_list, {}
)

self.assertIsNone(evaluator.evaluate(0))

substring_condition_list = [['headline_text', 'buy now', 'custom_attribute', 'substring']]

def test_substring__returns_true__when_condition_value_is_substring_of_user_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.substring_condition_list, {'headline_text': 'Limited time, buy now!'}
)

self.assertStrictTrue(evaluator.evaluate(0))

def test_substring__returns_false__when_condition_value_is_not_a_substring_of_user_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.substring_condition_list, {'headline_text': 'Breaking news!'}
)

self.assertStrictFalse(evaluator.evaluate(0))

def test_substring__returns_null__when_user_provided_value_not_a_string(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.substring_condition_list, {'headline_text': 10}
)

self.assertIsNone(evaluator.evaluate(0))

def test_substring__returns_null__when_no_user_provided_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.substring_condition_list, {}
)

self.assertIsNone(evaluator.evaluate(0))

gt_condition_list = [['meters_travelled', 48.2, 'custom_attribute', 'gt']]

def test_greater_than__returns_true__when_user_value_greater_than_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.gt_condition_list, {'meters_travelled': 48.3}
)

self.assertStrictTrue(evaluator.evaluate(0))

def test_greater_than__returns_false__when_user_value_not_greater_than_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.gt_condition_list, {'meters_travelled': 48.2}
)

self.assertStrictFalse(evaluator.evaluate(0))

def test_greater_than__returns_null__when_user_value_is_not_a_number(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.gt_condition_list, {'meters_travelled': 'a long way'}
)

self.assertIsNone(evaluator.evaluate(0))

def test_greater_than__returns_null__when_no_user_provided_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.gt_condition_list, {}
)

self.assertIsNone(evaluator.evaluate(0))

lt_condition_list = [['meters_travelled', 48.2, 'custom_attribute', 'lt']]

def test_less_than__returns_true__when_user_value_less_than_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.lt_condition_list, {'meters_travelled': 48.1}
)

self.assertStrictTrue(evaluator.evaluate(0))

def test_less_than__returns_false__when_user_value_not_less_than_condition_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.lt_condition_list, {'meters_travelled': 48.2}
)

self.assertStrictFalse(evaluator.evaluate(0))

def test_less_than__returns_null__when_user_value_is_not_a_number(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.lt_condition_list, {'meters_travelled': 'a long way'}
)

self.assertIsNone(evaluator.evaluate(0))

def test_less_than__returns_null__when_no_user_provided_value(self):

evaluator = condition_helper.CustomAttributeConditionEvaluator(
self.lt_condition_list, {}
)

self.assertIsNone(evaluator.evaluate(0))


class ConditionDecoderTests(base.BaseTest):

Expand Down

0 comments on commit a6447ff

Please sign in to comment.