Example #1
0
def test_get_plugin_config_api():
    with tempfile.TemporaryDirectory(prefix="/tmp/") as temp_dir_name:
        os.chmod(temp_dir_name, 0o755)
        s = "pds"
        with open(os.path.join(temp_dir_name, "index.json"), "w+") as f:
            f.write(json.dumps(s))

        try:
            apc = pc(temp_dir_name)
            plugin_config.add_plugin_configs([apc])
            ps = plugin_config.get_plugin_configs({"name": name})
            assert len(ps) == 1
            apc = ps[0]
            apc["_id"] = str(apc["_id"])

            resp = requests.put(f"{base_url}/admin/plugin/{name}/container", headers=headers)
            assert (resp.status_code == 200 or resp.status_code == 204)

            resp = requests.get(f"{base_url}/admin/plugin/{name}", headers=headers)

            assert resp.status_code == 200
            assert resp.json() == apc
        finally:
            api.delete_containers()
            plugin_config.delete_plugin_configs({})
Example #2
0
def test_get_plugin_containers_api():
    with tempfile.TemporaryDirectory(prefix="/tmp/") as temp_dir_name:
        os.chmod(temp_dir_name, 0o755)
        s = "pds"
        with open(os.path.join(temp_dir_name, "index.json"), "w+") as f:
            f.write(json.dumps(s))

        try:
            apc = pc(temp_dir_name)
            apc2 = pc2(temp_dir_name)
            plugin_config.add_plugin_configs([apc, apc2])
            ps = plugin_config.get_plugin_configs({})
            assert len(ps) == 2
            apc = ps[0]

            resp = requests.put(f"{base_url}/admin/container", headers=headers)
            assert (resp.status_code == 200 or resp.status_code == 204)

            resp = requests.get(f"{base_url}/admin/container", headers=headers)

            assert resp.status_code == 200
            assert bag_equal(resp.json(), [{"name": name, "container": {"status": "running"}}, {"name": name2, "container": {"status": "running"}}])
        finally:
            api.delete_containers()
            plugin_config.delete_plugin_configs({})
Example #3
0
def test_run_plugin_container_get_echo_405():

    try:
        apc = echo_pc
        plugin_config.add_plugin_configs([apc])
        container_name = apc["name"]
        ps = plugin_config.get_plugin_configs({"name": container_name})
        assert len(ps) == 1
        apc = ps[0]
        plugin.run_container(apc)
        
        time.sleep(CLIENT_DELAY)
        resp = requests.get(f"{base_url}/plugin/{container_name}/index.json?status=405")
        
        assert resp.status_code == 405
    finally:
        api.delete_containers()
        plugin_config.delete_plugin_configs({})
Example #4
0
def test_run_plugin_container_post_echo_405():
    s = "pds"
    
    try:
        apc = echo_pc
        plugin_config.add_plugin_configs([apc])
        container_name = apc["name"]
        ps = plugin_config.get_plugin_configs({"name": container_name})
        assert len(ps) == 1
        apc = ps[0]
        plugin.run_container(apc)
        
        time.sleep(CLIENT_DELAY)
        resp = requests.post(f"{base_url}/plugin/{container_name}/index.json?status=405", headers={"Content-Type": "application/json"}, json=s)

        assert resp.status_code == 405

    finally:
        api.delete_containers()
        plugin_config.delete_plugin_configs({})
Example #5
0
def test_run_plugin_container():
    with tempfile.TemporaryDirectory(prefix="/tmp/") as temp_dir_name:
        os.chmod(temp_dir_name, 0o755)
        s = "pds"
        with open(os.path.join(temp_dir_name, "index.json"), "w+") as f:
            f.write(json.dumps(s))

        try:
            apc = pc(temp_dir_name)
            plugin_config.add_plugin_configs([apc])
            ps = plugin_config.get_plugin_configs({"name": name})
            assert len(ps) == 1
            apc = ps[0]
            plugin.run_container(apc)
        
            resp = requests.get(f"{base_url}/plugin/{name}/index.json")
        
            assert resp.status_code == 200
            assert resp.json() == s
        finally:
            api.delete_containers()
            plugin_config.delete_plugin_configs({})