Skip to content

Commit

Permalink
Fix test for Django 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wlorenzetti committed Dec 31, 2024
1 parent 5e6de0a commit 7eec8bd
Show file tree
Hide file tree
Showing 8 changed files with 778 additions and 730 deletions.
1,390 changes: 725 additions & 665 deletions g3w-admin/editing/tests/data/editing_test_qgis334.qgs

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions g3w-admin/editing/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ def setUp(self):
So setUpTestData is changed in setUp calss method
'''


#Restore test database
self.reset_db_data()

call_command('loaddata', 'BaseLayer.json',
'--database=default', verbosity=0)
call_command('loaddata', 'G3WMapControls.json',
Expand Down
39 changes: 19 additions & 20 deletions g3w-admin/qplotly/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,55 +45,54 @@ def setUpClass(cls):

cls.client = APIClient()

@classmethod
def setUpTestData(cls):
# main project group
cls.project_group = CoreGroup(name='Group1', title='Group1', header_logo_img='',
def setUp(self):
# Main project group
self.project_group = CoreGroup(name='Group1', title='Group1', header_logo_img='',
srid=G3WSpatialRefSys.objects.get(auth_srid=4326))

cls.project_group.save()
self.project_group.save()

cls.project_group_3857 = CoreGroup(name='Group3857', title='Group3857', header_logo_img='',
self.project_group_3857 = CoreGroup(name='Group3857', title='Group3857', header_logo_img='',
srid=G3WSpatialRefSys.objects.get(auth_srid=3857))

cls.project_group_3857.save()
self.project_group_3857.save()

qgis_project_file = File(open('{}{}{}'.format(CURRENT_PATH, TEST_BASE_PATH, QGS_FILE), 'r', encoding='utf-8'))

# Replace name property with only file name without path to simulate UploadedFileWithId instance.
qgis_project_file.name = qgis_project_file.name.split('/')[-1]
cls.project = QgisProject(qgis_project_file)
cls.project.group = cls.project_group
cls.project.save()
self.project = QgisProject(qgis_project_file)
self.project.group = self.project_group
self.project.save()
qgis_project_file.close()

qgis_project_file_3857 = File(
open('{}{}{}'.format(CURRENT_PATH, TEST_BASE_PATH, QGS_FILE_3857), 'r', encoding='utf-8'))

# Replace name property with only file name without path to simulate UploadedFileWithId instance.
qgis_project_file_3857.name = qgis_project_file_3857.name.split('/')[-1]
cls.project_3857 = QgisProject(qgis_project_file_3857)
cls.project_3857.group = cls.project_group_3857
cls.project_3857.save()
self.project_3857 = QgisProject(qgis_project_file_3857)
self.project_3857.group = self.project_group_3857
self.project_3857.save()
qgis_project_file_3857.close()


file = File(open(f'{DATASOURCE_PATH}cities_scatter_plot_wrong_source_layer_id.xml', 'r'))
cls.wrong_settings_source_layer_id_xml = file.read()
self.wrong_settings_source_layer_id_xml = file.read()
file.close()

file = File(open(f'{DATASOURCE_PATH}countries_pie_plot_with_title.xml', 'r'))
cls.countries_plot_xml = file.read()
self.countries_plot_xml = file.read()
file.close()

file = File(open(f'{DATASOURCE_PATH}cities_histogram_plot.xml', 'r'))
cls.cities_histogram_plot_xml = file.read()
self.cities_histogram_plot_xml = file.read()
file.close()

@classmethod
def tearDownClass(cls):
cls.project.instance.delete()
super().tearDownClass()

def tearDown(self):
self.project.instance.delete()
super().tearDown()



Expand Down
28 changes: 13 additions & 15 deletions g3w-admin/qplotly/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,41 @@ def setUpClass(cls):

cls.client = APIClient()

@classmethod
def setUpTestData(cls):
def setUp(self):

cls.project_group = CoreGroup(name='Group1', title='Group1', header_logo_img='',
self.project_group = CoreGroup(name='Group1', title='Group1', header_logo_img='',
srid=G3WSpatialRefSys.objects.get(auth_srid=4326))

cls.project_group.save()
self.project_group.save()

qgis_project_file = File(open('{}{}{}'.format(CURRENT_PATH, TEST_BASE_PATH, QGS_FILE), 'r', encoding='utf-8'))

# Replace name property with only file name without path to simulate UploadedFileWithId instance.
qgis_project_file.name = qgis_project_file.name.split('/')[-1]
cls.project = QgisProject(qgis_project_file)
cls.project.group = cls.project_group
cls.project.save()
self.project = QgisProject(qgis_project_file)
self.project.group = self.project_group
self.project.save()
qgis_project_file.close()

file = File(open(f'{DATASOURCE_PATH}data_plotly_settings.xml', 'r'))
cls.histogram_countries_xml = file.read()
self.histogram_countries_xml = file.read()
file.close()

file = File(open(f'{DATASOURCE_PATH}cities_scatter_plot.xml', 'r'))
cls.scatter_cities_xml = file.read()
self.scatter_cities_xml = file.read()
file.close()

file = File(open(f'{DATASOURCE_PATH}wrong_data_plotly_settings.xml', 'r'))
cls.wrong_settings_xml = file.read()
self.wrong_settings_xml = file.read()
file.close()

file = File(open(f'{DATASOURCE_PATH}cities_scatter_plot_wrong_source_layer_id.xml', 'r'))
cls.wrong_settings_source_layer_id_xml = file.read()
self.wrong_settings_source_layer_id_xml = file.read()
file.close()

@classmethod
def tearDownClass(cls):
cls.project.instance.delete()
super().tearDownClass()
def tearDown(self):
self.project.instance.delete()
super().tearDown()

def test_widget(self):
"""Test QplotlyWidget model"""
Expand Down
17 changes: 8 additions & 9 deletions g3w-admin/qplotly/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,28 @@ def setUpClass(cls):

cls.client = Client()

@classmethod
def setUpTestData(cls):
def setUp(self):
# main project group
cls.project_group = CoreGroup(name='Group1', title='Group1', header_logo_img='',
self.project_group = CoreGroup(name='Group1', title='Group1', header_logo_img='',
srid=G3WSpatialRefSys.objects.get(auth_srid=4326))

cls.project_group.save()
self.project_group.save()

qgis_project_file = File(open('{}{}{}'.format(CURRENT_PATH, TEST_BASE_PATH, QGS_FILE), 'r', encoding='utf-8'))

# Replace name property with only file name without path to simulate UploadedFileWithId instance.
qgis_project_file.name = qgis_project_file.name.split('/')[-1]
cls.project = QgisProject(qgis_project_file)
cls.project.group = cls.project_group
cls.project.save()
self.project = QgisProject(qgis_project_file)
self.project.group = self.project_group
self.project.save()
qgis_project_file.close()

file = File(open(f'{DATASOURCE_PATH}countries_pie_plot_with_title.xml', 'r'))
cls.countries_plot_xml = file.read()
self.countries_plot_xml = file.read()
file.close()

file = File(open(f'{DATASOURCE_PATH}cities_histogram_plot.xml', 'r'))
cls.cities_histogram_plot_xml = file.read()
self.cities_histogram_plot_xml = file.read()
file.close()

def test_download_xml(self):
Expand Down
28 changes: 13 additions & 15 deletions g3w-admin/qtimeseries/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,36 @@ def setUpClass(cls):

cls.client = APIClient()

@classmethod
def setUpTestData(cls):
# main project group
cls.project_group = CoreGroup(name='Group1', title='Group1', header_logo_img='',
def setUp(self):
# Main project group
self.project_group = CoreGroup(name='Group1', title='Group1', header_logo_img='',
srid=G3WSpatialRefSys.objects.get(auth_srid=4326))

cls.project_group.save()
self.project_group.save()

qgis_project_file = File(open('{}{}{}'.format(CURRENT_PATH, TEST_BASE_PATH, QGS_FILE_RASTER), 'r',
encoding='utf-8'))

# Replace name property with only file name without path to simulate UploadedFileWithId instance.
qgis_project_file.name = qgis_project_file.name.split('/')[-1]
cls.project_raster = QgisProject(qgis_project_file)
cls.project_raster.group = cls.project_group
cls.project_raster.save()
self.project_raster = QgisProject(qgis_project_file)
self.project_raster.group = self.project_group
self.project_raster.save()
qgis_project_file.close()

qgis_project_file = File(open('{}{}{}'.format(CURRENT_PATH, TEST_BASE_PATH, QGS_FILE_RASTER_2), 'r',
encoding='utf-8'))

# Replace name property with only file name without path to simulate UploadedFileWithId instance.
qgis_project_file.name = qgis_project_file.name.split('/')[-1]
cls.project_raster_2 = QgisProject(qgis_project_file)
cls.project_raster_2.group = cls.project_group
cls.project_raster_2.save()
self.project_raster_2 = QgisProject(qgis_project_file)
self.project_raster_2.group = self.project_group
self.project_raster_2.save()
qgis_project_file.close()

@classmethod
def tearDownClass(cls):
cls.project_raster.instance.delete()
super().tearDownClass()
def tearDown(self):
self.project_raster.instance.delete()
super().tearDown()

def _testApiCall(self, view_name, args, kwargs={}, data=None, method='POST', username='admin01'):
"""Utility to make test calls for admin01 user"""
Expand Down
1 change: 0 additions & 1 deletion g3w-admin/usersmanage/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def test_list_users(self):

self.assertEqual(res.data['count'], 3)

print(res.data['results'])
self.assertEqual(res.data['results'][0], {
"id": 7,
"first_name": "",
Expand Down
1 change: 0 additions & 1 deletion g3w-admin/usersmanage/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def test_get_perms_by_user_backend(self):
self.test_editor2_3.userbackend.save()

def fake_receiver(sender, **kwargs):
print ('passa')
return [
'add_user'
]
Expand Down

0 comments on commit 7eec8bd

Please sign in to comment.