diff --git a/geonode/tests/bdd/conftest.py b/geonode/tests/bdd/conftest.py index 3c3728e2597..5408e1f8ba5 100644 --- a/geonode/tests/bdd/conftest.py +++ b/geonode/tests/bdd/conftest.py @@ -20,7 +20,10 @@ import os # import sys -from urlparse import urlparse +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse import django import pytest diff --git a/geonode/tests/bdd/e2e/conftest.py b/geonode/tests/bdd/e2e/conftest.py index eba2475d05f..bfa38fc9396 100644 --- a/geonode/tests/bdd/e2e/conftest.py +++ b/geonode/tests/bdd/e2e/conftest.py @@ -20,7 +20,10 @@ import os import signal -from urlparse import urljoin +try: + from urllib.parse import urljoin +except ImportError: + from urlparse import urljoin import pytest # from geonode import settings as gn_settings diff --git a/geonode/tests/bdd/e2e/fixtures/browser.py b/geonode/tests/bdd/e2e/fixtures/browser.py index 79d09a36ee4..f199aa20e97 100644 --- a/geonode/tests/bdd/e2e/fixtures/browser.py +++ b/geonode/tests/bdd/e2e/fixtures/browser.py @@ -17,7 +17,10 @@ # along with this program. If not, see . # ######################################################################### -from urlparse import urljoin +try: + from urllib.parse import urljoin +except ImportError: + from urlparse import urljoin import pytest from geonode import settings diff --git a/geonode/tests/csw.py b/geonode/tests/csw.py index bf27e3faac9..2994cec9591 100644 --- a/geonode/tests/csw.py +++ b/geonode/tests/csw.py @@ -27,6 +27,7 @@ from lxml import etree from defusedxml import lxml as dlxml +from decimal import Decimal from django.conf import settings @@ -112,23 +113,23 @@ def test_csw_outputschema_dc(self): outputschema='http://www.opengis.net/cat/csw/2.0.2', esn='full') - record = csw.catalogue.records.values()[0] + record = list(csw.catalogue.records.values())[0] # test that the ISO title maps correctly in Dublin Core - self.assertEquals(record.title, 'San Andres Y Providencia Location') + self.assertEqual(record.title, "San Andres Y Providencia Location") # test that the ISO abstract maps correctly in Dublin Core - self.assertEquals(record.abstract, None) + self.assertEqual(record.abstract, None) # test for correct service link articulation for link in record.references: if check_ogc_backend(geoserver.BACKEND_PACKAGE): if link['scheme'] == 'OGC:WMS': - self.assertEquals(link['url'], '{}ows'.format(settings.GEOSERVER_PUBLIC_LOCATION)) + self.assertEqual(link['url'], "{}ows".format(settings.GEOSERVER_PUBLIC_LOCATION)) elif link['scheme'] == 'OGC:WFS': - self.assertEquals(link['url'], '{}ows'.format(settings.GEOSERVER_PUBLIC_LOCATION)) + self.assertEqual(link['url'], "{}ows".format(settings.GEOSERVER_PUBLIC_LOCATION)) elif link['scheme'] == 'OGC:WCS': - self.assertEquals(link['url'], '{}ows'.format(settings.GEOSERVER_PUBLIC_LOCATION)) + self.assertEqual(link['url'], "{}ows".format(settings.GEOSERVER_PUBLIC_LOCATION)) elif check_ogc_backend(qgis_server.BACKEND_PACKAGE): if link['scheme'] == 'OGC:WMS': self.assertEqual( @@ -155,20 +156,19 @@ def test_csw_outputschema_iso(self): outputschema='http://www.isotc211.org/2005/gmd', esn='full') - record = csw.catalogue.records.values()[0] + record = list(csw.catalogue.records.values())[0] # test that the ISO title maps correctly in Dublin Core - self.assertEquals(record.identification.title, 'San Andres Y Providencia Location') + self.assertEqual(record.identification.title, "San Andres Y Providencia Location") # test that the ISO abstract maps correctly in Dublin Core - self.assertEquals(record.identification.abstract, None) + self.assertEqual(record.identification.abstract, None) # test BBOX properties in Dublin Core - from decimal import Decimal - self.assertEquals(Decimal(record.identification.bbox.minx), Decimal('-81.8593555')) - self.assertEquals(Decimal(record.identification.bbox.miny), Decimal('12.1665322')) - self.assertEquals(Decimal(record.identification.bbox.maxx), Decimal('-81.356409')) - self.assertEquals(Decimal(record.identification.bbox.maxy), Decimal('13.396306')) + self.assertEqual(Decimal(record.identification.bbox.minx), Decimal('-81.8593555')) + self.assertEqual(Decimal(record.identification.bbox.miny), Decimal('12.1665322')) + self.assertEqual(Decimal(record.identification.bbox.maxx), Decimal('-81.356409')) + self.assertEqual(Decimal(record.identification.bbox.maxy), Decimal('13.396306')) # test for correct link articulation for link in record.distribution.online: @@ -214,18 +214,18 @@ def test_csw_outputschema_dc_bbox(self): outputschema='http://www.opengis.net/cat/csw/2.0.2', esn='full') - record = csw.catalogue.records.values()[0] + record = list(csw.catalogue.records.values())[0] # test CRS constructs in Dublin Core - self.assertEquals(record.bbox.crs.code, 4326) + self.assertEqual(record.bbox.crs.code, 4326) # test BBOX properties in Dublin Core from decimal import Decimal logger.debug([Decimal(record.bbox.minx), Decimal(record.bbox.miny), Decimal(record.bbox.maxx), Decimal(record.bbox.maxy)]) - self.assertEquals(Decimal(record.bbox.minx), Decimal('-81.859356')) - self.assertEquals(Decimal(record.bbox.miny), Decimal('12.166532')) - self.assertEquals(Decimal(record.bbox.maxx), Decimal('-81.356409')) - self.assertEquals(Decimal(record.bbox.maxy), Decimal('13.396306')) + self.assertEqual(Decimal(record.bbox.minx), Decimal('-81.859356')) + self.assertEqual(Decimal(record.bbox.miny), Decimal('12.166532')) + self.assertEqual(Decimal(record.bbox.maxx), Decimal('-81.356409')) + self.assertEqual(Decimal(record.bbox.maxy), Decimal('13.396306')) def test_csw_outputschema_fgdc(self): """Verify that GeoNode CSW can handle ISO metadata with FGDC outputSchema""" @@ -241,13 +241,13 @@ def test_csw_outputschema_fgdc(self): keywords=['san_andres_y_providencia_location'], outputschema='http://www.opengis.net/cat/csw/csdgm') - record = csw.catalogue.records.values()[0] + record = list(csw.catalogue.records.values())[0] # test that the ISO title maps correctly in FGDC - self.assertEquals(record.idinfo.citation.citeinfo['title'], 'San Andres Y Providencia Location') + self.assertEqual(record.idinfo.citation.citeinfo['title'], "San Andres Y Providencia Location") # test that the ISO abstract maps correctly in FGDC - self.assertEquals(record.idinfo.descript.abstract, None) + self.assertEqual(record.idinfo.descript.abstract, None) def test_csw_query_bbox(self): """Verify that GeoNode CSW can handle bbox queries""" @@ -255,7 +255,7 @@ def test_csw_query_bbox(self): csw = get_catalogue() csw.catalogue.getrecords(bbox=[-140, -70, 80, 70]) logger.debug(csw.catalogue.results) - self.assertEquals(csw.catalogue.results, {'matches': 7, 'nextrecord': 0, 'returned': 7}) + self.assertEqual(csw.catalogue.results, {'matches': 7, 'nextrecord': 0, 'returned': 7}) def test_csw_upload_fgdc(self): """Verify that GeoNode CSW can handle FGDC metadata upload""" @@ -280,48 +280,48 @@ def test_csw_upload_fgdc(self): record=md_doc) # test that FGDC document was successfully inserted - self.assertEquals(csw.catalogue.results['inserted'], 1) + self.assertEqual(csw.catalogue.results['inserted'], 1) # query against FGDC typename, output FGDC csw.catalogue.getrecords(typenames='fgdc:metadata') - self.assertEquals(csw.catalogue.results['matches'], 1) + self.assertEqual(csw.catalogue.results['matches'], 1) - record = csw.catalogue.records.values()[0] + record = list(csw.catalogue.records.values())[0] # test that the FGDC title maps correctly in DC - self.assertEquals(record.title, 'Census_Blockgroup_Pop_Housing') + self.assertEqual(record.title, "Census_Blockgroup_Pop_Housing") # test that the FGDC type maps correctly in DC - self.assertEquals(record.type, 'vector digital data') + self.assertEqual(record.type, "vector digital data") # test CRS constructs in Dublin Core - self.assertEquals(record.bbox.crs.code, 4326) + self.assertEqual(record.bbox.crs.code, 4326) # test BBOX properties in Dublin Core from decimal import Decimal - self.assertEquals(Decimal(record.bbox.minx), Decimal('-117.6')) - self.assertEquals(Decimal(record.bbox.miny), Decimal('32.53')) - self.assertEquals(Decimal(record.bbox.maxx), Decimal('-116.08')) - self.assertEquals(Decimal(record.bbox.maxy), Decimal('33.51')) + self.assertEqual(Decimal(record.bbox.minx), Decimal('-117.6')) + self.assertEqual(Decimal(record.bbox.miny), Decimal('32.53')) + self.assertEqual(Decimal(record.bbox.maxx), Decimal('-116.08')) + self.assertEqual(Decimal(record.bbox.maxy), Decimal('33.51')) # query against FGDC typename, return in ISO csw.catalogue.getrecords( typenames='fgdc:metadata', esn='brief', outputschema='http://www.isotc211.org/2005/gmd') - self.assertEquals(csw.catalogue.results['matches'], 1) + self.assertEqual(csw.catalogue.results['matches'], 1) - record = csw.catalogue.records.values()[0] + record = list(csw.catalogue.records.values())[0] # test that the FGDC title maps correctly in ISO - self.assertEquals(record.identification.title, 'Census_Blockgroup_Pop_Housing') + self.assertEqual(record.identification.title, "Census_Blockgroup_Pop_Housing") # cleanup and delete inserted FGDC metadata document csw.catalogue.transaction( ttype='delete', typename='fgdc:metadata', cql='fgdc:Title like "Census_Blockgroup_Pop_Housing"') - self.assertEquals(csw.catalogue.results['deleted'], 1) + self.assertEqual(csw.catalogue.results['deleted'], 1) def test_csw_bulk_upload(self): """Verify that GeoNode CSW can handle bulk upload of ISO and FGDC metadata""" diff --git a/geonode/tests/integration.py b/geonode/tests/integration.py index fb0662fd88e..0c048826b85 100644 --- a/geonode/tests/integration.py +++ b/geonode/tests/integration.py @@ -25,18 +25,22 @@ import os import json import datetime -import urllib2 +try: + from urllib.request import urlopen, Request + from urllib.parse import urljoin +except ImportError: + from urllib2 import urlopen, Request + from urlparse import urljoin # import base64 import time import logging -from StringIO import StringIO +from io import StringIO # import traceback import gisdata from decimal import Decimal from defusedxml import lxml as dlxml from lxml import etree -from urlparse import urljoin from django.conf import settings from django.test.utils import override_settings @@ -60,15 +64,26 @@ from geonode.layers.utils import ( upload, file_upload, + resolve_regions, ) +from geonode.layers.metadata import set_metadata from geonode.tests.utils import check_layer, get_web_page -from geonode.geoserver.helpers import cascading_delete, set_attributes_from_geoserver # FIXME(Ariel): Uncomment these when #1767 is fixed # from geonode.geoserver.helpers import get_time_info # from geonode.geoserver.helpers import get_wms # from geonode.geoserver.helpers import set_time_info from geonode.geoserver.signals import gs_catalog +from geonode.geoserver.helpers import ( + cascading_delete, + get_sld_for, + fixup_style, + set_layer_style, + get_store, + set_attributes_from_geoserver, + set_styles, + create_gs_thumbnail, +) from geonode.utils import check_ogc_backend from contextlib import closing @@ -184,18 +199,9 @@ def test_layer_upload(self): from requests.auth import HTTPBasicAuth r = requests.get(url + 'gwc/rest/seed/%s.json' % saved_layer.alternate, auth=HTTPBasicAuth(user, passwd)) - self.assertEquals(r.status_code, 200) + self.assertEqual(r.status_code, 200) o = json.loads(r.text) self.assertTrue('long-array-array' in o) - - from geonode.geoserver.helpers import (get_sld_for, - fixup_style, - set_layer_style, - get_store, - set_attributes_from_geoserver, - set_styles, - create_gs_thumbnail) - _log("0. ------------ %s " % saved_layer) self.assertIsNotNone(saved_layer) workspace, name = saved_layer.alternate.split(':') @@ -230,7 +236,7 @@ def test_layer_upload(self): saved_layer.set_default_permissions() url = reverse('layer_metadata', args=[saved_layer.service_typename]) resp = self.client.get(url) - self.assertEquals(resp.status_code, 200) + self.assertEqual(resp.status_code, 200) finally: # Clean up and completely delete the layer saved_layer.delete() @@ -413,8 +419,8 @@ def test_extension_not_implemented(self): """ sampletxt = os.path.join(gisdata.VECTOR_DATA, 'points_epsg2249_no_prj.dbf') - with self.\ - assertRaisesRegexp(Exception, "You are attempting to replace a vector layer with an unknown format."): + with self.assertRaisesRegex(Exception, "You are attempting to replace " + "a vector layer with an unknown format."): file_upload(sampletxt) @timeout_decorator.timeout(LOCAL_TIMEOUT) @@ -484,10 +490,6 @@ def test_layer_upload_metadata(self): (todoc.day, todoc.month, todoc.year), 'Expected specific date from uploaded layer XML metadata') - # Set - from geonode.layers.metadata import set_metadata - from geonode.layers.utils import resolve_regions - thelayer_metadata = os.path.join( gisdata.PROJECT_ROOT, 'both/good/sangis.org/Airport/Air_Runways.shp.xml') @@ -577,13 +579,9 @@ def test_layer_zip_upload_metadata(self): date.replace(tzinfo=timezone.get_current_timezone()) today = date.today() todoc = uploaded.date.today() - self.assertEquals((today.day, today.month, today.year), - (todoc.day, todoc.month, todoc.year), - 'Expected specific date from uploaded layer XML metadata') - - # Set - from geonode.layers.metadata import set_metadata - from geonode.layers.utils import resolve_regions + self.assertEqual((today.day, today.month, today.year), + (todoc.day, todoc.month, todoc.year), + "Expected specific date from uploaded layer XML metadata") thelayer_metadata = os.path.join( gisdata.PROJECT_ROOT, @@ -620,9 +618,9 @@ def test_layer_zip_upload_non_utf8(self): zip_dir(thelayer_path, thelayer_zip) if os.path.exists(thelayer_zip): uploaded = file_upload(thelayer_zip, overwrite=True, charset='windows-1258') - self.assertEquals(uploaded.title, 'Zhejiang Yangcan Yanyu') - self.assertEquals(len(uploaded.keyword_list()), 2) - self.assertEquals(uploaded.constraints_other, None) + self.assertEqual(uploaded.title, 'Zhejiang Yangcan Yanyu') + self.assertEqual(len(uploaded.keyword_list()), 2) + self.assertEqual(uploaded.constraints_other, None) finally: # Clean up and completely delete the layer if uploaded: @@ -643,9 +641,9 @@ def test_layer_zip_upload_non_utf8(self): zip_dir(thelayer_path, thelayer_zip) if os.path.exists(thelayer_zip): uploaded = file_upload(thelayer_zip, overwrite=True, charset='windows-1258') - self.assertEquals(uploaded.title, 'Ming Female 1') - self.assertEquals(len(uploaded.keyword_list()), 2) - self.assertEquals(uploaded.constraints_other, None) + self.assertEqual(uploaded.title, 'Ming Female 1') + self.assertEqual(len(uploaded.keyword_list()), 2) + self.assertEqual(uploaded.constraints_other, None) finally: # Clean up and completely delete the layer if uploaded: @@ -671,9 +669,9 @@ def test_layer_zip_with_spaces(self): zip_dir(thelayer_path, thelayer_zip) if os.path.exists(thelayer_zip): uploaded = file_upload(thelayer_zip, overwrite=True, charset='UTF-8') - self.assertEquals(uploaded.title, 'Unesco Global Geoparks') - self.assertEquals(len(uploaded.keyword_list()), 2) - self.assertEquals(uploaded.constraints_other, None) + self.assertEqual(uploaded.title, 'Unesco Global Geoparks') + self.assertEqual(len(uploaded.keyword_list()), 2) + self.assertEqual(uploaded.constraints_other, None) finally: # Clean up and completely delete the layer if uploaded: @@ -963,7 +961,7 @@ def test_empty_bbox(self): uploaded.set_default_permissions() self.client.login(username='norman', password='norman') resp = self.client.get(uploaded.get_absolute_url()) - self.assertEquals(resp.status_code, 200) + self.assertEqual(resp.status_code, 200) finally: # Clean up and completely delete the layers uploaded.delete() @@ -991,16 +989,16 @@ def test_layer_replace(self): 'layer_replace', args=[ raster_layer.service_typename]) response = self.client.get(raster_replace_url) - self.assertEquals(response.status_code, 200) - self.assertEquals(response.context['is_featuretype'], False) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['is_featuretype'], False) # test the program can determine the original layer in vector type vector_replace_url = reverse( 'layer_replace', args=[ vector_layer.service_typename]) response = self.client.get(vector_replace_url) - self.assertEquals(response.status_code, 200) - self.assertEquals(response.context['is_featuretype'], True) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['is_featuretype'], True) # test replace a vector with a raster post_permissions = { @@ -1018,9 +1016,9 @@ def test_layer_replace(self): response = self.client.post( vector_replace_url, post_data) # TODO: This should really return a 400 series error with the json dict - self.assertEquals(response.status_code, 400) + self.assertEqual(response.status_code, 400) response_dict = json.loads(response.content) - self.assertEquals(response_dict['success'], False) + self.assertEqual(response_dict['success'], False) # test replace a vector with a different vector new_vector_file = os.path.join( @@ -1047,8 +1045,8 @@ def test_layer_replace(self): response_dict['errors']: pass else: - self.assertEquals(response.status_code, 400) - self.assertEquals(response_dict['success'], False) + self.assertEqual(response.status_code, 400) + self.assertEqual(response_dict['success'], False) if check_ogc_backend(geoserver.BACKEND_PACKAGE): # test replace a vector with an updated version of the vector file @@ -1076,8 +1074,8 @@ def test_layer_replace(self): response_dict['errors']: pass else: - self.assertEquals(response.status_code, 200) - self.assertEquals(response_dict['success'], True) + self.assertEqual(response.status_code, 200) + self.assertEqual(response_dict['success'], True) # Get a Layer object for the newly created layer. new_vector_layer = Layer.objects.get(pk=vector_layer.pk) @@ -1195,8 +1193,8 @@ def test_unpublished(self): 'service=wms&version=1.3.0&request=GetCapabilities' url = urljoin(geoserver_base_url, get_capabilities_url) str_to_check = 'geonode:san_andres_y_providencia_highway' - request = urllib2.Request(url) - response = urllib2.urlopen(request) + request = Request(url) + response = urlopen(request) # by default the uploaded layer is published self.assertTrue(layer.is_published, True) @@ -1222,8 +1220,8 @@ def test_unpublished(self): self.assertEqual(layer.is_published, False) # check the layer is not in GetCapabilities - request = urllib2.Request(url) - response = urllib2.urlopen(request) + request = Request(url) + response = urlopen(request) # now test with published layer layer = Layer.objects.get(pk=layer.pk) @@ -1233,8 +1231,8 @@ def test_unpublished(self): # we need some time to have the service up and running time.sleep(20) - request = urllib2.Request(url) - response = urllib2.urlopen(request) + request = Request(url) + response = urlopen(request) self.assertTrue(any(str_to_check in s for s in response.readlines())) finally: # Clean up and completely delete the layer @@ -1298,7 +1296,7 @@ def test_map_thumbnail(self): thumbnail_url = map_obj.get_thumbnail_url() if check_ogc_backend(qgis_server.BACKEND_PACKAGE): - self.assertEquals(thumbnail_url, staticfiles.static(settings.MISSING_THUMBNAIL)) + self.assertEqual(thumbnail_url, staticfiles.static(settings.MISSING_THUMBNAIL)) finally: # Cleanup saved_layer.delete() @@ -1347,12 +1345,12 @@ def testPrintProxy(self): # check is accessible while logged in resp = self.client.get(url) - self.assertEquals(resp.status_code, 200) + self.assertEqual(resp.status_code, 200) # check is inaccessible when not logged in self.client.logout() resp = self.client.get(url) - self.assertEquals(resp.status_code, 302) + self.assertEqual(resp.status_code, 302) # STEP 2: Create a Map with that layer @@ -1390,7 +1388,7 @@ def testPrintProxy(self): # Test the layer is still inaccessible as non authenticated resp = self.client.get(url) - self.assertEquals(resp.status_code, 302) + self.assertEqual(resp.status_code, 302) finally: # Clean up and completely delete the layer saved_layer.delete() @@ -1433,11 +1431,11 @@ def test_set_attributes_from_geoserver(self): # tests if everything is synced properly for attribute in layer.attribute_set.all(): - self.assertEquals( + self.assertEqual( attribute.attribute_label, '%s_label' % attribute.attribute ) - self.assertEquals( + self.assertEqual( attribute.description, '%s_description' % attribute.attribute ) @@ -1447,10 +1445,10 @@ def test_set_attributes_from_geoserver(self): self.assertTrue(len(links) > 7) original_data_links = [ll for ll in links if 'original' == ll.link_type] - self.assertEquals(len(original_data_links), 1) + self.assertEqual(len(original_data_links), 1) resp = self.client.get(original_data_links[0].url) - self.assertEquals(resp.status_code, 200) + self.assertEqual(resp.status_code, 200) finally: # Clean up and completely delete the layers layer.delete() @@ -1521,9 +1519,9 @@ def test_capabilities(self): layernodes = rootdoc.findall('./[wms:Name]', namespaces) layernode = layernodes[0] - self.assertEquals(1, len(layernodes)) - self.assertEquals(layernode.find('wms:Name', namespaces).text, - '%s:%s' % ('geonode', layer1.name)) + self.assertEqual(1, len(layernodes)) + self.assertEqual(layernode.find('wms:Name', namespaces).text, + "geonode:{}".format(layer1.name)) # 1. test capabilities_user url = reverse('capabilities_user', args=[norman.username]) @@ -1533,7 +1531,7 @@ def test_capabilities(self): layernodes = rootdoc.findall('./[wms:Name]', namespaces) # norman has 2 layers - self.assertEquals(1, len(layernodes)) + self.assertEqual(1, len(layernodes)) # the norman two layers are named layer1 and layer2 count = 0 @@ -1542,7 +1540,7 @@ def test_capabilities(self): count += 1 elif layernode.find('wms:Name', namespaces).text == '%s:%s' % ('geonode', layer2.name): count += 1 - self.assertEquals(1, count) + self.assertEqual(1, count) # 2. test capabilities_category url = reverse('capabilities_category', args=[category.identifier]) @@ -1552,7 +1550,7 @@ def test_capabilities(self): layernodes = rootdoc.findall('./[wms:Name]', namespaces) # category is in two layers - self.assertEquals(1, len(layernodes)) + self.assertEqual(1, len(layernodes)) # the layers for category are named layer1 and layer3 count = 0 @@ -1561,7 +1559,7 @@ def test_capabilities(self): count += 1 elif layernode.find('wms:Name', namespaces).text == '%s:%s' % ('geonode', layer3.name): count += 1 - self.assertEquals(1, count) + self.assertEqual(1, count) # 3. test for a map # TODO diff --git a/geonode/tests/smoke.py b/geonode/tests/smoke.py index 785bd22d21c..07f137df0dd 100644 --- a/geonode/tests/smoke.py +++ b/geonode/tests/smoke.py @@ -56,32 +56,32 @@ def tearDown(self): def test_home_page(self): '''Test if the homepage renders.''' response = self.client.get(reverse('home')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_help_page(self): '''Test help page renders.''' response = self.client.get(reverse('help')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_developer_page(self): '''Test help page renders.''' response = self.client.get(reverse('help')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) # Layer Pages # def test_layer_page(self): 'Test if the data home page renders.' response = self.client.get(reverse('layer_browse')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) @on_ogc_backend(geoserver.BACKEND_PACKAGE) def test_layer_acls(self): 'Test if the data/acls endpoint renders.' response = self.client.get(reverse('layer_acls')) - self.failUnlessEqual(response.status_code, 401) + self.assertEqual(response.status_code, 401) # Maps Pages # @@ -89,13 +89,13 @@ def test_maps_page(self): '''Test Maps page renders.''' response = self.client.get(reverse('maps_browse')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_new_map_page(self): '''Test New Map page renders.''' response = self.client.get(reverse('new_map')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) # People Pages # @@ -103,30 +103,30 @@ def test_profile_list(self): '''Test the profiles page renders.''' response = self.client.get(reverse('profile_browse')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) @override_settings(USE_GEOSERVER=False) def test_profiles(self): '''Test that user profile pages render.''' response = self.client.get(reverse('profile_detail', args=['admin'])) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) response = self.client.get(reverse('profile_detail', args=['norman'])) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) response = self.client.get( reverse( 'profile_detail', args=['a.fancy.username.123'])) - self.failUnlessEqual(response.status_code, 404) + self.assertEqual(response.status_code, 404) def test_csw_endpoint(self): '''Test that the CSW endpoint is correctly configured.''' response = self.client.get(reverse('csw_global_dispatch')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) def test_opensearch_description(self): '''Test that the local OpenSearch endpoint is correctly configured.''' response = self.client.get(reverse('opensearch_dispatch')) - self.failUnlessEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) class GeoNodeUtilsTests(GeoNodeBaseTestSupport): diff --git a/geonode/tests/suite/runner.py b/geonode/tests/suite/runner.py index a7454222e0f..1831f4978f0 100644 --- a/geonode/tests/suite/runner.py +++ b/geonode/tests/suite/runner.py @@ -1,10 +1,12 @@ +from __future__ import print_function + import sys import time import logging import multiprocessing from multiprocessing import Process, Queue, Event -from Queue import Empty +from queue import Empty from twisted.scripts.trial import Options, _getSuite from twisted.trial.runner import TrialRunner @@ -140,7 +142,7 @@ def _run_tests(self, tests, **kwargs): result = self._tests_func(tests=group_tests, worker_index=None) results_queue.put((group, result), block=False) - for group, tests in tests.iteritems(): + for group, tests in tests.items(): tests_queue.put((group, tests), block=False) pending_tests[group] = tests @@ -284,12 +286,12 @@ def _tests_func(self, worker_index): raise '_tests_func not implements' def _print_result(self, result): - print >> sys.stderr, result.output + print(result.output, file=sys.stderr) def _exit(self, start_time, end_time, failure_count, error_count): time_difference = (end_time - start_time) - print >> sys.stderr, 'Total run time: %d seconds' % (time_difference) + print("Total run time: {} seconds".format(time_difference), file=sys.stderr) try: sys.exit(failure_count + error_count) except Exception: @@ -338,7 +340,7 @@ def _create_worker_pool(self, pool_size, target_func, worker_args): def log(self, string): if self.verbosity >= 3: - print string + print(string) class DjangoParallelTestSuiteRunner(ParallelTestSuiteRunner, @@ -446,7 +448,7 @@ def setup_databases_18(self, **kwargs): old_names = [] mirrors = [] for signature, (db_name, aliases) in self.dependency_ordered( - test_databases.items(), dependencies): + list(test_databases.items()), dependencies): connection = connections[aliases[0]] old_names.append((connection, db_name, True)) test_db_name = connection.creation.create_test_db( diff --git a/geonode/tests/utils.py b/geonode/tests/utils.py index 7dc74966958..6c8f21cdaf8 100644 --- a/geonode/tests/utils.py +++ b/geonode/tests/utils.py @@ -22,17 +22,37 @@ import os import copy -import json import base64 import pickle -import urllib -import urllib2 +import requests +try: + from urllib.parse import urlencode + from urllib.request import ( + urlopen, + build_opener, + install_opener, + HTTPCookieProcessor, + HTTPPasswordMgrWithDefaultRealm, + HTTPBasicAuthHandler, + ) + from urllib.error import HTTPError, URLError +except ImportError: + from urllib import urlencode + from urllib2 import ( + urlopen, + build_opener, + install_opener, + HTTPCookieProcessor, + HTTPError, + HTTPPasswordMgrWithDefaultRealm, + HTTPBasicAuthHandler, + URLError, + ) import logging import contextlib from bs4 import BeautifulSoup -from poster.streaminghttp import register_openers -from poster.encode import multipart_encode, MultipartParam +from requests_toolbelt.multipart.encoder import MultipartEncoder from django.core import mail from django.conf import settings @@ -67,19 +87,13 @@ def __init__(self, url, user, passwd, *args, **kwargs): self.passwd = passwd self.csrf_token = None self.response_cookies = None - self.opener = self._init_url_opener() + self.cookies = requests.cookies.RequestsCookieJar() self.u, _ = get_user_model().objects.get_or_create(username=self.user) self.u.is_active = True self.u.email = 'admin@geonode.org' self.u.set_password(self.passwd) self.u.save() - def _init_url_opener(self): - self.cookies = urllib2.HTTPCookieProcessor() - opener = register_openers() - opener.add_handler(self.cookies) # Add cookie handler - return opener - def _login(self, user, backend=None): from importlib import import_module from django.http import HttpRequest @@ -101,16 +115,15 @@ def make_request(self, path, data=None, url = path if path.startswith("http") else self.url + path if ajax: url += '&force_ajax=true' if '?' in url else '?force_ajax=true' - request = None # Create a fake request to store login details. _request = None _session_id = None if force_login: session_cookie = settings.SESSION_COOKIE_NAME - for cookie in self.cookies.cookiejar: + for cookie in self.cookies: if cookie.name == session_cookie: _session_id = cookie.value - self.response_cookies += "; %s=%s" % (session_cookie, _session_id) + self.response_cookies += "; {}={}".format(session_cookie, _session_id) # _request = self.force_login(self.u) # # Save the session values. @@ -122,45 +135,42 @@ def make_request(self, path, data=None, # cookie.value = _request.session.session_key # cookie.expires = None # self.cookies.cookiejar.set_cookie(cookie) - + headers = {} if data: - items = [] + fields = {} # wrap post parameters for name, value in data.items(): if isinstance(value, file): # add file - items.append(MultipartParam.from_file(name, value.name)) - else: - if name == 'csrfmiddlewaretoken' and _request and _request.META['CSRF_COOKIE']: - value = _request.META['CSRF_COOKIE'] - self.csrf_token = value - for cookie in self.cookies.cookiejar: - if cookie.name == 'csrftoken': - cookie.value = value - self.cookies.cookiejar.set_cookie(cookie) - items.append(MultipartParam(name, value)) - logger.debug(" MultipartParam: %s / %s: " % (name, value)) - datagen, headers = multipart_encode(items) - request = urllib2.Request(url, datagen, headers) - else: - request = urllib2.Request(url=url) + fields[name] = (value.name, value) + elif name == 'csrfmiddlewaretoken' and _request and _request.META['CSRF_COOKIE']: + value = _request.META['CSRF_COOKIE'] + self.csrf_token = value + for cookie in self.cookies: + if cookie.name == 'csrftoken': + cookie.value = value + self.cookies.set_cookie(cookie) + fields[name] = value + logger.debug(" MultipartParam: {} / {}: ".format(name, value)) + encoder = MultipartEncoder(fields=fields) + headers['Content-Type'] = encoder.content_type if self.csrf_token: - request.add_header('X-CSRFToken', self.csrf_token) + headers['X-CSRFToken'] = self.csrf_token if self.response_cookies: - request.add_header('cookie', self.response_cookies) + headers['cookie'] = self.response_cookies if ajax: - request.add_header('X_REQUESTED_WITH', 'XMLHttpRequest') + headers['X_REQUESTED_WITH'] = "XMLHttpRequest" - try: - return self.opener.open(request) - except urllib2.HTTPError as ex: - if not debug: - raise - logger.error('error in request to %s' % path) - logger.error(ex.reason) - logger.error(ex.read()) - raise + if data: + response = requests.post(url, data=encoder, headers=headers, cookies=self.cookies) + else: + response = requests.get(url, headers=headers, cookies=self.cookies) + + response.raise_for_status() + response.code = response.status_code + + return response def get(self, path, debug=True): return self.make_request(path, debug=debug) @@ -229,26 +239,32 @@ def upload_file(self, _file): data=params, ajax=True, force_login=True) - data = resp.read() try: - return resp, json.loads(data) + return resp, resp.json() except ValueError: logger.exception(ValueError( 'probably not json, status %s' % - resp.getcode(), - data)) - return resp, data + resp.status_code, + resp.content)) + return resp, resp.content def get_html(self, path, debug=True): """ Method that make a get request and passes the results to bs4 Takes a path and returns a tuple """ resp = self.get(path, debug) - return resp, BeautifulSoup(resp.read()) + return resp, BeautifulSoup(resp.content) def get_json(self, path): resp = self.get(path) - return resp, json.loads(resp.read()) + try: + return resp, resp.json() + except ValueError: + logger.exception(ValueError( + 'probably not json, status %s' % + resp.status_code, + resp.content)) + return resp, resp.content def get_csrf_token(self, last=False): """Get a csrf_token from the home page or read from the cookie jar @@ -256,7 +272,7 @@ def get_csrf_token(self, last=False): """ if not last: self.get('/') - csrf = [c for c in self.cookies.cookiejar if c.name == 'csrftoken'] + csrf = [c for c in self.cookies if c.name == 'csrftoken'] return csrf[0].value if csrf else None @@ -266,9 +282,9 @@ def get_web_page(url, username=None, password=None, login_url=None): if login_url: # Login via a form - cookies = urllib2.HTTPCookieProcessor() - opener = urllib2.build_opener(cookies) - urllib2.install_opener(opener) + cookies = HTTPCookieProcessor() + opener = build_opener(cookies) + install_opener(opener) opener.open(login_url) @@ -282,7 +298,7 @@ def get_web_page(url, username=None, password=None, login_url=None): this_is_the_login_form=True, csrfmiddlewaretoken=token, ) - encoded_params = urllib.urlencode(params) + encoded_params = urlencode(params) with contextlib.closing(opener.open(login_url, encoded_params)) as f: f.read() @@ -290,22 +306,22 @@ def get_web_page(url, username=None, password=None, login_url=None): # Login using basic auth # Create password manager - passman = urllib2.HTTPPasswordMgrWithDefaultRealm() + passman = HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, url, username, password) # create the handler - authhandler = urllib2.HTTPBasicAuthHandler(passman) - opener = urllib2.build_opener(authhandler) - urllib2.install_opener(opener) + authhandler = HTTPBasicAuthHandler(passman) + opener = build_opener(authhandler) + install_opener(opener) try: - pagehandle = urllib2.urlopen(url) - except urllib2.HTTPError as e: + pagehandle = urlopen(url) + except HTTPError as e: msg = ('The server couldn\'t fulfill the request. ' 'Error code: %s' % e.code) e.args = (msg,) raise - except urllib2.URLError as e: + except URLError as e: msg = 'Could not open URL "%s": %s' % (url, e) e.args = (msg,) raise @@ -370,7 +386,7 @@ def test_set_attributes_creates_attributes(self): set_attributes(_l, attribute_map) # 2 items in attribute_map should translate into 2 Attribute instances - self.assertEquals(_l.attributes.count(), len(expected_results)) + self.assertEqual(_l.attributes.count(), len(expected_results)) # The name and type should be set as provided by attribute map for a in _l.attributes: diff --git a/package/debian/control b/package/debian/control index 4d1f2e338d1..eadd768e540 100644 --- a/package/debian/control +++ b/package/debian/control @@ -11,7 +11,7 @@ Build-Depends: python-all-dev (>= 2.6.6-3), debhelper (>= 7.0.50~) Package: geonode Architecture: all -Depends: geoserver-geonode (= 2.14.0), apache2, libapache2-mod-wsgi, gdal-bin, libgeos-dev, gettext, postgresql-contrib, postgis, libpq-dev, zip, unzip, language-pack-en, libjpeg-dev, libpng-dev, libxslt1-dev, zlib1g-dev, libffi-dev, libssl-dev, python-setuptools (= 39.0.1-2), python-django, python-pip, python-celery, python-gdal, python-shapely (= 1.5.17-3), python-pyproj, libproj-dev, python-virtualenv, python-paver, python-elasticsearch (= 2.4.1-1), python-sqlalchemy, python-bs4, python-html5lib, python-webencodings, python-lxml, python-psycopg2, python-arcrest (= 10.3-1), python-dateutil, python-pil, python-httplib2, python-shapely (= 1.5.17-3), python-paver, python-gsconfig (= 1.0.10-1), python-gn-gsimporter (= 1.0.9-2), python-owslib (= 0.16.0-1), python-pycsw (= 2.2.0-1), python-decorator, python-timeout-decorator (= 0.4.0-1), python-six (= 1.10.0-1), python-django-allauth, python-django-bootstrap-form (= 3.4-1), python-django-forms-bootstrap (= 3.1.0-2), python-django-activity-stream (= 0.6.5-2), python-django-autocomplete-light (= 2.3.3-2), python-django-filters, python-django-ipware (= 2.1.0-1), python-django-jsonfield (= 1.0.1-2), python-django-jsonfield-compat (= 0.4.4+geonode-1), python-django-leaflet (= 0.23.0-2), python-django-multi-email-field (= 0.5.1-2), python-django-taggit, python-django-treebeard, python-django-mptt, python-django-guardian, python-django-tastypie, python-dj-database-url (= 0.4.2-1), python-pinax-notifications (= 4.1.0+geonode-1), python-backports.functools-lru-cache, python-boto3, python-constantly, python-django-geoexplorer (= 4.0.41-1), python-django-appconf, python-django-storages (= 1.6.5-2), python-django-floppyforms (= 1.7.0-2), python-django-invitations (= 1.9.2-2), python-django-bootstrap3-datetimepicker-2 (= 2.5.0+geonode-1), python-slugify, python-uwsgi (= 2.0.17-2), python-websocket-client (= 0.51.0-1), python-django-geonode-client, python-django-modeltranslation, python-geonode-user-messages (= 0.1.14-1), python-geonode-avatar (= 2.1.8-1), python-pinax-ratings (= 3.0.3), python-geonode-dialogos (= 1.2-1), python-geonode-oauth-toolkit (= 1.1.2rc0-1), python-geonode-announcements (= 1.0.13+geonode-1), python-oauthlib (= 2.1.0-1), python-itypes, python-uritemplate, python-jinja2 (= 2.10-1), python-inflection, python-pygments, python-openid, python-configparser, python-sqlalchemy, python-psutil, python-django-cors-headers, python-requests, python-django-downloadview, python-django-extra-views, python-django-polymorphic, python-django-basic-authentication-decorator (= 0.9-2), python-django-haystack, python-coverage, python-ply, python-pep8, python-poster, python-pyshp, python-antlr, python-dicttoxml, python-datautil, python-enum34, python-geographiclib, python-geopy, python-glob2, python-gunicorn, python-hyperlink, python-simplegeneric, python-scandir, python-pyasn1, python-twisted-bin, python-pyasn1-modules, python-ipython-genutils, python-incremental, python-wcwidth, python-ptyprocess, python-zope.interface, python-serial, python-pathlib2, python-pam, python-traitlets, python-automat, python-service-identity, python-prompt-toolkit, python-pexpect, python-twisted-core, python-pickleshare, python-ipython, python-pycountry, python-lxml, python-jwcrypto, python-jdcal, python-maxminddb, python-parse-type, python-pillow, python-pluggy, python-hamcrest, python-openssl, python-pycodestyle, python-xmljson (= 0.1.9-2), python-user-agents (= 1.1.0-2), python-twisted, python-typing, python-py, python-tqdm, python-traitlets, python-mock, python-mako, python-invoke, python-memcached (= 1.59-2), python-yaml, python-dj-pagination (= 2.3.2-2), python-ua-parser (= 0.8.0-4), python-humanfriendly, ${misc:Depends}, ${python:Depends} +Depends: geoserver-geonode (= 2.14.0), apache2, libapache2-mod-wsgi, gdal-bin, libgeos-dev, gettext, postgresql-contrib, postgis, libpq-dev, zip, unzip, language-pack-en, libjpeg-dev, libpng-dev, libxslt1-dev, zlib1g-dev, libffi-dev, libssl-dev, python-setuptools (= 39.0.1-2), python-django, python-pip, python-celery, python-gdal, python-shapely (= 1.5.17-3), python-pyproj, libproj-dev, python-virtualenv, python-paver, python-elasticsearch (= 2.4.1-1), python-sqlalchemy, python-bs4, python-html5lib, python-webencodings, python-lxml, python-psycopg2, python-arcrest (= 10.3-1), python-dateutil, python-pil, python-httplib2, python-shapely (= 1.5.17-3), python-paver, python-gsconfig (= 1.0.10-1), python-gn-gsimporter (= 1.0.9-2), python-owslib (= 0.16.0-1), python-pycsw (= 2.2.0-1), python-decorator, python-timeout-decorator (= 0.4.0-1), python-six (= 1.10.0-1), python-django-allauth, python-django-bootstrap-form (= 3.4-1), python-django-forms-bootstrap (= 3.1.0-2), python-django-activity-stream (= 0.6.5-2), python-django-autocomplete-light (= 2.3.3-2), python-django-filters, python-django-ipware (= 2.1.0-1), python-django-jsonfield (= 1.0.1-2), python-django-jsonfield-compat (= 0.4.4+geonode-1), python-django-leaflet (= 0.23.0-2), python-django-multi-email-field (= 0.5.1-2), python-django-taggit, python-django-treebeard, python-django-mptt, python-django-guardian, python-django-tastypie, python-dj-database-url (= 0.4.2-1), python-pinax-notifications (= 4.1.0+geonode-1), python-backports.functools-lru-cache, python-boto3, python-constantly, python-django-geoexplorer (= 4.0.41-1), python-django-appconf, python-django-storages (= 1.6.5-2), python-django-floppyforms (= 1.7.0-2), python-django-invitations (= 1.9.2-2), python-django-bootstrap3-datetimepicker-2 (= 2.5.0+geonode-1), python-slugify, python-uwsgi (= 2.0.17-2), python-websocket-client (= 0.51.0-1), python-django-geonode-client, python-django-modeltranslation, python-geonode-user-messages (= 0.1.14-1), python-geonode-avatar (= 2.1.8-1), python-pinax-ratings (= 3.0.3), python-geonode-dialogos (= 1.2-1), python-geonode-oauth-toolkit (= 1.1.2rc0-1), python-geonode-announcements (= 1.0.13+geonode-1), python-oauthlib (= 2.1.0-1), python-itypes, python-uritemplate, python-jinja2 (= 2.10-1), python-inflection, python-pygments, python-openid, python-configparser, python-sqlalchemy, python-psutil, python-django-cors-headers, python-requests, python-requests-toolbelt, python-django-downloadview, python-django-extra-views, python-django-polymorphic, python-django-basic-authentication-decorator (= 0.9-2), python-django-haystack, python-coverage, python-ply, python-pep8, python-pyshp, python-antlr, python-dicttoxml, python-datautil, python-enum34, python-geographiclib, python-geopy, python-glob2, python-gunicorn, python-hyperlink, python-simplegeneric, python-scandir, python-pyasn1, python-twisted-bin, python-pyasn1-modules, python-ipython-genutils, python-incremental, python-wcwidth, python-ptyprocess, python-zope.interface, python-serial, python-pathlib2, python-pam, python-traitlets, python-automat, python-service-identity, python-prompt-toolkit, python-pexpect, python-twisted-core, python-pickleshare, python-ipython, python-pycountry, python-lxml, python-jwcrypto, python-jdcal, python-maxminddb, python-parse-type, python-pillow, python-pluggy, python-hamcrest, python-openssl, python-pycodestyle, python-xmljson (= 0.1.9-2), python-user-agents (= 1.1.0-2), python-twisted, python-typing, python-py, python-tqdm, python-traitlets, python-mock, python-mako, python-invoke, python-memcached (= 1.59-2), python-yaml, python-dj-pagination (= 2.3.2-2), python-ua-parser (= 0.8.0-4), python-humanfriendly, ${misc:Depends}, ${python:Depends} Recommends: python-gisdata Description: Allows the creation, sharing, and collaborative use of geospatial data. At its core, the GeoNode has a stack based on GeoServer, pycsw, diff --git a/requirements.txt b/requirements.txt index 6ece8c3b0d8..7621a6813fe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -128,7 +128,7 @@ invoke==1.3.0 # tests coverage==4.5.4 parse-type==0.5.2 -poster~=0.8.1 +requests-toolbelt==0.9.1 flake8==3.7.9 pytest==4.6.6 pytest-bdd==3.2.1