Skip to content

Commit

Permalink
Refactor for compliance with PEP8-naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Schilling committed Feb 19, 2025
1 parent 5dcbac3 commit 142c75f
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 75 deletions.
4 changes: 2 additions & 2 deletions src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Meta:
# XXX: enabling this requires the tests/mocks to be updated. exercise left to the
# reader.
@classproperty
def oidcdb_check_idp_availability(cls):
def oidcdb_check_idp_availability(cls): # noqa: N805
return False

@property
Expand All @@ -89,7 +89,7 @@ class Meta:
# XXX: enabling this requires the tests/mocks to be updated. exercise left to the
# reader.
@classproperty
def oidcdb_check_idp_availability(cls):
def oidcdb_check_idp_availability(cls): # noqa: N805
return False

@property
Expand Down
6 changes: 3 additions & 3 deletions src/open_inwoner/accounts/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import requests_mock
from django_webtest import WebTest
from furl import furl
from pyquery import PyQuery as PQ
from pyquery import PyQuery

from open_inwoner.accounts.choices import NotificationChannelChoice
from open_inwoner.accounts.signals import KvKClient, update_user_on_login
Expand Down Expand Up @@ -2008,7 +2008,7 @@ def test_password_change_form_done_custom_template_is_rendered(self):
def test_password_change_button_is_rendered_with_default_login_type(self):
response = self.app.get(reverse("profile:detail"), user=self.user)

doc = PQ(response.content)
doc = PyQuery(response.content)
link = doc.find("[aria-label='Wachtwoord']")[0]
self.assertTrue(doc(link).is_("a"))

Expand All @@ -2018,7 +2018,7 @@ def test_password_change_button_is_not_rendered_with_digid_login_type(self):
)
response = self.app.get(reverse("profile:detail"), user=digid_user)

