From 941cc70373c27aca87c37a22d9bd14d36c664176 Mon Sep 17 00:00:00 2001 From: Eric Herrera Date: Wed, 13 Oct 2021 08:26:44 -0500 Subject: [PATCH] fix: Quality tests related to f-string --- designer/apps/api/v1/views.py | 8 ++----- designer/apps/core/tests/utils.py | 22 ++++--------------- .../apps/pages/tests/test_create_pages.py | 4 ++-- designer/apps/pages/tests/utils.py | 2 +- 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/designer/apps/api/v1/views.py b/designer/apps/api/v1/views.py index 6a5bc979..08af85bf 100644 --- a/designer/apps/api/v1/views.py +++ b/designer/apps/api/v1/views.py @@ -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 @@ -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 diff --git a/designer/apps/core/tests/utils.py b/designer/apps/core/tests/utils.py index 79ca4eb0..2c2dc17d 100644 --- a/designer/apps/core/tests/utils.py +++ b/designer/apps/core/tests/utils.py @@ -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(' ', '')) @@ -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) ) @@ -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) @@ -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')}" ) diff --git a/designer/apps/pages/tests/test_create_pages.py b/designer/apps/pages/tests/test_create_pages.py index 23a7792c..fb291c7a 100644 --- a/designer/apps/pages/tests/test_create_pages.py +++ b/designer/apps/pages/tests/test_create_pages.py @@ -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': "".format( + 'external_program_website-0-description': "".format( # pylint: disable=consider-using-f-string [f"
  • {s}
  • " for s in fake.sentences(nb=4)] ), 'external_program_website-0-link_display_text': f"Return to {page_name} homepage", @@ -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: diff --git a/designer/apps/pages/tests/utils.py b/designer/apps/pages/tests/utils.py index 00d1a4ff..25cf6c11 100644 --- a/designer/apps/pages/tests/utils.py +++ b/designer/apps/pages/tests/utils.py @@ -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: "".format( + description = factory.LazyAttribute(lambda l: "".format( # pylint: disable=consider-using-f-string [f"
  • {s}
  • " for s in fake.sentences(nb=4)] )) link_display_text = factory.LazyAttribute(lambda l: fake.sentence())