Beispiel #1
0
 def test_patch_400_extrafields(self, api):
     BinaryFlag.create("flag0")
     api.patch_json("/flags/flag0", {
         "value": True,
         "label": "Label",
     },
                    status=400)
Beispiel #2
0
 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
Beispiel #3
0
    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
Beispiel #4
0
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)
Beispiel #5
0
    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
Beispiel #6
0
 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
Beispiel #7
0
    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"
Beispiel #8
0
    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()
Beispiel #9
0
 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
Beispiel #10
0
def fakeflag(fakestore):
    """
    Fixture providing a flag stored in fake storage.
    It's generated anew for every test.
    """

    return BinaryFlag.create("fakeflag", store=fakestore)
Beispiel #11
0
 def test_flag_active(self, fakestore):
     flag0 = BinaryFlag.create(
         "flag0",
         store=fakestore,
         used=datetime.datetime.now(),
     )
     assert flag0.active == FlagActive.ACTIVE
Beispiel #12
0
 def test_flag_create(self, fakestore):
     flag = BinaryFlag.create(
         "flag0",
         store=fakestore,
     )
     flag.set()
     assert flag
Beispiel #13
0
 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
Beispiel #14
0
    def test_patch(self, api):
        payload = {
            "value": True,
        }
        flag = BinaryFlag.create("flag0")
        api.patch_json("/flags/flag0", payload, status=204)

        assert flag
Beispiel #15
0
def test_benchmark_store(benchmark, db):
    flag = BinaryFlag.create("flag0")

    def store_flag(f):
        f.value = True

    benchmark(store_flag, flag)
    assert flag.value
Beispiel #16
0
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
Beispiel #17
0
 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
Beispiel #18
0
 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
Beispiel #19
0
 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
Beispiel #20
0
 def test_flag_new(self, fakestore):
     flag0 = BinaryFlag.create("flag0", store=fakestore)
     assert flag0.active == FlagActive.NEW
Beispiel #21
0
def test_benchmark_patch(benchmark, db, api):
    BinaryFlag.create("flag0")
    benchmark(api.patch_json, "/flags/flag0", {"value": True}, status=204)
Beispiel #22
0
 def test_patch_400_novalue(self, api):
     BinaryFlag.create("flag0")
     api.patch_json("/flags/flag0", {}, status=400)
Beispiel #23
0
 def create_flag():
     name = str(uuid.uuid4())
     BinaryFlag.create(name)
     return name
Beispiel #24
0
def flag(db):
    """
    Create a flag for the current feature under test, clean up when done.
    """
    return BinaryFlag.create("flag0")
Beispiel #25
0
 def test_flag_active(self):
     flag0 = BinaryFlag.create("flag0")
     flag0.set()
     assert flag0
     assert flag0.active == FlagActive.ACTIVE
Beispiel #26
0
 def test_flag_new(self):
     flag0 = BinaryFlag.create("flag0")
     assert flag0.active == FlagActive.NEW
Beispiel #27
0
def test_benchmark_api_get_all(benchmark, db, api):
    for k in range(100):
        BinaryFlag.create("flag{}".format(k))
    benchmark(api.get, "/flags", status=200)