# Path: tests/conftest.py
# def splitName(name):
#     if ':' in name:
#         imageAndTag = name.split(':')
#     else:
#         imageAndTag = name.split('@')
#     return imageAndTag[0], imageAndTag[1]


import pytest
import docker
import json
from girder_jobs.constants import JobStatus
from pytest_girder.assertions import assertStatus
from pytest_girder.utils import getResponseBody
from .conftest import splitName
    # loads an image and attempts to run an arbitrary xml endpoint

    img_name = 'girder/slicer_cli_web:small'
    images.addImage(img_name, JobStatus.SUCCESS)
    images.imageIsLoaded(img_name, True)

    name, tag = splitName(img_name)
    data = images.getEndpoint()
    for tag in data.values():
        for cli in tag.values():
            for info in cli.values():
                route = info['xmlspec']
                resp = server.request(
                    path=route,
                    user=admin,
                    isJson=False)
                assertStatus(resp, 200)
                xmlString = getResponseBody(resp)
                # TODO validate with xml schema
                assert xmlString != ''
    images.deleteImage(img_name, True, )


@pytest.mark.plugin('slicer_cli_web')
def testEndpointDeletion(images, server, admin):
    img_name = 'girder/slicer_cli_web:small'
    images.addImage(img_name, JobStatus.SUCCESS)
    images.imageIsLoaded(img_name, True)
    data = images.getEndpoint()
    images.deleteImage(img_name, True)

# Path: tests/conftest.py
# def splitName(name):
#     if ':' in name:
#         imageAndTag = name.split(':')
#     else:
#         imageAndTag = name.split('@')
#     return imageAndTag[0], imageAndTag[1]


# Path: tests/test_docker.py
import pytest
import docker
import json
from girder_jobs.constants import JobStatus
from pytest_girder.assertions import assertStatus
from pytest_girder.utils import getResponseBody
from .conftest import splitName

    # loads an image and attempts to run an arbitrary xml endpoint

    img_name = 'girder/slicer_cli_web:small'
    images.addImage(img_name, JobStatus.SUCCESS)
    images.imageIsLoaded(img_name, True)

    name, tag = splitName(img_name)
    data = images.getEndpoint()
    for tag in data.values():
        for cli in tag.values():
            for info in cli.values():
                route = info['xmlspec']
                resp = server.request(
                    path=route,
                    user=admin,
                    isJson=False)
                assertStatus(resp, 200)
                xmlString = getResponseBody(resp)
                # TODO validate with xml schema
                assert xmlString != ''
    images.deleteImage(img_name, True, )


@pytest.mark.plugin('slicer_cli_web')
def testEndpointDeletion(images, server, admin):
    img_name = 'girder/slicer_cli_web:small'
    images.addImage(img_name, JobStatus.SUCCESS)
    images.imageIsLoaded(img_name, True)
    data = images.getEndpoint()
    images.deleteImage(img_name, True)

    name, tag = splitName(img_name)