Skip to content

Commit

Permalink
fix: Quality tests related to f-string
Browse files Browse the repository at this point in the history
  • Loading branch information
ericfab179 committed Oct 13, 2021
1 parent 11e31d8 commit 941cc70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
8 changes: 2 additions & 6 deletions designer/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ def _get_serialized_pages(queryset):
"""
pages = []
for page in queryset:
page_type = "{app_label}.{model_name}".format(
app_label=page._meta.app_label,
model_name=page._meta.model.__name__,
)

page_type = f"{page._meta.app_label}.{page._meta.model.__name__}"
if page_type in PAGE_TYPE_SERIALIZERS:
serialized_data = PAGE_TYPE_SERIALIZERS[page_type](page).data

Expand Down Expand Up @@ -158,7 +154,7 @@ def get(self, *args, **kwargs):

def generate_frontend_url(request, program_page):
"""Used to create the frontend URL based on the program page data"""
url = '{scheme}://{hostname}/{slug}'.format(
url = '{scheme}://{hostname}/{slug}'.format( # pylint: disable=consider-using-f-string
scheme='https' if request.is_secure() else 'https',
hostname=program_page.get_site().hostname,
slug=program_page.slug
Expand Down
22 changes: 4 additions & 18 deletions designer/apps/core/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ class Params:
firstname = factory.LazyAttribute(lambda __: fake.first_name())
lastname = factory.LazyAttribute(lambda __: fake.last_name())

full_name = factory.LazyAttribute(lambda o: "{firstname} {lastname}".format(
firstname=o.firstname,
lastname=o.lastname,
))
full_name = factory.LazyAttribute(lambda o: f"{o.firstname} {o.lastname}")
first_name = factory.LazyAttribute(lambda o: o.firstname)
last_name = factory.LazyAttribute(lambda o: o.lastname)
username = factory.LazyAttribute(lambda o: (o.firstname + o.lastname).lower().replace(' ', ''))
Expand All @@ -79,11 +76,7 @@ class Params:

site_name = factory.LazyAttribute(lambda o: o.company_name)
hostname = factory.LazyAttribute(
lambda o: "{company_name}.{domain_name}".format(
company_name=o.company_name.replace(' ', '-').lower(),
domain_name=fake.domain_name()
)
)
lambda o: f"{o.company_name.replace(' ', '-').lower()}.{fake.domain_name()}")
root_page = factory.LazyAttribute(
lambda o: create_index_page(o.site_name)
)
Expand All @@ -99,11 +92,7 @@ class Params:

title = factory.LazyAttribute(lambda o: o.image_title)
file = factory.LazyAttribute(
lambda o: "/media/original_images/{filename}.{extension}".format(
filename=o.image_title.replace(' ', '-'),
extension=fake.file_extension(category='image')
)
)
lambda o: f"/media/original_images/{o.image_title.replace(' ', '-')}.{fake.file_extension(category='image')}")
width = random.randint(100, 10000)
height = random.randint(100, 10000)

Expand All @@ -119,8 +108,5 @@ class Params:

title = factory.LazyAttribute(lambda o: o.doc_title)
file = factory.LazyAttribute(
lambda o: "/media/documents/{filename}.{extension}".format(
filename=o.doc_title.replace(' ', '-'),
extension=fake.file_extension(category='text')
)
lambda o: f"/media/documents/{o.doc_title.replace(' ', '-')}.{fake.file_extension(category='text')}"
)
4 changes: 2 additions & 2 deletions designer/apps/pages/tests/test_create_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _create_program_page_data(self, branding=True, program_documents=True, exter
'external_program_website-INITIAL_FORMS': '0',
'external_program_website-0-display': True,
'external_program_website-0-header': ' '.join([word.capitalize() for word in fake.words(nb=3)]),
'external_program_website-0-description': "<ul>{}</ul>".format(
'external_program_website-0-description': "<ul>{}</ul>".format( # pylint: disable=consider-using-f-string
[f"<li>{s}</li>" for s in fake.sentences(nb=4)]
),
'external_program_website-0-link_display_text': f"Return to {page_name} homepage",
Expand Down Expand Up @@ -168,7 +168,7 @@ def _assert_can_create(self, parent, child_model, data):
if not form.errors:
self.fail('Creating a page failed for unknown reason')

errors = '\n'.join([' {}:\n {}'.format(key, '\n'.join(values)) for key, values in form.errors.items()])
errors = '\n'.join([' {}:\n {}'.format(key, '\n'.join(values)) for key, values in form.errors.items()]) # pylint: disable=consider-using-f-string
self.fail(f"Creating a page failed for the following reasons:\n{errors}")

try:
Expand Down
2 changes: 1 addition & 1 deletion designer/apps/pages/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Meta:

display = factory.LazyAttribute(lambda l: fake.boolean())
header = factory.LazyAttribute(lambda l: ' '.join([word.capitalize() for word in fake.words(nb=3)]))
description = factory.LazyAttribute(lambda l: "<ul>{}</ul>".format(
description = factory.LazyAttribute(lambda l: "<ul>{}</ul>".format( # pylint: disable=consider-using-f-string
[f"<li>{s}</li>" for s in fake.sentences(nb=4)]
))
link_display_text = factory.LazyAttribute(lambda l: fake.sentence())
Expand Down

0 comments on commit 941cc70

Please sign in to comment.