Ejemplo n.º 1
0
 def test_patch_400_extrafields(self, api):
     BinaryFlag.create("flag0")
     api.patch_json("/flags/flag0", {
         "value": True,
         "label": "Label",
     },
                    status=400)
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 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"
Ejemplo n.º 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()
Ejemplo n.º 9
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
Ejemplo n.º 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)
Ejemplo n.º 11
0
 def test_flag_create(self, fakestore):
     flag = BinaryFlag.create(
         "flag0",
         store=fakestore,
     )
     flag.set()
     assert flag
Ejemplo n.º 12
0
    def collection_get(self):
        """
        Get all flags in the system.
        """
        # pylint: disable=no-self-use

        return [FlagSchema(flag).__dict__ for flag in BinaryFlag.all()]
Ejemplo n.º 13
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
Ejemplo n.º 14
0
 def test_flag_active(self, fakestore):
     flag0 = BinaryFlag.create(
         "flag0",
         store=fakestore,
         used=datetime.datetime.now(),
     )
     assert flag0.active == FlagActive.ACTIVE
Ejemplo n.º 15
0
    def test_patch(self, api):
        payload = {
            "value": True,
        }
        flag = BinaryFlag.create("flag0")
        api.patch_json("/flags/flag0", payload, status=204)

        assert flag
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 19
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
Ejemplo n.º 20
0
    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()
Ejemplo n.º 21
0
    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
Ejemplo n.º 22
0
    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__
Ejemplo n.º 23
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
Ejemplo n.º 24
0
def test_benchmark_patch(benchmark, db, api):
    BinaryFlag.create("flag0")
    benchmark(api.patch_json, "/flags/flag0", {"value": True}, status=204)
Ejemplo n.º 25
0
def flag(db):
    """
    Create a flag for the current feature under test, clean up when done.
    """
    return BinaryFlag.create("flag0")
Ejemplo n.º 26
0
 def test_flag_new(self, fakestore):
     flag0 = BinaryFlag.create("flag0", store=fakestore)
     assert flag0.active == FlagActive.NEW
Ejemplo n.º 27
0
 def test_flag_raises_if_inexistent(self, fakestore):
     with pytest.raises(FlagDoesNotExist):
         BinaryFlag("flag42", store=fakestore)
Ejemplo n.º 28
0
 def test_flag_exists(self):
     with pytest.raises(FlagDoesNotExist):
         BinaryFlag("flag0")
Ejemplo n.º 29
0
 def test_flag_active(self):
     flag0 = BinaryFlag.create("flag0")
     flag0.set()
     assert flag0
     assert flag0.active == FlagActive.ACTIVE
Ejemplo n.º 30
0
 def test_flag_new(self):
     flag0 = BinaryFlag.create("flag0")
     assert flag0.active == FlagActive.NEW