Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply ruff pep8-naming rule #1616

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ select = [
"PERF",
# https://docs.astral.sh/ruff/rules/#refurb-furb
"FURB",
# https://docs.astral.sh/ruff/rules/#pep8-naming-n
"N",
]
ignore = [
# Whitespace before ':' (conflicts with Black)
Expand All @@ -67,13 +69,28 @@ ignore = [
# Use a single `with` statement with multiple contexts instead of nested `with` statements
"SIM117",
# Checks for nested if statements that can be collapsed into a single if statement.
"SIM102"
"SIM102",
# Variables in function scope should be lower-case
"N806",
# Variables in class scope should not be mixed-case
"N815",
# Exception name should be named with Error suffix
"N818",
]


# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Ad hoc exceptions
[lint.pep8-naming]
ignore-names = [
# N801
"eHerkenning*", "eSuite*", "BRP_[0-9]_[0-9]",
# N802
"*setUp*", "tearDown*", "*assert*",
"*TimelineLog*", "innNnpId",
]
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 @@ -1337,13 +1337,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 @@ -1500,30 +1500,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, qmatic_client_factory
from open_inwoner.questionnaire.models import QuestionnaireStep
from open_inwoner.utils.views import CommonPageMixin, LogMixin

Expand Down Expand Up @@ -389,7 +389,7 @@ def get_context_data(self, **kwargs) -> dict[str, Any]:
context["appointments"] = []
else:
try:
client = QmaticClient()
client = qmatic_client_factory()
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, qmatic_client_factory

logger = logging.getLogger(__name__)

Expand All @@ -24,7 +24,7 @@ def render(self, context, instance, placeholder):
appointments = []
else:
try:
client = QmaticClient()
client = qmatic_client_factory()
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
Loading
Loading