Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pywps/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pywps.inout import Format
from pywps.app.Common import Metadata

import re

import logging

Expand Down Expand Up @@ -72,7 +73,7 @@ class WpsTestResponse(BaseResponse):

def __init__(self, *args):
super(WpsTestResponse, self).__init__(*args)
if self.headers.get('Content-Type') == 'text/xml':
if re.match('text/xml(;\s*charset=.*)?', self.headers.get('Content-Type')):
self.xml = lxml.etree.fromstring(self.get_data())

def xpath(self, path):
Expand All @@ -95,7 +96,7 @@ def client_for(service):

def assert_response_accepted(resp):
assert resp.status_code == 200
assert resp.headers['Content-Type'] == 'text/xml'
assert re.match('text/xml(;\s*charset=.*)?', resp.headers['Content-Type'])
success = resp.xpath_text('/wps:ExecuteResponse'
'/wps:Status'
'/wps:ProcessAccepted')
Expand All @@ -105,7 +106,7 @@ def assert_response_accepted(resp):

def assert_process_started(resp):
assert resp.status_code == 200
assert resp.headers['Content-Type'] == 'text/xml'
assert re.match('text/xml(;\s*charset=.*)?', resp.headers['Content-Type'])
success = resp.xpath_text('/wps:ExecuteResponse'
'/wps:Status'
'ProcessStarted')
Expand All @@ -115,14 +116,14 @@ def assert_process_started(resp):

def assert_response_success(resp):
assert resp.status_code == 200
assert resp.headers['Content-Type'] == 'text/xml'
assert re.match('text/xml(;\s*charset=.*)?', resp.headers['Content-Type'])
success = resp.xpath('/wps:ExecuteResponse/wps:Status/wps:ProcessSucceeded')
assert len(success) == 1


def assert_process_exception(resp, code=None):
assert resp.status_code == 400
assert resp.headers['Content-Type'] == 'text/xml'
assert re.match('text/xml(;\s*charset=.*)?', resp.headers['Content-Type'])
elem = resp.xpath('/ows:ExceptionReport'
'/ows:Exception')
assert elem[0].attrib['exceptionCode'] == code
Expand Down
10 changes: 6 additions & 4 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pywps.tests import assert_pywps_version, client_for
import lxml.etree

import re

VERSION="1.0.0"
WPS, OWS = get_ElementMakerForVersion(VERSION)
xpath_ns = get_xpath_ns(VERSION)
Expand All @@ -23,28 +25,28 @@ def test_invalid_parameter_value(self):
exception_el = resp.xpath('/ows:ExceptionReport/ows:Exception')[0]
assert exception_el.attrib['exceptionCode'] == 'InvalidParameterValue'
assert resp.status_code == 400
assert resp.headers['Content-Type'] == 'text/xml'
assert re.match('text/xml(;\s*charset=.*)?', resp.headers['Content-Type'])
assert_pywps_version(resp)

def test_missing_parameter_value(self):
resp = self.client.get()
exception_el = resp.xpath('/ows:ExceptionReport/ows:Exception')[0]
assert exception_el.attrib['exceptionCode'] == 'MissingParameterValue'
assert resp.status_code == 400
assert resp.headers['Content-Type'] == 'text/xml'
assert re.match('text/xml(;\s*charset=.*)?', resp.headers['Content-Type'])

def test_missing_request(self):
resp = self.client.get("?service=wps")
exception_el = resp.xpath('/ows:ExceptionReport/ows:Exception/ows:ExceptionText')[0]
# should mention something about a request
assert 'request' in exception_el.text
assert resp.headers['Content-Type'] == 'text/xml'
assert re.match('text/xml(;\s*charset=.*)?', resp.headers['Content-Type'])

def test_bad_request(self):
resp = self.client.get("?service=wps&request=xyz")
exception_el = resp.xpath('/ows:ExceptionReport/ows:Exception')[0]
assert exception_el.attrib['exceptionCode'] == 'OperationNotSupported'
assert resp.headers['Content-Type'] == 'text/xml'
assert re.match('text/xml(;\s*charset=.*)?', resp.headers['Content-Type'])

def load_tests(loader=None, tests=None, pattern=None):
if not loader:
Expand Down