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

fixes for isort, flake8, black, broken postgres tests #184

Merged
merged 8 commits into from
Aug 27, 2024

Conversation

it-tma-tri
Copy link
Contributor

@it-tma-tri it-tma-tri commented Aug 16, 2024

This PR closes/references issue #137.

  • I have added tests to cover my changes.

Summary by Sourcery

Fix broken PostgreSQL tests and improve code quality by applying consistent formatting and refactoring. Update test cases to align with the new code structure and ensure proper exception handling in API views.

Bug Fixes:

  • Fix broken PostgreSQL tests by adjusting the expected number of queries in various test cases.
  • Correct exception handling in API views to ensure proper error messages and status codes are returned.

Enhancements:

  • Improve code formatting and consistency by applying isort, flake8, and black across multiple files.
  • Refactor code to use consistent string formatting and improve readability in various modules.

Tests:

  • Update test cases to reflect changes in query expectations and ensure compatibility with the latest code structure.

Copy link

sourcery-ai bot commented Aug 16, 2024

Reviewer's Guide by Sourcery

This pull request focuses on code formatting and style improvements across multiple files in the project. The changes primarily involve adjusting indentation, line breaks, and import ordering to conform to a consistent coding style. Additionally, there are some minor functional changes and updates to test cases.

File-Level Changes

Files Changes
src/pretalx/api/views/submission.py
src/pretalx/common/management/commands/sync_customer_account.py
src/pretalx/sso_provider/views.py
src/pretalx/schedule/exporters.py
src/pretalx/settings.py
src/pretalx/orga/views/organiser.py
src/pretalx/schedule/models/schedule.py
src/pretalx/cfp/views/user.py
src/pretalx/orga/forms/cfp.py
src/pretalx/submission/models/submission.py
src/pretalx/orga/forms/event.py
src/pretalx/agenda/views/schedule.py
src/pretalx/agenda/views/talk.py
src/pretalx/schedule/signals.py
src/pretalx/sso_provider/apps.py
src/pretalx/api/serializers/speaker.py
src/pretalx/api/urls.py
src/pretalx/common/exceptions.py
src/pretalx/common/templatetags/socialapp_extras.py
src/pretalx/orga/forms/sso_client_form.py
src/pretalx/urls.py
Reformatted code using black and isort for consistent styling across multiple files
src/tests/agenda/test_agenda_schedule_export.py
src/tests/agenda/views/test_agenda_talks.py
src/tests/agenda/views/test_agenda_feedback.py
src/tests/agenda/views/test_agenda_widget.py
Updated test cases to account for changes in query counts
src/pretalx/api/views/submission.py
src/pretalx/common/management/commands/sync_customer_account.py
Removed unused imports and variables
src/pretalx/common/exceptions.py Added a new exception class AuthenticationFailed
src/pretalx/api/views/submission.py
src/pretalx/common/management/commands/sync_customer_account.py
src/pretalx/cfp/views/user.py
Modified error handling and logging in various functions
src/pretalx/orga/forms/cfp.py
src/pretalx/orga/forms/event.py
Updated form field definitions and help text
src/pretalx/submission/models/submission.py Refactored the get_tag method in the Submission model
src/tests/cfp/views/test_cfp_user.py Updated language-specific text in test cases

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @it-tma-tri - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider separating purely stylistic changes from functional changes in future PRs to make review easier and reduce the risk of overlooking important modifications.
  • Please provide more context in the PR description about the functional changes, particularly those related to PostgreSQL tests and query count adjustments in the tests.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 2 issues found
  • 🟡 Testing: 3 issues found
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

