def test_execute(): client = Docker.local_client() conf = { 'name': 'aio-1', 'image': 'gliderlabs/alpine:3.1', 'command': ['sleep', '60'] } with pytest.raises(NotFound): yield from client.containers.get('aio-1') container_id = yield from client.containers.create(**conf) assert container_id started = yield from client.containers.start(container_id) assert started # the real test starts now exec_id = yield from client.executors.create(container_id, cmd=[ 'echo', 'FOOBAR' ]) yield from client.executors.start(exec_id) results = yield from client.executors.inspect(exec_id) assert results['exit_code'] == 0, 'should been 0' # end of the test stoped = yield from client.containers.stop(container_id) assert stoped, 'Should be stoped' deleted = yield from client.containers.delete(container_id) assert deleted, 'Should be deleted'
def test_delete(): client = Docker.local_client() images = yield from client.images.items() for image in images: if '<none>:<none>' in image['repo_tags']: deleted = yield from client.images.delete(image['id'], force=True) assert deleted, 'cannot remove image'
def test_conflict(): client = Docker.local_client() conf = { 'name': 'aio-1', 'image': 'gliderlabs/alpine:3.1', 'command': ['sleep', '60'] } with pytest.raises(NotFound): yield from client.containers.get('aio-1') container_id = yield from client.containers.create(**conf) assert container_id data_1 = yield from client.containers.get('aio-1') data_2 = yield from client.containers.get(container_id) assert data_1 == data_2, 'Fetch by name or id must returns same data' assert data_1['id'] == container_id # Cannot create container with the same name with pytest.raises(ConflictError): yield from client.containers.create(**conf) c1 = containers = yield from client.containers.items(status='all') assert {'id': container_id} in containers, 'Must match by id' c2 = containers = yield from client.containers.items(status='running') assert {'id': container_id} not in containers, 'Must not be running' c3 = containers = yield from client.containers.items(status='exited') assert {'id': container_id} in containers, 'Must be exited' started = yield from client.containers.start(container_id) assert started started = yield from client.containers.start(container_id) assert not started # Cannot delete running container with pytest.raises(ConflictError): yield from client.containers.delete(container_id) stoped = yield from client.containers.stop(container_id) assert stoped, 'Should be stoped' stoped = yield from client.containers.stop(container_id) assert not stoped, 'Should be already stoped' deleted = yield from client.containers.delete(container_id) assert deleted, 'Should be deleted' deleted = yield from client.containers.delete(container_id) assert not deleted, 'Should be already deleted'
def test_pull(): client = Docker.local_client() ref = 'gliderlabs/alpine:2.6' pulled = yield from client.dockerhub.pull(ref) assert pulled, 'Should download gliderlabs/alpine:2.6' # is it present locally? image = yield from client.images.inspect(ref) assert image # start a new container with this image container_id = yield from client.containers.create(**{ 'name': 'aio-2', 'image': 'gliderlabs/alpine:2.6', 'command': ['sleep', '60'] }) assert container_id started = yield from client.containers.start(container_id) assert started pulled = yield from client.dockerhub.pull(ref) assert pulled, 'Should still download gliderlabs/alpine:2.6' with pytest.raises(ConflictError): destroyed = yield from client.images.delete(ref) assert not destroyed, 'Should not allow destroy' stoped = yield from client.containers.stop(container_id) assert stoped, 'Should stop container' removed = yield from client.containers.remove(container_id) assert removed, 'Should remove container' images = yield from client.images.items() assert {'repo_tag': ref} in images, 'Should be present' destroyed = yield from client.images.delete(ref, force=True) assert destroyed, 'Should be destroyed' images = yield from client.images.items() assert {'repo_tag': ref} not in images, 'Should be absent'
def test_search(): # TODO mock result client = Docker.local_client() info = yield from client.dockerhub.search('ubuntu') assert info[0].name == 'ubuntu'
def test_pull(): client = Docker.local_client() images = yield from client.images.items()
def test_info(): client = Docker.local_client() info = yield from client.info() assert 'containers' in info, 'must have containers key'
def test_ping(): client = Docker.local_client() assert (yield from client.ping())
def test_version(): client = Docker.local_client() version = yield from client.version() assert client.api.version <= version['api_version'], 'api versions should be equals'