From 6549f6cdaef2354e11dc8ed343f45aba36c7735f Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Wed, 23 Oct 2024 16:51:46 +0200 Subject: [PATCH] Replace assertEquals usage --- ureport/bots/tests.py | 74 +++++++++++++++++------------------ ureport/landingpages/tests.py | 42 ++++++++++---------- ureport/polls/tests.py | 18 ++++----- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/ureport/bots/tests.py b/ureport/bots/tests.py index 63a6c6c35..d9cf34335 100644 --- a/ureport/bots/tests.py +++ b/ureport/bots/tests.py @@ -13,8 +13,8 @@ def test_create_bot(self): self.login(self.admin) response = self.client.get(create_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(response.status_code, 200) - self.assertEquals(len(response.context["form"].fields), 12) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["form"].fields), 12) self.assertNotIn("org", response.context["form"].fields) post_data = dict() @@ -34,22 +34,22 @@ def test_create_bot(self): ) response = self.client.post(create_url, post_data, follow=True, SERVER_NAME="uganda.ureport.io") bot = Bot.objects.order_by("-pk")[0] - self.assertEquals(response.status_code, 200) - self.assertEquals(response.request["PATH_INFO"], reverse("bots.bot_list")) - self.assertEquals(bot.title, "WhatsApp") - self.assertEquals(bot.org, self.uganda) - self.assertEquals(bot.channel, "+12345") - self.assertEquals(bot.keyword, "join") - self.assertEquals(bot.facebook_deeplink, "https://example.com/12345") - self.assertEquals(bot.description, "The main channel") - self.assertEquals(bot.priority, 1) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.request["PATH_INFO"], reverse("bots.bot_list")) + self.assertEqual(bot.title, "WhatsApp") + self.assertEqual(bot.org, self.uganda) + self.assertEqual(bot.channel, "+12345") + self.assertEqual(bot.keyword, "join") + self.assertEqual(bot.facebook_deeplink, "https://example.com/12345") + self.assertEqual(bot.description, "The main channel") + self.assertEqual(bot.priority, 1) self.assertTrue(bot.featured) self.assertFalse(bot.landing_page_only) self.login(self.superuser) response = self.client.get(create_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(response.status_code, 200) - self.assertEquals(len(response.context["form"].fields), 12) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["form"].fields), 12) self.assertNotIn("org", response.context["form"].fields) post_data = dict( @@ -62,15 +62,15 @@ def test_create_bot(self): ) response = self.client.post(create_url, post_data, follow=True, SERVER_NAME="uganda.ureport.io") bot = Bot.objects.order_by("-pk")[0] - self.assertEquals(response.status_code, 200) - self.assertEquals(response.request["PATH_INFO"], reverse("bots.bot_list")) - self.assertEquals(bot.title, "Facebook") - self.assertEquals(bot.org, self.uganda) - self.assertEquals(bot.channel, "HereWeGo") - self.assertEquals(bot.keyword, "participate") - self.assertEquals(bot.facebook_deeplink, "https://example.com/herewego") - self.assertEquals(bot.description, "The Facebook channel") - self.assertEquals(bot.priority, 2) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.request["PATH_INFO"], reverse("bots.bot_list")) + self.assertEqual(bot.title, "Facebook") + self.assertEqual(bot.org, self.uganda) + self.assertEqual(bot.channel, "HereWeGo") + self.assertEqual(bot.keyword, "participate") + self.assertEqual(bot.facebook_deeplink, "https://example.com/herewego") + self.assertEqual(bot.description, "The Facebook channel") + self.assertEqual(bot.priority, 2) self.assertFalse(bot.featured) self.assertFalse(bot.landing_page_only) @@ -124,22 +124,22 @@ def test_list(self): self.login(self.admin) response = self.client.get(list_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(len(response.context["object_list"]), 2) + self.assertEqual(len(response.context["object_list"]), 2) self.assertNotIn(nigeria_wa_bot, response.context["object_list"]) self.assertIn(uganda_wa_bot, response.context["object_list"]) self.assertIn(uganda_fb_bot, response.context["object_list"]) response = self.client.get(list_url, SERVER_NAME="nigeria.ureport.io") - self.assertEquals(len(response.context["object_list"]), 1) + self.assertEqual(len(response.context["object_list"]), 1) self.assertNotIn(uganda_wa_bot, response.context["object_list"]) self.assertNotIn(uganda_wa_bot, response.context["object_list"]) self.assertIn(nigeria_wa_bot, response.context["object_list"]) - self.assertEquals(len(response.context["fields"]), 5) + self.assertEqual(len(response.context["fields"]), 5) self.login(self.superuser) response = self.client.get(list_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(len(response.context["fields"]), 5) - self.assertEquals(len(response.context["object_list"]), 2) + self.assertEqual(len(response.context["fields"]), 5) + self.assertEqual(len(response.context["object_list"]), 2) self.assertIn(uganda_wa_bot, response.context["object_list"]) self.assertIn(uganda_wa_bot, response.context["object_list"]) self.assertNotIn(nigeria_wa_bot, response.context["object_list"]) @@ -188,8 +188,8 @@ def test_bot_update(self): self.assertLoginRedirect(response) response = self.client.get(uganda_update_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(response.status_code, 200) - self.assertEquals(len(response.context["form"].fields), 13) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["form"].fields), 13) post_data = dict( is_active=True, @@ -203,14 +203,14 @@ def test_bot_update(self): priority=3, ) response = self.client.post(uganda_update_url, post_data, follow=True, SERVER_NAME="uganda.ureport.io") - self.assertEquals(response.request["PATH_INFO"], reverse("bots.bot_list")) + self.assertEqual(response.request["PATH_INFO"], reverse("bots.bot_list")) bot = Bot.objects.get(pk=uganda_fb_bot.pk) - self.assertEquals(bot.title, "WhatsApp") - self.assertEquals(bot.org, self.uganda) - self.assertEquals(bot.channel, "+12345") - self.assertEquals(bot.keyword, "join") - self.assertEquals(bot.facebook_deeplink, "https://example.com/12345") - self.assertEquals(bot.description, "The main channel") - self.assertEquals(bot.priority, 3) + self.assertEqual(bot.title, "WhatsApp") + self.assertEqual(bot.org, self.uganda) + self.assertEqual(bot.channel, "+12345") + self.assertEqual(bot.keyword, "join") + self.assertEqual(bot.facebook_deeplink, "https://example.com/12345") + self.assertEqual(bot.description, "The main channel") + self.assertEqual(bot.priority, 3) self.assertTrue(bot.featured) self.assertTrue(bot.landing_page_only) diff --git a/ureport/landingpages/tests.py b/ureport/landingpages/tests.py index 17c9bfeff..ae876a404 100644 --- a/ureport/landingpages/tests.py +++ b/ureport/landingpages/tests.py @@ -14,8 +14,8 @@ def test_create(self): self.login(self.admin) response = self.client.get(create_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(response.status_code, 200) - self.assertEquals(len(response.context["form"].fields), 7) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["form"].fields), 7) self.assertNotIn("org", response.context["form"].fields) post_data = dict() @@ -32,15 +32,15 @@ def test_create(self): response = self.client.post(create_url, post_data, follow=True, SERVER_NAME="uganda.ureport.io") landing_page = LandingPage.objects.order_by("-pk")[0] - self.assertEquals(response.status_code, 200) - self.assertEquals(response.request["PATH_INFO"], reverse("landingpages.landingpage_list")) - self.assertEquals(landing_page.title, "Welcome") - self.assertEquals(landing_page.slug, "lorem") + self.assertEqual(response.status_code, 200) + self.assertEqual(response.request["PATH_INFO"], reverse("landingpages.landingpage_list")) + self.assertEqual(landing_page.title, "Welcome") + self.assertEqual(landing_page.slug, "lorem") self.login(self.superuser) response = self.client.get(create_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(response.status_code, 200) - self.assertEquals(len(response.context["form"].fields), 7) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["form"].fields), 7) self.assertNotIn("org", response.context["form"].fields) post_data = dict( @@ -51,8 +51,8 @@ def test_create(self): response = self.client.post(create_url, post_data, follow=True, SERVER_NAME="uganda.ureport.io") landing_page = LandingPage.objects.order_by("-pk")[0] - self.assertEquals(landing_page.title, "Foo Bar") - self.assertEquals(landing_page.slug, "foo") + self.assertEqual(landing_page.title, "Foo Bar") + self.assertEqual(landing_page.slug, "foo") def test_list(self): uganda_foo_lp = LandingPage.objects.create( @@ -89,23 +89,23 @@ def test_list(self): self.login(self.admin) response = self.client.get(list_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(len(response.context["object_list"]), 2) + self.assertEqual(len(response.context["object_list"]), 2) self.assertNotIn(nigeria_foo_lp, response.context["object_list"]) self.assertIn(uganda_foo_lp, response.context["object_list"]) self.assertIn(uganda_bar_lp, response.context["object_list"]) response = self.client.get(list_url, SERVER_NAME="nigeria.ureport.io") - self.assertEquals(len(response.context["object_list"]), 1) + self.assertEqual(len(response.context["object_list"]), 1) self.assertNotIn(uganda_foo_lp, response.context["object_list"]) self.assertNotIn(uganda_bar_lp, response.context["object_list"]) self.assertIn(nigeria_foo_lp, response.context["object_list"]) - self.assertEquals(len(response.context["fields"]), 3) + self.assertEqual(len(response.context["fields"]), 3) self.login(self.superuser) response = self.client.get(list_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(len(response.context["fields"]), 3) - self.assertEquals(len(response.context["object_list"]), 2) + self.assertEqual(len(response.context["fields"]), 3) + self.assertEqual(len(response.context["object_list"]), 2) self.assertIn(uganda_foo_lp, response.context["object_list"]) self.assertIn(uganda_bar_lp, response.context["object_list"]) self.assertNotIn(nigeria_foo_lp, response.context["object_list"]) @@ -171,8 +171,8 @@ def test_bot_update(self): self.assertLoginRedirect(response) response = self.client.get(uganda_update_url, SERVER_NAME="uganda.ureport.io") - self.assertEquals(response.status_code, 200) - self.assertEquals(len(response.context["form"].fields), 8) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["form"].fields), 8) self.assertEqual( list(response.context["form"].fields["bots"].choices), [(uganda_fb_bot.pk, "Facebook Bot")], @@ -185,8 +185,8 @@ def test_bot_update(self): ) response = self.client.post(uganda_update_url, post_data, follow=True, SERVER_NAME="uganda.ureport.io") - self.assertEquals(response.request["PATH_INFO"], reverse("landingpages.landingpage_list")) + self.assertEqual(response.request["PATH_INFO"], reverse("landingpages.landingpage_list")) landing_page = LandingPage.objects.get(pk=uganda_foo_lp.pk) - self.assertEquals(landing_page.title, "Bar Bar") - self.assertEquals(landing_page.slug, "bar") - self.assertEquals(landing_page.content, "Phasellus id arcu quis urna faucibus eleifend.") + self.assertEqual(landing_page.title, "Bar Bar") + self.assertEqual(landing_page.slug, "bar") + self.assertEqual(landing_page.content, "Phasellus id arcu quis urna faucibus eleifend.") diff --git a/ureport/polls/tests.py b/ureport/polls/tests.py index 874ffb7bd..0abbee476 100644 --- a/ureport/polls/tests.py +++ b/ureport/polls/tests.py @@ -306,7 +306,7 @@ def test_get_flow(self): poll1 = self.create_poll(self.uganda, "Poll 1", "uuid-1", self.health_uganda, self.admin, featured=True) - self.assertEquals(poll1.get_flow(), "Flow") + self.assertEqual(poll1.get_flow(), "Flow") mock.assert_called_once_with(backend=poll1.backend) def test_runs(self): @@ -465,9 +465,9 @@ def test_create_poll(self): self.assertTrue(Poll.objects.all()) poll = Poll.objects.get() - self.assertEquals(poll.title, "Poll 1") - self.assertEquals(poll.backend.slug, "rapidpro") - self.assertEquals(poll.org, self.uganda) + self.assertEqual(poll.title, "Poll 1") + self.assertEqual(poll.backend.slug, "rapidpro") + self.assertEqual(poll.org, self.uganda) self.assertEqual(poll.tags.all().count(), 2) self.assertEqual(set(poll.tags.all().values_list("name", flat=True)), {"Books", "sports"}) @@ -562,8 +562,8 @@ def test_create_poll(self): self.assertIn("loc", response.context["form"].fields) self.assertIn("backend", response.context["form"].fields) - self.assertEquals(len(response.context["form"].fields["backend"].choices), 3) - self.assertEquals( + self.assertEqual(len(response.context["form"].fields["backend"].choices), 3) + self.assertEqual( set( [ (getattr(elt[0], "value", ""), elt[1]) @@ -1051,7 +1051,7 @@ def test_templatetags(self): mock.return_value = "Done" self.assertIsNone(config(None, "field_name")) - self.assertEquals(config(self.uganda, "field_name"), "Done") + self.assertEqual(config(self.uganda, "field_name"), "Done") mock.assert_called_with("field_name") self.assertIsNone(org_color(None, 1)) @@ -1456,12 +1456,12 @@ def test_poll_question_model(self): self.assertFalse(PollWordCloud.objects.all()) poll_question1.generate_word_cloud() self.assertTrue(PollWordCloud.objects.all()) - self.assertEquals(PollWordCloud.objects.all().count(), 1) + self.assertEqual(PollWordCloud.objects.all().count(), 1) # another run will keep the same DB object poll_question1.generate_word_cloud() self.assertTrue(PollWordCloud.objects.all()) - self.assertEquals(PollWordCloud.objects.all().count(), 1) + self.assertEqual(PollWordCloud.objects.all().count(), 1) results = poll_question1.calculate_results() result = results[0]