def test_ordnance_survey_tile_styles(): """ Tests that setting the Ordnance Survey tile style works as expected. This is essentially just assures information is properly propagated through the class structure. """ dummy_apikey = "None" ref_url = ('https://api2.ordnancesurvey.co.uk/' 'mapping_api/v1/service/wmts?' 'key=None&height=256&width=256&tilematrixSet=EPSG%3A3857&' 'version=1.0.0&style=true&layer={layer}%203857&' 'SERVICE=WMTS&REQUEST=GetTile&format=image%2Fpng&' 'TileMatrix=EPSG%3A3857%3A{z}&TileRow={y}&TileCol={x}') tile = ["1", "2", "3"] # Default is Road. os = cimgt.OrdnanceSurvey(dummy_apikey) url = os._image_url(tile) assert url == ref_url.format(layer="Road", z=tile[2], y=tile[1], x=tile[0]) for layer in ['Outdoor', 'Light', 'Night', 'Leisure']: os = cimgt.OrdnanceSurvey(dummy_apikey, layer=layer) url = os._image_url(tile) assert url == ref_url.format(layer=layer, z=tile[2], y=tile[1], x=tile[0]) # Exception is raised if unknown style is passed. with pytest.raises(ValueError): cimgt.OrdnanceSurvey(dummy_apikey, layer="random_style")
def test_ordnance_survey_get_image(): # In order to test fetching map images from OS # an API key needs to be provided try: api_key = os.environ['ORDNANCE_SURVEY_API_KEY'] except KeyError: pytest.skip('ORDNANCE_SURVEY_API_KEY environment variable is unset.') os1 = cimgt.OrdnanceSurvey(api_key, layer="Outdoor") os2 = cimgt.OrdnanceSurvey(api_key, layer="Night") tile = (500, 300, 10) img1, extent1, _ = os1.get_image(tile) img2, extent2, _ = os2.get_image(tile) # Different images for different layers assert img1 != img2 # The extent is the same though assert extent1 == extent2