doc = PQ(response.content)
doc = PyQuery(response.content)
links = doc.find("[aria-label='Wachtwoord']")
self.assertEqual(len(links), 0)

Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/accounts/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class DeleteContactInvitationsTest(AssertTimelineLogMixin, TestCase):
@freeze_time("2023-09-26", as_arg=True)
def test_delete_expired_invitations(frozen_time, self):
def test_delete_expired_invitations(frozen_time, self): # noqa: N805
user = UserFactory(
first_name="Johann Maria Salvadore",
infix="van de",
Expand Down
16 changes: 8 additions & 8 deletions src/open_inwoner/accounts/tests/test_oidc_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django_webtest import DjangoTestApp, DjangoWebtestResponse, WebTest
from furl import furl
from mozilla_django_oidc_db.models import OpenIDConnectConfig
from pyquery import PyQuery as PQ
from pyquery import PyQuery

from open_inwoner.accounts.views.auth_oidc import (
GENERIC_DIGID_ERROR_MSG,
Expand Down Expand Up @@ -48,7 +48,7 @@ def perform_oidc_login(

login_response = app.get(login_url)

doc = PQ(login_response.content)
doc = PyQuery(login_response.content)
login_link = doc.find(f".link--{login_type}")
init_url = login_link.attr("href")

Expand Down Expand Up @@ -817,7 +817,7 @@ def test_login_error_message_mapped_in_config(
)

login_response = self.client.get(error_response.url)
doc = PQ(login_response.content)
doc = PyQuery(login_response.content)
error_msg = doc.find(".notification__content").text()

self.assertEqual(error_msg, "Je hebt het inloggen met DigiD geannuleerd.")
Expand Down Expand Up @@ -874,7 +874,7 @@ def test_login_error_message_not_mapped_in_config(
)

login_response = self.client.get(error_response.url)
doc = PQ(login_response.content)
doc = PyQuery(login_response.content)
error_msg = doc.find(".notification__content").text()

self.assertEqual(error_msg, str(GENERIC_DIGID_ERROR_MSG))
Expand Down Expand Up @@ -927,7 +927,7 @@ def test_login_validation_error(
)

login_response = self.client.get(error_response.url)
doc = PQ(login_response.content)
doc = PyQuery(login_response.content)
error_msg = doc.find(".notification__content").text()

self.assertEqual(error_msg, str(GENERIC_DIGID_ERROR_MSG))
Expand Down Expand Up @@ -1438,7 +1438,7 @@ def test_login_error_message_mapped_in_config(
)

login_response = self.client.get(error_response.url)
doc = PQ(login_response.content)
doc = PyQuery(login_response.content)
error_msg = doc.find(".notification__content").text()

self.assertEqual(error_msg, "Je hebt het inloggen met eHerkenning geannuleerd.")
Expand Down Expand Up @@ -1497,7 +1497,7 @@ def test_login_error_message_not_mapped_in_config(
)

login_response = self.client.get(error_response.url)
doc = PQ(login_response.content)
doc = PyQuery(login_response.content)
error_msg = doc.find(".notification__content").text()

self.assertEqual(error_msg, str(GENERIC_EHERKENNING_ERROR_MSG))
Expand Down Expand Up @@ -1557,7 +1557,7 @@ def test_login_validation_error(
)

login_response = self.client.get(error_response.url)
doc = PQ(login_response.content)
doc = PyQuery(login_response.content)
error_msg = doc.find(".notification__content").text()

self.assertEqual(error_msg, str(GENERIC_EHERKENNING_ERROR_MSG))
Expand Down
50 changes: 28 additions & 22 deletions src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import requests_mock
from django_webtest import WebTest
from freezegun import freeze_time
from pyquery import PyQuery as PQ
from pyquery import PyQuery
from webtest import Upload

from open_inwoner.accounts.choices import NotificationChannelChoice, StatusChoices
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_user_information_profile_page(self, m):
self.assertNotContains(response, "Bedrijfsgegevens")

# check notification preferences displayed
doc = PQ(response.content)
doc = PyQuery(response.content)

notifications_text = doc.find("#profile-notifications")[0].text_content()
self.assertIn("Mijn Berichten", notifications_text)
Expand All @@ -171,7 +171,7 @@ def test_admin_disable_options(self, m):

response = self.app.get(self.url, user=self.user)

doc = PQ(response.content)
doc = PyQuery(response.content)

self.assertEqual(doc.find("#profile-notifications"), [])

Expand Down Expand Up @@ -250,7 +250,7 @@ def test_info_eherkenning_user(self):
self.assertContains(response, "Fantasiestraat 42")
self.assertContains(response, "1234 XY The good place")

doc = PQ(response.content)
doc = PyQuery(response.content)

business_section = doc.find("#business-overview")[0]
self.assertEqual(business_section.text.strip(), "Bedrijfsgegevens")
Expand Down Expand Up @@ -1332,13 +1332,13 @@ def test_save_form_with_errors(self, m):
)

self.assertEqual(
PQ(subscribe_error).text(),
PyQuery(subscribe_error).text(),
_(
"Something went wrong while trying to subscribe to '{list_name}', please try again later"
).format(list_name="Nieuwsbrief2"),
)
self.assertEqual(
PQ(unsubscribe_error).text(),
PyQuery(unsubscribe_error).text(),
_(
"Something went wrong while trying to unsubscribe from '{list_name}', please try again later"
).format(list_name="Nieuwsbrief1"),
Expand Down Expand Up @@ -1495,30 +1495,36 @@ def test_render_list_if_appointments_are_found(self, m):

self.assertNotIn("Old appointment", response.text)

self.assertEqual(PQ(cards[0]).find(".card__heading-2").text(), "Paspoort")
self.assertEqual(PyQuery(cards[0]).find(".card__heading-2").text(), "Paspoort")

passport_appointment = PQ(cards[0]).find("ul").children()
passport_appointment = PyQuery(cards[0]).find("ul").children()

self.assertEqual(PQ(passport_appointment[0]).text(), "Datum\n1 januari 2020")
self.assertEqual(PQ(passport_appointment[1]).text(), "Tijd\n13:00 uur")
self.assertEqual(PQ(passport_appointment[2]).text(), "Locatie\nHoofdkantoor")
self.assertEqual(PQ(passport_appointment[3]).text(), "Dam 1")
self.assertEqual(PQ(passport_appointment[4]).text(), "1234 ZZ Amsterdam")
self.assertEqual(
PQ(cards[0]).find("a").attr("href"),
PyQuery(passport_appointment[0]).text(), "Datum\n1 januari 2020"
)
self.assertEqual(PyQuery(passport_appointment[1]).text(), "Tijd\n13:00 uur")
self.assertEqual(
PyQuery(passport_appointment[2]).text(), "Locatie\nHoofdkantoor"
)
self.assertEqual(PyQuery(passport_appointment[3]).text(), "Dam 1")
self.assertEqual(PyQuery(passport_appointment[4]).text(), "1234 ZZ Amsterdam")
self.assertEqual(
PyQuery(cards[0]).find("a").attr("href"),
f"{self.data.config.booking_base_url}{self.data.appointment_passport.publicId}",
)

self.assertEqual(PQ(cards[1]).find(".card__heading-2").text(), "ID kaart")
self.assertEqual(PyQuery(cards[1]).find(".card__heading-2").text(), "ID kaart")

id_card_appointment = PQ(cards[1]).find("ul").children()
id_card_appointment = PyQuery(cards[1]).find("ul").children()

self.assertEqual(PQ(id_card_appointment[0]).text(), "Datum\n6 maart 2020")
self.assertEqual(PQ(id_card_appointment[1]).text(), "Tijd\n11:30 uur")
self.assertEqual(PQ(id_card_appointment[2]).text(), "Locatie\nHoofdkantoor")
self.assertEqual(PQ(id_card_appointment[3]).text(), "Wall Street 1")
self.assertEqual(PQ(id_card_appointment[4]).text(), "1111 AA New York")
self.assertEqual(PyQuery(id_card_appointment[0]).text(), "Datum\n6 maart 2020")
self.assertEqual(PyQuery(id_card_appointment[1]).text(), "Tijd\n11:30 uur")
self.assertEqual(
PyQuery(id_card_appointment[2]).text(), "Locatie\nHoofdkantoor"
)
self.assertEqual(PyQuery(id_card_appointment[3]).text(), "Wall Street 1")
self.assertEqual(PyQuery(id_card_appointment[4]).text(), "1111 AA New York")
self.assertEqual(
PQ(cards[1]).find("a").attr("href"),
PyQuery(cards[1]).find("a").attr("href"),
f"{self.data.config.booking_base_url}{self.data.appointment_idcard.publicId}",
)
4 changes: 2 additions & 2 deletions src/open_inwoner/accounts/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from open_inwoner.laposta.forms import NewsletterSubscriptionForm
from open_inwoner.laposta.models import LapostaConfig
from open_inwoner.plans.models import Plan
from open_inwoner.qmatic.client import NoServiceConfigured, QmaticClient
from open_inwoner.qmatic.client import NoServiceConfigured, make_qmatic_client
from open_inwoner.questionnaire.models import QuestionnaireStep
from open_inwoner.utils.views import CommonPageMixin, LogMixin

Expand Down Expand Up @@ -388,7 +388,7 @@ def get_context_data(self, **kwargs) -> dict[str, Any]:
context["appointments"] = []
else:
try:
client = QmaticClient()
client = make_qmatic_client()
except NoServiceConfigured:
logger.exception("Error occurred while creating Qmatic client")
context["appointments"] = []
Expand Down
4 changes: 2 additions & 2 deletions src/open_inwoner/cms/plugins/cms_plugins/appointments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cms.plugin_pool import plugin_pool

from open_inwoner.cms.plugins.models.appointments import UserAppointments
from open_inwoner.qmatic.client import NoServiceConfigured, QmaticClient
from open_inwoner.qmatic.client import NoServiceConfigured, make_qmatic_client

logger = logging.getLogger(__name__)

Expand All @@ -24,7 +24,7 @@ def render(self, context, instance, placeholder):
appointments = []
else:
try:
client = QmaticClient()
client = make_qmatic_client()
except NoServiceConfigured:
logger.exception("Error occurred while creating Qmatic client")
appointments = []
Expand Down
12 changes: 6 additions & 6 deletions src/open_inwoner/cms/plugins/tests/test_appointments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import requests_mock
from freezegun import freeze_time
from pyquery import PyQuery as PQ
from pyquery import PyQuery

from open_inwoner.cms.tests import cms_tools
from open_inwoner.qmatic.tests.data import QmaticMockData
Expand Down Expand Up @@ -33,16 +33,16 @@ def test_plugin(self, m):
self.assertIn("ID kaart", html)
self.assertNotIn("Old appointment", html)

pyquery = PQ(html)
pyquery = PyQuery(html)

# test item
items = pyquery.find(".card-container .card")
self.assertEqual(len(items), 2)

aanvraag_paspoort_date = PQ(items.find("p.tabled__value")[0]).text()
aanvraag_paspoort_title = PQ(items.find(".plugin-card__heading")[0]).text()
aanvraag_id_kaart_date = PQ(items.find("p.tabled__value")[1]).text()
aanvraag_id_kaart_title = PQ(items.find(".plugin-card__heading")[1]).text()
aanvraag_paspoort_date = PyQuery(items.find("p.tabled__value")[0]).text()
aanvraag_paspoort_title = PyQuery(items.find(".plugin-card__heading")[0]).text()
aanvraag_id_kaart_date = PyQuery(items.find("p.tabled__value")[1]).text()
aanvraag_id_kaart_title = PyQuery(items.find(".plugin-card__heading")[1]).text()

self.assertEqual(aanvraag_paspoort_date, "1 januari 2020 om 13:00 uur")
self.assertEqual(aanvraag_paspoort_title, "Paspoort")
Expand Down
4 changes: 2 additions & 2 deletions src/open_inwoner/cms/plugins/tests/test_userfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.utils.html import strip_tags
from django.utils.translation import ngettext

from pyquery import PyQuery as PQ
from pyquery import PyQuery

from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.cms.tests import cms_tools
Expand All @@ -26,7 +26,7 @@ def test_plugin(self):
self.assertIn("Test message", html)
self.assertIn("Hello", html)

pyquery = PQ(html)
pyquery = PyQuery(html)

# test summary
summaries = pyquery.find(".userfeed__summary .userfeed__list-item")
Expand Down
6 changes: 3 additions & 3 deletions src/open_inwoner/cms/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import reverse

from maykin_2fa.test import disable_admin_mfa
from pyquery import PyQuery as pq
from pyquery import PyQuery

from open_inwoner.cms.tests import cms_tools
from open_inwoner.cms.utils.middleware import DropToolbarMiddleware
Expand Down Expand Up @@ -61,11 +61,11 @@ def test_staff_verified_with_2fa_shows_toolbar(self):
self.assertHasToolbar(response)

def assertHasToolbar(self, response):
d = pq(response.content.decode("utf8"))
d = PyQuery(response.content.decode("utf8"))
if not len(d(".cms-toolbar")):
self.fail("cannot locate element with class '.cms-toolbar'")

def assertNotHasToolbar(self, response):
d = pq(response.content.decode("utf8"))
d = PyQuery(response.content.decode("utf8"))
if len(d(".cms-toolbar")):
self.fail("found element with class '.cms-toolbar'")
4 changes: 2 additions & 2 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sentry_sdk
from celery.schedules import crontab
from easy_thumbnails.conf import Settings as thumbnail_settings
from easy_thumbnails.conf import Settings as ThumbnailSettings
from log_outgoing_requests.formatters import HttpFormatter

from .utils import config, get_sentry_integrations
Expand Down Expand Up @@ -790,7 +790,7 @@
THUMBNAIL_PROCESSORS = (
"filer.thumbnail_processors.scale_and_crop_with_subject_location",
"image_cropping.thumbnail_processors.crop_corners",
) + thumbnail_settings.THUMBNAIL_PROCESSORS
) + ThumbnailSettings.THUMBNAIL_PROCESSORS

THUMBNAIL_HIGH_RESOLUTION = True

Expand Down
6 changes: 3 additions & 3 deletions src/open_inwoner/configurations/tests/test_kcm_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.test import TestCase

from pyquery import PyQuery as PQ
from pyquery import PyQuery

from open_inwoner.cms.profile.cms_apps import ProfileApphook
from open_inwoner.cms.tests import cms_tools
Expand All @@ -25,7 +25,7 @@ def setUp(self):
def test_kcm_survey_configured(self, mock_config):
response = self.client.get("/")

doc = PQ(response.content)
doc = PyQuery(response.content)

self.assertEqual(len(doc.find(self.css_selector)), 1)

Expand All @@ -46,6 +46,6 @@ def test_kcm_survey_not_configured(self):
):
response = self.client.get("/")

doc = PQ(response.content)
doc = PyQuery(response.content)

self.assertEqual(len(doc.find(self.css_selector)), 0)
Loading

0 comments on commit 142c75f

Please sign in to comment.