def test_list_images(loop):
    response = [{
        "RepoTags": ["ubuntu:12.04", "ubuntu:precise", "ubuntu:latest"],
        "Id":
        "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c",
        "Created": 1365714795,
        "Size": 131506275,
        "VirtualSize": 131506275
    }, {
        "RepoTags": ["ubuntu:12.10", "ubuntu:quantal", "<none>:<none>"],
        "ParentId": "27cf784147099545",
        "Id":
        "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
        "Created": 1364102658,
        "Size": 24653,
        "VirtualSize": 180116135
    }]

    with asyncio_patch("gns3server.modules.docker.Docker.query",
                       return_value=response) as mock:
        images = loop.run_until_complete(asyncio. async (
            Docker.instance().list_images()))
        mock.assert_called_with("GET", "images/json", params={"all": 0})
    assert len(images) == 5
    assert {"image": "ubuntu:12.04"} in images
    assert {"image": "ubuntu:precise"} in images
    assert {"image": "ubuntu:latest"} in images
    assert {"image": "ubuntu:12.10"} in images
    assert {"image": "ubuntu:quantal"} in images
def test_list_images(loop):
    response = [
        {
            "RepoTags": [
                "ubuntu:12.04",
                "ubuntu:precise",
                "ubuntu:latest"
            ],
            "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c",
            "Created": 1365714795,
            "Size": 131506275,
            "VirtualSize": 131506275
        },
        {
            "RepoTags": [
                "ubuntu:12.10",
                "ubuntu:quantal",
                "<none>:<none>"
            ],
            "ParentId": "27cf784147099545",
            "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
            "Created": 1364102658,
            "Size": 24653,
            "VirtualSize": 180116135
        }
    ]

    with asyncio_patch("gns3server.modules.docker.Docker.query", return_value=response) as mock:
        images = loop.run_until_complete(asyncio.async(Docker.instance().list_images()))
        mock.assert_called_with("GET", "images/json", params={"all": 0})
    assert len(images) == 5
    assert {"image": "ubuntu:12.04"} in images
    assert {"image": "ubuntu:precise"} in images
    assert {"image": "ubuntu:latest"} in images
    assert {"image": "ubuntu:12.10"} in images
    assert {"image": "ubuntu:quantal"} in images
Exemple #3
0
def manager(port_manager):
    m = Docker.instance()
    m.port_manager = port_manager
    return m
Exemple #4
0
def manager(port_manager):
    m = Docker.instance()
    m.port_manager = port_manager
    return m
Exemple #5
0
def mock_connection():
    docker = Docker.instance()
    docker._connected = True
    docker._connector = MagicMock()
    yield
    Docker._instance = None