Beispiel #1
0
def test_get_proxy_404(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=404)
        assert k.get() is None
Beispiel #2
0
def test_get_proxy_404(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=404)
        assert k.get() is None
Beispiel #3
0
def test_get_proxy_500_raise(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=500)
        with pytest.raises(requests.exceptions.HTTPError):
            k.get()
Beispiel #4
0
def test_get_proxy_500_raise(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=500)
        with pytest.raises(requests.exceptions.HTTPError):
            k.get()
Beispiel #5
0
def test_get_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response)
        assert json.dumps(k.get()) == json.dumps(json.loads(response))
Beispiel #6
0
def test_get_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response)
        assert json.dumps(k.get()) == json.dumps(json.loads(response))
Beispiel #7
0
def test_create_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s" % (proxy, svc_resource['endpoint'][1:-1])
    url2 = "%s/%s" % (k.proxy.geturl(), k.endpoint)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.post(url, text=response)
        m.get(url + "/" + svc_resource['name'], status_code=404)
        assert k.create() == "created"
Beispiel #8
0
def test_create_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s" % (proxy, svc_resource['endpoint'][1:-1])
    url2 = "%s/%s" % (k.proxy.geturl(), k.endpoint)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.post(url, text=response)
        m.get(url + "/" + svc_resource['name'], status_code=404)
        assert k.create() == "created"
Beispiel #9
0
def test_wait(svc_resource, monkeypatch):
    import time
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, [{'status_code': 404}, {'text': response, 'status_code': 200}])
        assert json.dumps(k.wait()) == json.dumps(json.loads(response))
        assert m.call_count == 2
Beispiel #10
0
def test_wait(svc_resource, monkeypatch):
    import time
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, [{'status_code': 404}, {'text': response, 'status_code': 200}])
        assert json.dumps(k.wait()) == json.dumps(json.loads(response))
        assert m.call_count == 2
Beispiel #11
0
def test_get_svc(subcall_get_assert, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert json.dumps(k.get()) == json.dumps(
        json.loads(get_response(k.name, k.kind)))
Beispiel #12
0
def test_get_ns(subcall_get_assert, ns_resource):
    k = Kubernetes(body=ns_resource['body'], namespace="testns")
    assert json.dumps(k.get()) == json.dumps(
        json.loads(get_response(k.name, k.kind)))
Beispiel #13
0
def test_get_ns(subcall_get_assert, ns_resource):
    k = Kubernetes(body=ns_resource['body'], namespace="testns")
    assert json.dumps(k.get()) == json.dumps(json.loads(get_response(k.name, k.kind)))
Beispiel #14
0
def test_get_svc(subcall_get_assert, svc_resource):
    k = Kubernetes(body=svc_resource['body'])
    assert json.dumps(k.get()) == json.dumps(json.loads(get_response(k.name, k.kind)))