Example #1
0
    def test_saves_on_change(self):
        filename = mktemp(".json")
        repo = FileRepository(filename)
        repo.set_feature_state(FeatureState("FLAG", True))

        with open(filename, "r") as file:
            data = json.load(file)
        self.assertTrue(data["FLAG"]["enabled"])
Example #2
0
    def test_writes_file_after_exit(self):
        filename = mktemp(".json")
        file_repo = FileRepository(filename)
        self.features.configure(state_repository=file_repo)

        with self.features.new_feature_context(read_only=False):
            self.features.set_feature_state(FeatureState("FLAG", True))

        with open(filename, 'r') as file:
            data = json.load(file)
        self.assertTrue(data["FLAG"]["enabled"])
Example #3
0
 def test_save(self):
     with patch.object(requests,
                       'get',
                       return_value=self.empty_get_response):
         with patch.object(requests, 'put',
                           return_value=self.put_response) as put_method:
             feature_state = self.repo.set_feature_state(
                 FeatureState("A", enabled=True))
             put_method.assert_called_with("http://localhost:8080",
                                           data={'A': {
                                               'enabled': True
                                           }})
Example #4
0
 def test_save(self):
     when(self.table).scan().thenReturn({"Items": []})
     self.repo = DynamodbRepository(
         dynamodb_resource=self.dynamodb_resource,
         table_name=self.table_name)
     self.repo.set_feature_state(FeatureState("f1", True))
     verify(self.table).put_item(Item={
         "featureName": "f1",
         "featureState": {
             "enabled": True
         }
     })
Example #5
0
    def test_load_called_on_set_feature_state(self):
        self.repo.set_feature_state(FeatureState("A", enabled=True))

        self.assertTrue(self.repo.loaded)
 def test_set_feature_state(self):
     self.repo = DynamodbRepository(self.local_dynamodb.resource)
     self.repo.set_feature_state(FeatureState("F1", True))
     self.local_dynamodb.assert_contains_item(table_name="features",
                                              key={"featureName": "F1"})
Example #7
0
 def __given_repo_with_feature_enabled(self, feature_name):
     feature_state = FeatureState(feature_name, True)
     when(self.state_repo).get_feature_state(feature_name).thenReturn(
         feature_state)
Example #8
0
    def test_dont_pass_through_to_repo_if_present(self):
        self.__given_snapshot({"F1": FeatureState("F1", True)})

        feature_state = self.snapshot.get_feature_state("F1")
        self.assertTrue(feature_state.enabled)
        verify(self.state_repo, times=0).get_feature_state("F1")
Example #9
0
    def test_set_non_feature_state(self):
        self.repo.set_feature_state(FeatureState("A", enabled=True))

        self.assertEqual(self.repo.feature_states,
                         {"A": FeatureState("A", enabled=True)})
Example #10
0
    def test_get_disabled_feature_state(self):
        self.repo.feature_states = {"A": FeatureState("A", enabled=False)}

        feature_state = self.repo.get_feature_state("A")

        self.assertFalse(feature_state.enabled)
Example #11
0
    def test_get_enabled_feature_state(self):
        self.repo.feature_states = {"A": FeatureState("A", enabled=True)}

        feature_state = self.repo.get_feature_state("A")

        self.assertTrue(feature_state.enabled)
Example #12
0
    def test_init(self):
        f = FeatureState("Enabled", True)

        self.assertEqual("Enabled", f.name)
        self.assertTrue(f.enabled)
Example #13
0
 def test_repr(self):
     a = FeatureState("a", enabled=True)
     self.assertEqual("<FeatureState name=a enabled=True>", repr(a))
Example #14
0
 def test_ne_if_enabled_doesnt_match(self):
     a = FeatureState("a", enabled=True)
     self.assertNotEqual(FeatureState("a", enabled=False), a)
Example #15
0
 def test_eq_if_attributes_match(self):
     a_enabled = FeatureState("a", enabled=True)
     self.assertEqual(FeatureState("a", enabled=True), a_enabled)