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

test: Add tests for permissions #205

Merged
merged 1 commit into from
May 16, 2021

Conversation

abhiabhi94
Copy link
Collaborator

@abhiabhi94 abhiabhi94 commented May 15, 2021

  • almost but takes test coverage to 100%.

@abhiabhi94
Copy link
Collaborator Author

abhiabhi94 commented May 15, 2021

Hey, see what I found testing the current permissions. The permission delete_comment is same as the default one created with by django for all models.

https://github.com/django/django/blob/main/django/contrib/auth/models.py#L35-L56

Was this done knowingly?

@abhiabhi94
Copy link
Collaborator Author

abhiabhi94 commented May 15, 2021

i can't think of a scenario, where this condition would become false

def set_unique_urlhash(model, instance):
if not instance.urlhash:
instance.urlhash = generate_urlhash()
while model.objects.filter(urlhash=instance.urlhash).exists():
instance.urlhash = generate_urlhash()

should we probably remove this?

@abhiabhi94 abhiabhi94 force-pushed the test/add-migration-tests branch 3 times, most recently from f232b81 to d4e5aed Compare May 15, 2021 19:19
@Radi85
Copy link
Owner

Radi85 commented May 16, 2021

Hey, see what I found testing the current permissions. The permission delete_comment is same as the default one created with by django for all models.

https://github.com/django/django/blob/main/django/contrib/auth/models.py#L35-L56

Was this done knowingly?

Yes, we are using get_or_create to make sure that the permission will be created if won't by default for any reason.
Our permission is matching django default one Can delete comment.

@Radi85
Copy link
Owner

Radi85 commented May 16, 2021

i can't think of a scenario, where this condition would become false

def set_unique_urlhash(model, instance):
if not instance.urlhash:
instance.urlhash = generate_urlhash()
while model.objects.filter(urlhash=instance.urlhash).exists():
instance.urlhash = generate_urlhash()

should we probably remove this?

This function was added to comply old version with the new one. I believe it will be always needed.

@abhiabhi94
Copy link
Collaborator Author

This function was added to comply old version with the new one. I believe it will be always needed.

no, my bad i should have explained the exact thing that i wanted to mention. I was just talking about the scenario where if not instance.urlhash: would return False. This is the only part which is not covered by tests.

As the attribute will only be created and filled in this migration itself, i can't think of a real world scenario where a comment can have urlhash property beforehand and the condition would become False.

I think we can safely remove this.

@abhiabhi94
Copy link
Collaborator Author

Our permission is matching django default one Can delete comment.

Is this a good thing? should we be concerned about it. I can adjust the current tests to bypass this thing but just wanted an extra set of brains to just discuss.

@Radi85
Copy link
Owner

Radi85 commented May 16, 2021

I think we can safely remove this.

I think yes. not instance.urlhash this is always True since the comment model has no urlhash before this migration.

@Radi85
Copy link
Owner

Radi85 commented May 16, 2021

Is this a good thing? should we be concerned about it. I can adjust the current tests to bypass this thing but just wanted an extra set of brains to just discuss.

I am not sure I fully got what your concern is here? We are using django default permission or we create it if not exist, what's the issue?

@abhiabhi94
Copy link
Collaborator Author

I am not sure I fully got what your concern is here? We are using django default permission or we create it if not exist, what's the issue?

nothing, i can't think of a reason to support my concern now. maybe i was just concerned that we may be overriding something from the default permissions, but we actually aren't. so we should be safe i think.

- almost but takes the test coverage to 100%.

Remove unnecessary check for previous urlhash from migrations

- since the attribute was created and filled in this migration itself, it wasn't necessary.
Copy link
Owner

@Radi85 Radi85 left a comment

Choose a reason for hiding this comment

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

Thanks @abhiabhi94

@Radi85 Radi85 merged commit c4d2682 into Radi85:develop May 16, 2021
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.

2 participants