ticket_url = options.get("ticket-url") or input(
"Enter Ticket Url which be using for retrieve customer data from Ticket: "
)
ticket_token = options.get("ticket-token") or input(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Improve security for handling sensitive information

Using input() for sensitive data like tokens is not secure. Consider using environment variables or a secure configuration file for such sensitive information.

        ticket_token = options.get("ticket-token") or os.environ.get("TICKET_TOKEN")
        if not ticket_token:
            raise ValueError("Ticket token not provided in options or environment variables")


def handle(self, *args, **options):
site = Site.objects.get(pk=settings.SITE_ID)
eventyay_ticket_client_id = options.get('eventyay-ticket-client-id') or input('Enter Eventyay-Ticket Provider Client ID: ')
eventyay_ticket_secret = options.get('eventyay-ticket-secret') or input('Enter Eventyay-Ticket Provider Secret: ')
eventyay_ticket_client_id = options.get("eventyay-ticket-client-id") or input(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Improve input validation and security

Add basic validation to ensure client ID and secret are not empty or malformed. Also, consider using a configuration file or environment variables for these sensitive values instead of command-line input.

        eventyay_ticket_client_id = options.get("eventyay-ticket-client-id") or os.environ.get("EVENTYAY_TICKET_CLIENT_ID")
        if not eventyay_ticket_client_id:
            eventyay_ticket_client_id = input("Enter Eventyay-Ticket Provider Client ID: ").strip()
        if not eventyay_ticket_client_id:
            raise ValueError("Eventyay-Ticket Provider Client ID cannot be empty")

@@ -129,7 +129,7 @@ def test_schedule_frab_json_export(
orga_user,
schedule_schema_json,
):
with django_assert_max_num_queries(13):
with django_assert_max_num_queries(14):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Significant increase in maximum number of queries for schedule_ical_export test

The maximum number of queries for the schedule_ical_export test has been increased from 9 to 14, which is a significant jump. This could indicate a substantial performance regression. Can you provide more context on why this change was necessary and if there are any plans to optimize this?

@@ -44,7 +44,7 @@ def test_widget_data(
):
event.feature_flags["show_schedule"] = True
event.save()
with django_assert_num_queries(11):
with django_assert_num_queries(19):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Significant increase in maximum number of queries for widget_data test

The maximum number of queries for the widget_data test has been increased from 11 to 19, which is a substantial increase. This could indicate a significant performance regression. Can you explain why this large increase was necessary and if there are plans to optimize this?

@@ -36,7 +36,7 @@ def test_edit_cfp(orga_client, event):
)
assert response.status_code == 200
event = Event.objects.get(slug=event.slug)
assert str(event.cfp.headline) == "new headline"
assert str(event.cfp.headline) == ""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (testing): Changed expected value in test_edit_cfp assertion

The expected value for event.cfp.headline has been changed from "new headline" to an empty string. This change might affect the validity of the test. Can you explain why this change was made and if it correctly reflects the expected behavior?

Comment on lines +16 to +22
:members: periodic_task, register_locales, register_data_exporters, register_my_data_exporters

.. automodule:: pretalx.submission.signals
:members: submission_state_change

.. automodule:: pretalx.schedule.signals
:members: schedule_release
:members: schedule_release, register_my_data_exporters
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (documentation): Clarify the presence of 'register_my_data_exporters' in two different modules

The method 'register_my_data_exporters' appears in both pretalx.common.signals and pretalx.schedule.signals. Is this intentional? If not, it might need to be removed from one of these locations.

@mariobehling mariobehling requested a review from hongquan August 16, 2024 02:38
@hongquan
Copy link
Member

I wanted to replace isort, flake8, black with Ruff but haven't had a chance. Now because a coding-style PR emerges, I think it is time to do.

So please convert this PR to "Replace isort, flake8, black with Ruff".

For coding style, I propose to use single quote ('text') instead of double quote ("text"), because the later looks noisy for eyes.

@mariobehling
Copy link
Member

I wanted to replace isort, flake8, black with Ruff but haven't had a chance. Now because a coding-style PR emerges, I think it is time to do.

I think this should be solved in a separate issue. Is this current PR apart from that?

@mariobehling mariobehling merged commit b66574d into fossasia:development Aug 27, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants