Exemplo n.º 1
0
 def test_sets_correct_is_enabled(self):
     name = self.txt()
     is_enabled = True
     meta = FeatureFlagStoreMeta(self.now, {})
     item = FeatureFlagStoreItem(name, is_enabled, meta)
     serialized = item.serialize()
     deserialized = FeatureFlagStoreItem.deserialize(serialized)
     self.assertEqual(is_enabled, deserialized.is_enabled())
Exemplo n.º 2
0
 def test_returns_instance_of_class(self):
     name = self.txt()
     is_enabled = True
     meta = FeatureFlagStoreMeta(self.now, {})
     item = FeatureFlagStoreItem(name, is_enabled, meta)
     serialized = item.serialize()
     deserialized = FeatureFlagStoreItem.deserialize(serialized)
     self.assertTrue(isinstance(deserialized, FeatureFlagStoreItem))
Exemplo n.º 3
0
 def test_sets_correct_client_data(self):
     name = self.txt()
     is_enabled = True
     client_data = {"foo": "bar"}
     meta = FeatureFlagStoreMeta(self.now, client_data)
     item = FeatureFlagStoreItem(name, is_enabled, meta)
     serialized = item.serialize()
     deserialized = FeatureFlagStoreItem.deserialize(serialized)
     self.assertEqual(client_data, deserialized.to_dict()["meta"]["client_data"])
Exemplo n.º 4
0
    def test_returns_false_when_bucketer_returns_true_and_conditions_return_false(
        self
    ):  # noqa: E501
        # flag.is_enabled(user_id=1, is_admin=False) # False
        bucketer = MagicMock()
        bucketer.check.return_value = True
        condition = Condition(is_admin=True)

        meta = FeatureFlagStoreMeta(self.now, bucketer=bucketer, conditions=[condition])
        item = FeatureFlagStoreItem(self.txt(), True, meta)
        self.assertFalse(item.is_enabled(is_admin=False))
Exemplo n.º 5
0
    def test_sets_correct_value_in_redis_with_default(self):
        feature_name = self.txt()

        self.store.create(feature_name)

        key = "/".join([self.store.base_key, feature_name])

        self.assertFalse(
            FeatureFlagStoreItem.deserialize(self.redis.get(key)).is_enabled())
Exemplo n.º 6
0
    def test_sets_correct_value_in_s3_with_default(self):
        feature_name = self.txt()

        self.store.create(feature_name)

        serialized = self.client.get_object(Bucket=self.bucket_name,
                                            Key=feature_name)["Body"].read()

        self.assertFalse(
            FeatureFlagStoreItem.deserialize(serialized).is_enabled())
Exemplo n.º 7
0
 def test_contains_all_fields_from_json(self):
     name = self.txt()
     is_enabled = True
     meta = FeatureFlagStoreMeta(self.now, {})
     item = FeatureFlagStoreItem(name, is_enabled, meta)
     self.assertEqual(json.dumps(item.to_dict()), item.serialize().decode("utf-8"))
Exemplo n.º 8
0
 def test_is_base_64_encoded(self):
     name = self.txt()
     is_enabled = True
     meta = FeatureFlagStoreMeta(self.now, {})
     item = FeatureFlagStoreItem(name, is_enabled, meta)
     self.assertTrue(isinstance(item.serialize().decode("utf-8"), str))
Exemplo n.º 9
0
 def test_includes_correct_meta(self):
     client_data = {"foo": "bar"}
     meta = FeatureFlagStoreMeta(self.now, client_data)
     item = FeatureFlagStoreItem(self.txt(), True, meta)
     self.assertEqual(meta.to_dict(), item.to_dict()["meta"])
Exemplo n.º 10
0
 def test_includes_correct_is_enabled_when_false(self):
     is_enabled = False
     item = FeatureFlagStoreItem(
         self.txt(), is_enabled, FeatureFlagStoreMeta(self.now, {})
     )
     self.assertEqual(is_enabled, item.to_dict()["is_enabled"])
Exemplo n.º 11
0
 def test_includes_correct_feature_name(self):
     name = self.txt()
     meta = FeatureFlagStoreMeta(self.now, {})
     item = FeatureFlagStoreItem(name, True, meta)
     self.assertEqual(name, item.to_dict()["feature_name"])
Exemplo n.º 12
0
 def test_returns_true_if_bucketer_check_returns_true(self):
     bucketer = MagicMock()
     bucketer.check.return_value = True
     meta = FeatureFlagStoreMeta(self.now, bucketer=bucketer)
     item = FeatureFlagStoreItem(self.txt(), True, meta)
     self.assertTrue(item.is_enabled())
Exemplo n.º 13
0
 def test_is_true_if_all_of_many_conditions_are_matched(self):
     conditions = [Condition(foo=True), Condition(x=9)]
     meta = FeatureFlagStoreMeta(self.now, conditions=conditions)
     item = FeatureFlagStoreItem(self.txt(), True, meta)
     self.assertTrue(item.is_enabled(foo=True, x=9))
Exemplo n.º 14
0
 def test_is_false_if_conditions_are_not_matched(self):
     meta = FeatureFlagStoreMeta(self.now, conditions=[Condition(foo=True)])
     item = FeatureFlagStoreItem(self.txt(), True, meta)
     self.assertFalse(item.is_enabled(foo=False))
Exemplo n.º 15
0
 def test_is_enabled_is_false(self):
     meta = FeatureFlagStoreMeta(self.now, {})
     item = FeatureFlagStoreItem(self.txt(), False, meta)
     self.assertFalse(item.is_enabled())