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

Fix Linting Issues #209

Merged
merged 1 commit into from
Mar 5, 2024
Merged

Fix Linting Issues #209

merged 1 commit into from
Mar 5, 2024

Conversation

WayneLambert
Copy link
Owner

Resolves linting issues reported by Ruff

@WayneLambert WayneLambert added the refactor candidate Items that could be refactored at a later stage label Mar 5, 2024
@WayneLambert WayneLambert self-assigned this Mar 5, 2024
@WayneLambert WayneLambert merged commit 1f21275 into develop Mar 5, 2024
1 check failed
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 WayneLambert - Here's my review!

General suggestions:

  • Consider the implications of directly referencing the User model on future flexibility and extensibility of the user model.
  • Review all related unit tests to ensure they are updated to reflect the changes in model relationships and method signatures.
  • Ensure that the direct use of User does not introduce any regressions or limitations, especially in custom user model scenarios.
  • Verify the broader impact of these changes on the application, particularly in areas related to user authentication and profile management.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -51,7 +50,7 @@ class UserRegisterView(CreateView):

def user_exists(self, form) -> bool:
username = form.data["username"]
Copy link

Choose a reason for hiding this comment

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

issue (llm): Directly referencing the User model instead of using get_user_model() reduces the flexibility of the user model. If the project ever needs to customize the user model, this change will necessitate refactoring all direct references to User.

@@ -51,7 +50,7 @@

def user_exists(self, form) -> bool:
username = form.data["username"]
user = get_user_model().objects.filter(username=username)
user = User.objects.filter(username=username)
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): I noticed the change from get_user_model() to User directly. While this change might not directly impact functionality, it's crucial to ensure that all related unit tests are updated to reflect this change. Specifically, any mock objects or fixtures that rely on the user model should be reviewed to ensure consistency.

@@ -110,7 +109,7 @@
},
)

def email_two_factor_token(self, user: get_user_model(), token):
def email_two_factor_token(self, user: User, token):
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): Given the changes in method signatures to use User directly, it's important to verify if the tests covering email_two_factor_token and related methods are still valid. Ensure that the tests accurately mock the User model and any of its interactions within these methods.

@@ -29,7 +28,7 @@ class AuthorView(models.IntegerChoices):

# Relationship Fields
user = models.OneToOneField(
get_user_model(), primary_key=True, related_name="profile", on_delete=models.CASCADE
User, primary_key=True, related_name="profile", on_delete=models.CASCADE
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): The change in the ForeignKey relationship to use User directly should prompt a review of the model tests, especially those involving the profile related name. Ensure that the tests reflect this change and that any mock or factory objects used in the tests are updated accordingly.

@@ -49,7 +48,7 @@ class Post(models.Model):
help_text="For bests results, use an image that is 1,200px wide x 600px high",
)
status = models.IntegerField(db_index=True, choices=STATUS, default=0)
author = models.ForeignKey(get_user_model(), related_name="author", on_delete=models.CASCADE)
author = models.ForeignKey(User, related_name="author", on_delete=models.CASCADE)
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): This change impacts the Post model's relationship with the User model. It's essential to ensure that all tests related to the Post model, especially those that involve the author relationship, are updated to reflect this change. This includes updating any fixtures or mock objects used in these tests.

@@ -1,24 +1,17 @@
import datetime

from django.contrib.auth import get_user_model
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): The removal of get_user_model import in this test file suggests that there were changes in how the user model is referenced in the tests. Please ensure that all instances where get_user_model() was used are updated to use the User model directly, and that these changes do not affect the integrity of the tests.

Comment on lines +157 to +158
user_passes_auth = self.authenticate_user(user=user)
if user_passes_auth:
Copy link

Choose a reason for hiding this comment

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

suggestion (rule): Sourcery has identified the following issue:

Suggested change
user_passes_auth = self.authenticate_user(user=user)
if user_passes_auth:
if user_passes_auth := self.authenticate_user(user=user):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor candidate Items that could be refactored at a later stage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant