# Path: tests/common.py
# def get_output(doc):
#     """Copied from pywps/tests/test_execute.py.
#     TODO: make this helper method public in pywps."""
#     output = {}
#     for output_el in xpath_ns(doc, '/wps:ExecuteResponse'
#                                    '/wps:ProcessOutputs/wps:Output'):
#         [identifier_el] = xpath_ns(output_el, './ows:Identifier')
# 
#         lit_el = xpath_ns(output_el, './wps:Data/wps:LiteralData')
#         if lit_el != []:
#             output[identifier_el.text] = lit_el[0].text
# 
#         ref_el = xpath_ns(output_el, './wps:Reference')
#         if ref_el != []:
#             output[identifier_el.text] = ref_el[0].attrib['href']
# 
#         data_el = xpath_ns(output_el, './wps:Data/wps:ComplexData')
#         if data_el != []:
#             output[identifier_el.text] = data_el[0].text
# 
#     return output
# 
# Path: flyingpigeon/processes/wps_say_hello.py
# class SayHello(Process):
#     """A nice process saying 'hello'."""
#     def __init__(self):
#         inputs = [
#             LiteralInput('name', 'Your name',
#                          abstract='Please enter your name.',
#                          keywords=['name', 'firstname'],
#                          data_type='string')]
#         outputs = [
#             LiteralOutput('output', 'Output response',
#                           abstract='A friendly Hello from us.',
#                           keywords=['output', 'result', 'response'],
#                           data_type='string')]
# 
#         super(SayHello, self).__init__(
#             self._handler,
#             identifier='hello',
#             title='Say Hello',
#             abstract='Just says a friendly Hello.'
#                      'Returns a literal string output with Hello plus the inputed name.',
#             keywords=['hello', 'demo'],
#             metadata=[
#                 Metadata('User Guide', 'https://emu.readthedocs.io/en/latest/processes.html'),  # noqa
#                 Metadata('PyWPS Demo', 'https://pywps-demo.readthedocs.io/en/latest/'),
#             ],
#             version='1.5',
#             inputs=inputs,
#             outputs=outputs,
#             store_supported=True,
#             status_supported=True
#         )
# 
#     @staticmethod
#     def _handler(request, response):
#         LOGGER.info("say hello")
#         response.outputs['output'].data = 'Hello ' + request.inputs['name'][0].data
#         response.outputs['output'].uom = UOM('unity')
#         return response


from pywps import Service
from pywps.tests import client_for, assert_response_success
from .common import get_output
from flyingpigeon.processes.wps_say_hello import SayHello



def test_wps_hello():
    client = client_for(Service(processes=[SayHello()]))
    datainputs = "name=Flying Pigeon"
    resp = client.get(
        "?service=WPS&request=Execute&version=1.0.0&identifier=hello&datainputs={}".format(
            datainputs))

# Path: tests/common.py
# def get_output(doc):
#     """Copied from pywps/tests/test_execute.py.
#     TODO: make this helper method public in pywps."""
#     output = {}
#     for output_el in xpath_ns(doc, '/wps:ExecuteResponse'
#                                    '/wps:ProcessOutputs/wps:Output'):
#         [identifier_el] = xpath_ns(output_el, './ows:Identifier')
# 
#         lit_el = xpath_ns(output_el, './wps:Data/wps:LiteralData')
#         if lit_el != []:
#             output[identifier_el.text] = lit_el[0].text
# 
#         ref_el = xpath_ns(output_el, './wps:Reference')
#         if ref_el != []:
#             output[identifier_el.text] = ref_el[0].attrib['href']
# 
#         data_el = xpath_ns(output_el, './wps:Data/wps:ComplexData')
#         if data_el != []:
#             output[identifier_el.text] = data_el[0].text
# 
#     return output
# 
# Path: flyingpigeon/processes/wps_say_hello.py
# class SayHello(Process):
#     """A nice process saying 'hello'."""
#     def __init__(self):
#         inputs = [
#             LiteralInput('name', 'Your name',
#                          abstract='Please enter your name.',
#                          keywords=['name', 'firstname'],
#                          data_type='string')]
#         outputs = [
#             LiteralOutput('output', 'Output response',
#                           abstract='A friendly Hello from us.',
#                           keywords=['output', 'result', 'response'],
#                           data_type='string')]
# 
#         super(SayHello, self).__init__(
#             self._handler,
#             identifier='hello',
#             title='Say Hello',
#             abstract='Just says a friendly Hello.'
#                      'Returns a literal string output with Hello plus the inputed name.',
#             keywords=['hello', 'demo'],
#             metadata=[
#                 Metadata('User Guide', 'https://emu.readthedocs.io/en/latest/processes.html'),  # noqa
#                 Metadata('PyWPS Demo', 'https://pywps-demo.readthedocs.io/en/latest/'),
#             ],
#             version='1.5',
#             inputs=inputs,
#             outputs=outputs,
#             store_supported=True,
#             status_supported=True
#         )
# 
#     @staticmethod
#     def _handler(request, response):
#         LOGGER.info("say hello")
#         response.outputs['output'].data = 'Hello ' + request.inputs['name'][0].data
#         response.outputs['output'].uom = UOM('unity')
#         return response


# Path: tests/test_wps_hello.py
from pywps import Service
from pywps.tests import client_for, assert_response_success
from .common import get_output
from flyingpigeon.processes.wps_say_hello import SayHello




def test_wps_hello():
    client = client_for(Service(processes=[SayHello()]))
    datainputs = "name=Flying Pigeon"
    resp = client.get(
        "?service=WPS&request=Execute&version=1.0.0&identifier=hello&datainputs={}".format(
            datainputs))

    assert_response_success(resp)