示例#1
0
def test_request_w_url():
    url = WMSMapRequest(url="http://localhost:8000/service?",
                        param={
                            "layers": "foo,bar"
                        }).complete_url
    assert_url_eq(
        url,
        "http://localhost:8000/service?layers=foo,bar&styles=&request=GetMap&service=WMS",
    )
    url = WMSMapRequest(url="http://localhost:8000/service",
                        param={
                            "layers": "foo,bar"
                        }).complete_url
    assert_url_eq(
        url,
        "http://localhost:8000/service?layers=foo,bar&styles=&request=GetMap&service=WMS",
    )
    url = WMSMapRequest(url="http://localhost:8000/service?map=foo",
                        param={
                            "layers": "foo,bar"
                        }).complete_url
    assert_url_eq(
        url,
        "http://localhost:8000/service?map=foo&layers=foo,bar&styles=&request=GetMap&service=WMS",
    )
示例#2
0
def test_request_w_url():
    url = WMSMapRequest(url='http://localhost:8000/service?',
                        param={
                            'layers': 'foo,bar'
                        }).complete_url
    assert_url_eq(
        url,
        'http://localhost:8000/service?layers=foo,bar&styles=&request=GetMap&service=WMS'
    )
    url = WMSMapRequest(url='http://localhost:8000/service',
                        param={
                            'layers': 'foo,bar'
                        }).complete_url
    assert_url_eq(
        url,
        'http://localhost:8000/service?layers=foo,bar&styles=&request=GetMap&service=WMS'
    )
    url = WMSMapRequest(url='http://localhost:8000/service?map=foo',
                        param={
                            'layers': 'foo,bar'
                        }).complete_url
    assert_url_eq(
        url,
        'http://localhost:8000/service?map=foo&layers=foo,bar&styles=&request=GetMap&service=WMS'
    )
示例#3
0
def test_maprequest_from_request():
    env = {
        'QUERY_STRING': 'layers=bar&bBOx=-90,-80,70.0,+80&format=image/png&'\
                        'WIdth=100&heIGHT=200&LAyerS=foo'
    }
    req = WMSMapRequest(param=Request(env).args)
    assert req.params.bbox == (-90.0, -80.0, 70.0, 80.0)
    assert req.params.layers == ['bar', 'foo']
    assert req.params.size == (100, 200)
示例#4
0
def test_maprequest_from_request():
    env = {
        "QUERY_STRING":
        "layers=bar&bBOx=-90,-80,70.0,+80&format=image/png&"
        "WIdth=100&heIGHT=200&LAyerS=foo"
    }
    req = WMSMapRequest(param=Request(env).args)
    assert req.params.bbox == (-90.0, -80.0, 70.0, 80.0)
    assert req.params.layers == ["bar", "foo"]
    assert req.params.size == (100, 200)
示例#5
0
    def test_exception(self):
        self.req['exceptions'] = 'blank'
        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(img.getpixel((0, 0)), 0)  #pallete image
        eq_(img.getpalette()[0:3], [255, 255, 255])
示例#6
0
    def test_exception(self):
        self.req.set('exceptions', 'inimage')
        self.req.set('transparent', 'true')

        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
示例#7
0
    def test_exception_w_bgcolor(self):
        self.req.set('exceptions', 'blank')
        self.req.set('bgcolor', '0xff00ff')

        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = BytesIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        assert img.getpixel((0, 0)) == 0  #pallete image
        assert img.getpalette()[0:3] == [255, 0, 255]
示例#8
0
    def test_exception_w_transparent(self):
        self.req.set('exceptions', 'blank')
        self.req.set('transparent', 'true')

        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        assert img.mode == 'P'
        img = img.convert('RGBA')
        eq_(img.getpixel((0, 0))[3], 0)
示例#9
0
    def test_exception_w_transparent(self):
        self.req.set('exceptions', 'inimage')
        self.req.set('transparent', 'true')

        req = WMSMapRequest(self.req)
        req_ex = RequestError('the exception message', request=req)

        response = req_ex.render()
        assert response.content_type == 'image/png'
        data = StringIO(response.data)
        assert is_png(data)
        img = Image.open(data)
        assert img.size == (150, 100)
        eq_(sorted([x for x in img.histogram() if x > 25]), [377, 14623])
        img = img.convert('RGBA')
        eq_(img.getpixel((0, 0))[3], 0)
示例#10
0
def test_non_mime_format():
    m = WMSMapRequest(param={'format': 'jpeg'})
    assert m.params.format == 'jpeg'
示例#11
0
def test_non_mime_format():
    m = WMSMapRequest(param={"format": "jpeg"})
    assert m.params.format == "jpeg"