コード例 #1
0
class TestFind(object):
    @pytest.fixture
    def client(self):
        with mock.patch.object(Example, "_client") as m:
            yield m

    def test_find_by_name(self, client):
        Example.find("app_name")
        client.get.assert_called_once_with(
            "/example", params={"labelSelector": "app=app_name"})

    @pytest.mark.parametrize("value, selector", (
        (Equality("my_value"), "my_key=my_value"),
        (Inequality("my_value"), "my_key!=my_value"),
        (In(("value1", "value2")), "my_key in (value1,value2)"),
        (NotIn(("value1", "value2")), "my_key notin (value1,value2)"),
        (Exists(), "my_key"),
        ("my_unwrapped_value", "my_key=my_unwrapped_value"),
    ))
    def test_find_by_selectors(self, client, value, selector):
        Example.find(labels={"my_key": value})
        client.get.assert_called_once_with("/example",
                                           params={"labelSelector": selector})

    def test_repeated_keys_in_label_selector(self, client):
        labels = [("foo", Inequality("bar")), ("foo", Exists())]
        Example.find(labels=labels)

        expected_selector = "foo!=bar,foo"

        client.get.assert_called_once_with(
            "/example", params={"labelSelector": expected_selector})
コード例 #2
0
    def test_repeated_keys_in_label_selector(self, client):
        labels = [("foo", Inequality("bar")), ("foo", Exists())]
        Example.find(labels=labels)

        expected_selector = "foo!=bar,foo"

        client.get.assert_called_once_with(
            "/example", params={"labelSelector": expected_selector})
コード例 #3
0
 def delete(self, app_spec):
     LOG.info("Deleting ingresses for %s", app_spec.name)
     try:
         Ingress.delete_list(namespace=app_spec.namespace,
                             labels={
                                 "app": Equality(app_spec.name),
                                 "fiaas/deployment_id": Exists()
                             })
     except NotFound:
         pass
コード例 #4
0
 def _delete_unused(self, app_spec, labels):
     filter_labels = [("app", Equality(labels["app"])),
                      ("fiaas/deployment_id", Exists()),
                      ("fiaas/deployment_id",
                       Inequality(labels["fiaas/deployment_id"]))]
     Ingress.delete_list(namespace=app_spec.namespace, labels=filter_labels)