def test_patch_400_extrafields(self, api): BinaryFlag.create("flag0") api.patch_json("/flags/flag0", { "value": True, "label": "Label", }, status=400)
def test_flag_not(self, fakestore): flag0 = BinaryFlag.create("flag0", store=fakestore) flag0.unset() flag1 = BinaryFlag.create("flag1", store=fakestore) flag1.set() assert ~flag0 assert not ~flag1
def test_benchmark_api_get(benchmark, db, api): BinaryFlag.create( "flag0", label="Flag", description="Testing flag", tags="test", ) benchmark(api.get, "/flags/flag0", status=200)
def test_get_all_flags(self, fakestore): names = ["flag0", "flag1", "flag2"] for name in names: BinaryFlag.create(name, store=fakestore) allflags = BinaryFlag.all(store=fakestore) assert len(allflags) == len(names) for flag in allflags: assert flag.name in names
def test_flag_xor(self, fakestore): flag0 = BinaryFlag.create("flag0", store=fakestore) flag0.unset() flag1 = BinaryFlag.create("flag1", store=fakestore) flag1.set() assert not flag0 ^ flag0 assert flag0 ^ flag1 assert flag1 ^ flag0 assert not flag1 ^ flag1
def test_collection_get(self, api): names = ["flag0", "flag1", "flag42"] for name in names: BinaryFlag.create(name) response = api.get("/flags", status=200) assert len(response.json) == len(names) for item in response.json: assert item["name"] in names
def test_get(self, api): BinaryFlag.create( "flag0", label="Fake flag", description="Flag for testing purposes", tags="test,fake", ) response = api.get("/flags/flag0", status=200) assert response.json["name"] == "flag0"
def collection_post(self): """ Create a new flag. """ data = self.request.json_body try: name = data.pop("name") except KeyError: raise HTTPBadRequest() BinaryFlag.create(name, **data) return HTTPCreated()
def test_get_set_flags(self): flag0 = BinaryFlag.create("flag0") assert flag0.value is None flag0.value = True assert flag0 flag0.value = False assert not flag0
def fakeflag(fakestore): """ Fixture providing a flag stored in fake storage. It's generated anew for every test. """ return BinaryFlag.create("fakeflag", store=fakestore)
def test_flag_create(self, fakestore): flag = BinaryFlag.create( "flag0", store=fakestore, ) flag.set() assert flag
def collection_get(self): """ Get all flags in the system. """ # pylint: disable=no-self-use return [FlagSchema(flag).__dict__ for flag in BinaryFlag.all()]
def test_flag_inactive(self, fakestore): flag0 = BinaryFlag.create( "flag0", store=fakestore, used=datetime.datetime.now() - datetime.timedelta(days=8), ) assert flag0.active == FlagActive.INACTIVE
def test_flag_active(self, fakestore): flag0 = BinaryFlag.create( "flag0", store=fakestore, used=datetime.datetime.now(), ) assert flag0.active == FlagActive.ACTIVE
def test_patch(self, api): payload = { "value": True, } flag = BinaryFlag.create("flag0") api.patch_json("/flags/flag0", payload, status=204) assert flag
def test_benchmark_store(benchmark, db): flag = BinaryFlag.create("flag0") def store_flag(f): f.value = True benchmark(store_flag, flag) assert flag.value
def test_benchmark_load(benchmark, db): flag = BinaryFlag.create("flag0") flag.set() def load_flag(f): return f.value result = benchmark(load_flag, flag) assert result
def test_create_flags(self): flag0 = BinaryFlag.create( "flag0", value_binary=True, label="Test flag 0", description="Flag for the purposes of testing", tags="test,flag", ) assert flag0
def test_flag_info(self): want_info = { "name": "flag0", "label": "Fake flag", "description": "Flag for testing purposes", "tags": "test,fake", } flag0 = BinaryFlag.create(**want_info) assert flag0.info == want_info
def patch(self): """ Change a flag's value. If any other property is provided, abort. """ data = self.request.json_body if list(data.keys()) != ["value"]: raise HTTPBadRequest() name = self.request.matchdict["name"] value = data.pop("value") try: flag = BinaryFlag(name) flag.value = value except FlagDoesNotExist: raise HTTPNotFound() return HTTPNoContent()
def test_post(self, api): payload = { "name": "test_flag", "label": "Test flag", "description": "Flag for testing purposes", "tags": "test,flag,fake", } api.post_json("/flags", payload, status=201) flag = BinaryFlag("test_flag") assert flag.info == payload
def get(self): """ Get the full information for a given flag. """ name = self.request.matchdict["name"] try: flag = BinaryFlag(name) except FlagDoesNotExist: raise HTTPNotFound() return FlagSchema(flag).__dict__
def test_basic_info(self, fakestore): want_info = { "name": "flag0", "label": "", "description": "", "tags": "", } flag0 = BinaryFlag.create( name="flag0", store=fakestore, ) assert flag0.info == want_info
def test_benchmark_patch(benchmark, db, api): BinaryFlag.create("flag0") benchmark(api.patch_json, "/flags/flag0", {"value": True}, status=204)
def flag(db): """ Create a flag for the current feature under test, clean up when done. """ return BinaryFlag.create("flag0")
def test_flag_new(self, fakestore): flag0 = BinaryFlag.create("flag0", store=fakestore) assert flag0.active == FlagActive.NEW
def test_flag_raises_if_inexistent(self, fakestore): with pytest.raises(FlagDoesNotExist): BinaryFlag("flag42", store=fakestore)
def test_flag_exists(self): with pytest.raises(FlagDoesNotExist): BinaryFlag("flag0")
def test_flag_active(self): flag0 = BinaryFlag.create("flag0") flag0.set() assert flag0 assert flag0.active == FlagActive.ACTIVE
def test_flag_new(self): flag0 = BinaryFlag.create("flag0") assert flag0.active == FlagActive.NEW