From 07009f07dcab11e28219da0ea01cb8f489ab7cef Mon Sep 17 00:00:00 2001 From: Wille Marcel Date: Mon, 16 Oct 2023 20:27:53 -0300 Subject: [PATCH] Update code that uses yaml and XML functions --- osmchadjango/changeset/tasks.py | 6 +++++- osmchadjango/changeset/tests/test_tasks.py | 6 +++--- osmchadjango/supervise/tests/test_views.py | 10 +++++----- osmchadjango/users/tests/test_management.py | 6 +++--- osmchadjango/users/tests/test_utils.py | 4 ++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/osmchadjango/changeset/tasks.py b/osmchadjango/changeset/tasks.py index 29d237e4..5959bb70 100644 --- a/osmchadjango/changeset/tasks.py +++ b/osmchadjango/changeset/tasks.py @@ -3,6 +3,10 @@ from os.path import join from urllib.parse import quote import yaml +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader from django.conf import settings @@ -74,7 +78,7 @@ def get_last_replication_id(): state = requests.get( '{}state.yaml'.format(settings.OSM_PLANET_BASE_URL) ).content - state = yaml.load(state) + state = yaml.load(state, Loader) return state.get('sequence') diff --git a/osmchadjango/changeset/tests/test_tasks.py b/osmchadjango/changeset/tests/test_tasks.py index fd392856..33c653c3 100644 --- a/osmchadjango/changeset/tests/test_tasks.py +++ b/osmchadjango/changeset/tests/test_tasks.py @@ -30,7 +30,7 @@ def test_creation(self): self.assertEqual(Changeset.objects.count(), 1) self.assertEqual( changeset.bbox.wkt, - 'POLYGON ((-34.9230192 -8.219786900000001, -34.855581 -8.219786900000001, -34.855581 -8.0335263, -34.9230192 -8.0335263, -34.9230192 -8.219786900000001))' + 'POLYGON ((-34.9230192 -8.2197869, -34.855581 -8.2197869, -34.855581 -8.0335263, -34.9230192 -8.0335263, -34.9230192 -8.2197869))' ) self.assertIsInstance(changeset.area, float) @@ -62,8 +62,8 @@ class TestCreateChangesetWithoutBBOX(TestCase): def test_creation(self): changeset = create_changeset(47052680) self.assertEqual(Changeset.objects.count(), 1) - self.assertIsNone(changeset.bbox) - self.assertEqual(changeset.area, None) + self.assertTrue(changeset.bbox.empty) + self.assertEqual(changeset.area, 0.0) class TestChangesetCommentAPI(TestCase): diff --git a/osmchadjango/supervise/tests/test_views.py b/osmchadjango/supervise/tests/test_views.py index 36b82151..6000c5cd 100644 --- a/osmchadjango/supervise/tests/test_views.py +++ b/osmchadjango/supervise/tests/test_views.py @@ -859,10 +859,10 @@ def test_aoi_changesets_feed_view(self): reverse('supervise:aoi-changesets-feed', args=[self.aoi.pk]) ) self.assertEqual(response.status_code, 200) - rss_data = ET.fromstring(response.content).getchildren()[0].getchildren() + rss_data = ET.fromstring(response.content)[0] title = [i for i in rss_data if i.tag == 'title'][0] items = [i for i in rss_data if i.tag == 'item'] - link = [i for i in items[0].getchildren() if i.tag == 'link'][0] + link = [i for i in items[0] if i.tag == 'link'][0] self.assertIn( "?aoi=", link.text @@ -893,7 +893,7 @@ def test_feed_view_of_unnamed_aoi_and_zero_changesets(self): reverse('supervise:aoi-changesets-feed', args=[self.aoi.pk]) ) self.assertEqual(response.status_code, 200) - rss_data = ET.fromstring(response.content).getchildren()[0].getchildren() + rss_data = ET.fromstring(response.content)[0] title = [i for i in rss_data if i.tag == 'title'][0] items = [i for i in rss_data if i.tag == 'item'] self.assertEqual( @@ -931,7 +931,7 @@ def test_feed_view_of_aoi_with_blacklist_filter(self): reverse('supervise:aoi-changesets-feed', args=[self.aoi.pk]) ) self.assertEqual(response.status_code, 200) - rss_data = ET.fromstring(response.content).getchildren()[0].getchildren() + rss_data = ET.fromstring(response.content)[0] title = [i for i in rss_data if i.tag == 'title'][0] items = [i for i in rss_data if i.tag == 'item'] self.assertEqual( @@ -961,7 +961,7 @@ def test_feed_view_of_aoi_with_hide_whitelist_filter(self): reverse('supervise:aoi-changesets-feed', args=[aoi.pk]) ) self.assertEqual(response.status_code, 200) - rss_data = ET.fromstring(response.content).getchildren()[0].getchildren() + rss_data = ET.fromstring(response.content)[0] title = [i for i in rss_data if i.tag == 'title'][0] items = [i for i in rss_data if i.tag == 'item'] self.assertEqual( diff --git a/osmchadjango/users/tests/test_management.py b/osmchadjango/users/tests/test_management.py index 19ba6c45..acee0858 100644 --- a/osmchadjango/users/tests/test_management.py +++ b/osmchadjango/users/tests/test_management.py @@ -13,7 +13,7 @@ class TestUpdateUserNameCommand(TestCase): def setUp(self): self.user = User.objects.create_user( - username='WilleMarcel', + username='rosrever', email='b@a.com', password='password' ) @@ -37,14 +37,14 @@ def test_command(self): call_command('update_user_names') self.user.refresh_from_db() self.user_2.refresh_from_db() - self.assertEqual(self.user.name, 'Wille Marcel') + self.assertEqual(self.user.name, 'rosrever') self.assertEqual(self.user_2.name, 'narceliodesa') class TestClearTokensCommand(TestCase): def setUp(self): self.user = User.objects.create_user( - username='WilleMarcel', + username='rosrever', email='b@a.com', password='password' ) diff --git a/osmchadjango/users/tests/test_utils.py b/osmchadjango/users/tests/test_utils.py index c6da0d27..9071ae35 100644 --- a/osmchadjango/users/tests/test_utils.py +++ b/osmchadjango/users/tests/test_utils.py @@ -12,7 +12,7 @@ class TestUpdateUserName(TestCase): def setUp(self): self.user = User.objects.create_user( - username='WilleMarcel', + username='rosrever', email='b@a.com', password='password' ) @@ -35,7 +35,7 @@ def setUp(self): def test_update_user_name(self): update_user_name(self.user) update_user_name(self.user_2) - self.assertEqual(self.user.name, 'Wille Marcel') + self.assertEqual(self.user.name, 'rosrever') self.assertEqual(self.user_2.name, 'narceliodesa') def test_user_with_wrong_uid(self):