File: test_app_exceptions.py

package info (click to toggle)
pywps 4.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,016 kB
  • sloc: python: 8,846; xml: 723; makefile: 106
file content (32 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
##################################################################
# Copyright 2018 Open Source Geospatial Foundation and others    #
# licensed under MIT, Please consult LICENSE.txt for details     #
##################################################################

from basic import TestBase
from pywps.app.exceptions import format_message, ProcessError, DEFAULT_ALLOWED_CHARS


class AppExceptionsTest(TestBase):

    def test_format_message(self):
        assert format_message('no data available') == 'no data available'
        assert format_message(' no data available! ') == 'no data available!'
        assert format_message('no') == ''
        assert format_message('no data available', max_length=7) == 'no data'
        assert format_message('no &data% available') == 'no data available'
        assert format_message(DEFAULT_ALLOWED_CHARS) == DEFAULT_ALLOWED_CHARS

    def test_process_error(self):
        assert ProcessError(' no &data available!').message == 'no data available!'
        assert ProcessError('no', min_length=2).message == 'no'
        assert ProcessError('0 data available', max_length=6).message == '0 data'
        assert ProcessError('no data? not available!', allowed_chars='?').message == 'no data? not available'
        assert ProcessError('').message == 'Sorry, process failed. Please check server error log.'
        assert ProcessError(1234).message == 'Sorry, process failed. Please check server error log.'
        try:
            raise ProcessError('no data!!')
        except ProcessError as e:
            assert f"{e}" == 'no data!!'
        else:
            assert False