Ejemplo n.º 1
0
    def test_complicated_flag(self):
        Person.objects.create(
            team=self.team,
            distinct_ids=["test_id"],
            properties={"email": "*****@*****.**"},
        )

        feature_flag = self.create_feature_flag(
            filters={
                "groups": [
                    {
                        "properties": [{
                            "key": "email",
                            "type": "person",
                            "value": "*****@*****.**",
                            "operator": "exact"
                        }],
                        "rollout_percentage":
                        100,
                    },
                    {
                        "rollout_percentage": 50
                    },
                ]
            })

        self.assertEqual(
            FeatureFlagMatcher(feature_flag, "test_id").get_match(),
            FeatureFlagMatch())
        self.assertEqual(
            FeatureFlagMatcher(feature_flag, "example_id").get_match(),
            FeatureFlagMatch())
        self.assertIsNone(
            FeatureFlagMatcher(feature_flag, "another_id").get_match())
Ejemplo n.º 2
0
    def test_legacy_user_in_cohort(self):
        Person.objects.create(team=self.team,
                              distinct_ids=["example_id_2"],
                              properties={"$some_prop_2": "something_2"})
        cohort = Cohort.objects.create(team=self.team,
                                       groups=[{
                                           "properties": {
                                               "$some_prop_2": "something_2"
                                           }
                                       }],
                                       name="cohort2")
        cohort.calculate_people_ch(pending_version=0)

        feature_flag: FeatureFlag = self.create_feature_flag(filters={
            "properties": [{
                "key": "id",
                "value": cohort.pk,
                "type": "cohort"
            }],
        })

        feature_flag.update_cohorts()

        self.assertEqual(
            FeatureFlagMatcher(feature_flag, "example_id_2").get_match(),
            FeatureFlagMatch())
        self.assertIsNone(
            FeatureFlagMatcher(feature_flag, "another_id").get_match())
Ejemplo n.º 3
0
 def test_legacy_rollout_and_property_filter(self):
     Person.objects.create(
         team=self.team,
         distinct_ids=["example_id"],
         properties={"email": "*****@*****.**"},
     )
     Person.objects.create(
         team=self.team,
         distinct_ids=["another_id"],
         properties={"email": "*****@*****.**"},
     )
     Person.objects.create(
         team=self.team,
         distinct_ids=["id_number_3"],
         properties={"email": "*****@*****.**"},
     )
     feature_flag = self.create_feature_flag(
         rollout_percentage=50,
         filters={
             "properties": [{
                 "key": "email",
                 "value": "*****@*****.**",
                 "type": "person"
             }]
         },
     )
     with self.assertNumQueries(1):
         self.assertEqual(
             FeatureFlagMatcher(feature_flag, "example_id").get_match(),
             FeatureFlagMatch())
     self.assertIsNone(
         FeatureFlagMatcher(feature_flag, "another_id").get_match())
     self.assertIsNone(
         FeatureFlagMatcher(feature_flag, "id_number_3").get_match())
Ejemplo n.º 4
0
 def test_legacy_rollout_percentage(self):
     feature_flag = self.create_feature_flag(rollout_percentage=50)
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "example_id").get_match(),
         FeatureFlagMatch())
     self.assertIsNone(
         FeatureFlagMatcher(feature_flag, "another_id").get_match())
Ejemplo n.º 5
0
 def test_empty_group(self):
     feature_flag = self.create_feature_flag(filters={"groups": [{}]})
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "example_id").get_match(),
         FeatureFlagMatch())
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "another_id").get_match(),
         FeatureFlagMatch())
Ejemplo n.º 6
0
 def test_blank_flag(self):
     # Blank feature flags now default to be released for everyone
     feature_flag = self.create_feature_flag()
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "example_id").get_match(),
         FeatureFlagMatch())
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "another_id").get_match(),
         FeatureFlagMatch())
Ejemplo n.º 7
0
 def test_rollout_percentage(self):
     feature_flag = self.create_feature_flag(
         filters={"groups": [{
             "rollout_percentage": 50
         }]})
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "example_id").get_match(),
         FeatureFlagMatch())
     self.assertIsNone(
         FeatureFlagMatcher(feature_flag, "another_id").get_match())
Ejemplo n.º 8
0
 def test_zero_rollout_percentage(self):
     feature_flag = self.create_feature_flag(
         filters={"groups": [{
             "properties": [],
             "rollout_percentage": 0
         }]})
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "example_id").get_match(), None)
Ejemplo n.º 9
0
    def test_flag_by_groups_with_rollout_50(self):
        self.create_groups()
        feature_flag = self.create_feature_flag(
            filters={
                "aggregation_group_type_index": 1,
                "groups": [{
                    "rollout_percentage": 50
                }],
            })

        self.assertIsNone(
            FeatureFlagMatcher(feature_flag, "", {
                "project": "1"
            }).get_match())
        self.assertEqual(
            FeatureFlagMatcher(feature_flag, "", {
                "project": "4"
            }).get_match(), FeatureFlagMatch())
Ejemplo n.º 10
0
 def test_legacy_property_filters(self):
     Person.objects.create(
         team=self.team,
         distinct_ids=["example_id"],
         properties={"email": "*****@*****.**"},
     )
     Person.objects.create(
         team=self.team,
         distinct_ids=["another_id"],
         properties={"email": "*****@*****.**"},
     )
     feature_flag = self.create_feature_flag(filters={
         "properties": [{
             "key": "email",
             "value": "*****@*****.**"
         }]
     }, )
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "example_id").get_match(),
         FeatureFlagMatch())
     self.assertIsNone(
         FeatureFlagMatcher(feature_flag, "another_id").get_match())
Ejemplo n.º 11
0
 def test_flag_by_group_properties(self):
     self.create_groups()
     feature_flag = self.create_feature_flag(
         filters={
             "aggregation_group_type_index":
             0,
             "groups": [{
                 "properties": [{
                     "key": "name",
                     "value": "foo.inc",
                     "type": "group",
                     "group_type_index": 0
                 }],
             }],
         })
     self.assertEqual(
         FeatureFlagMatcher(feature_flag, "", {
             "organization": "foo"
         }).get_match(), FeatureFlagMatch())
     self.assertIsNone(
         FeatureFlagMatcher(feature_flag, "", {
             "organization": "bar"
         }).get_match())
Ejemplo n.º 12
0
    def test_variants(self):
        feature_flag = self.create_feature_flag(
            filters={
                "groups": [{
                    "properties": [],
                    "rollout_percentage": None
                }],
                "multivariate": {
                    "variants": [
                        {
                            "key": "first-variant",
                            "name": "First Variant",
                            "rollout_percentage": 50
                        },
                        {
                            "key": "second-variant",
                            "name": "Second Variant",
                            "rollout_percentage": 25
                        },
                        {
                            "key": "third-variant",
                            "name": "Third Variant",
                            "rollout_percentage": 25
                        },
                    ],
                },
            })

        self.assertEqual(
            FeatureFlagMatcher(feature_flag, "11").get_match(),
            FeatureFlagMatch(variant="first-variant"))
        self.assertEqual(
            FeatureFlagMatcher(feature_flag, "example_id").get_match(),
            FeatureFlagMatch(variant="second-variant"))
        self.assertEqual(
            FeatureFlagMatcher(feature_flag, "3").get_match(),
            FeatureFlagMatch(variant="third-variant"))