def test_request_invalid_response_not_cached(): test.web_server_poke('bad', {'status_code': 400, 'text': 'ORIGINAL'}) res = gws.lib.net.http_request(test.web_server_url('bad'), max_age=10) assert res.text == 'ORIGINAL' test.web_server_poke('bad', {'status_code': 400, 'text': 'UPDATED'}) res = gws.lib.net.http_request(test.web_server_url('ok'), max_age=10) assert res.text == 'UPDATED'
def test_request_redirect_ok(): test.web_server_poke('redirect', { 'status_code': 301, 'headers': { 'location': test.web_server_url('ok') } }) res = gws.lib.net.http_request(test.web_server_url('redirect')) assert (res.ok, res.status_code, res.text) == (True, 200, 'hello')
def test_request_valid_response_cached(): test.web_server_poke('ok', {'text': 'ORIGINAL'}) res = gws.lib.net.http_request(test.web_server_url('ok'), max_age=3) assert res.text == 'ORIGINAL' test.web_server_poke('ok', {'text': 'UPDATED'}) res = gws.lib.net.http_request(test.web_server_url('ok'), max_age=3) assert res.text == 'ORIGINAL' res = gws.lib.net.http_request(test.web_server_url('ok')) assert res.text == 'UPDATED'
def test_request_cache_expiration(): test.web_server_poke('ok', {'text': 'ORIGINAL'}) res = gws.lib.net.http_request(test.web_server_url('ok'), max_age=3) assert res.text == 'ORIGINAL' test.web_server_poke('ok', {'text': 'UPDATED'}) res = gws.lib.net.http_request(test.web_server_url('ok'), max_age=3) assert res.text == 'ORIGINAL' test.sleep(4) res = gws.lib.net.http_request(test.web_server_url('ok'), max_age=3) assert res.text == 'UPDATED'
def test_request_timeout(): test.web_server_poke('timeout', {'time': 2}) res = gws.lib.net.http_request(test.web_server_url('timeout'), timeout=1) assert (res.ok, res.status_code) == (False, 0) res = gws.lib.net.http_request(test.web_server_url('timeout'), timeout=5) assert (res.ok, res.status_code) == (True, 200)
def test_request_404(): res = gws.lib.net.http_request(test.web_server_url('NOT_FOUND')) assert (res.ok, res.status_code) == (False, 404)
def test_request_ok(): test.web_server_poke('ok', {'text': 'hello'}) res = gws.lib.net.http_request(test.web_server_url('ok')) assert (res.ok, res.status_code, res.text) == (True, 200, 'hello')
import gws.lib.test as test SERVICE_URL = test.web_server_url('XYZ') WMS_CONFIG = { 'url': SERVICE_URL, 'layers': [ { 'name': 'root', 'extent': [111, 222, 888, 999], }, { 'name': 'A', 'extent': [100, 200, 300, 400], 'parent': 'root', 'queryable': True, }, { 'name': 'A1', 'extent': [200, 300, 400, 500], 'parent': 'A', 'queryable': True, }, { 'name': 'B', 'extent': [300, 400, 500, 600], 'parent': 'root', }, { 'name': 'B1', 'extent': [400, 500, 600, 700],