Skip to content

Conversation

@n2ygk
Copy link
Contributor

@n2ygk n2ygk commented Jan 10, 2022

Fixes #1065

Description of the Change

Add test for cleartokens command

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test added
  • documentation updated
  • CHANGELOG.md updated (only for user relevant changes)
  • author name in AUTHORS

@n2ygk n2ygk requested a review from a team January 10, 2022 23:06
@codecov
Copy link

codecov bot commented Jan 10, 2022

Codecov Report

Merging #1084 (814855c) into master (68da292) will increase coverage by 0.34%.
The diff coverage is n/a.

❗ Current head 814855c differs from pull request most recent head 372074d. Consider uploading reports for the commit 372074d to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1084      +/-   ##
==========================================
+ Coverage   96.64%   96.99%   +0.34%     
==========================================
  Files          31       31              
  Lines        1761     1761              
==========================================
+ Hits         1702     1708       +6     
+ Misses         59       53       -6     
Impacted Files Coverage Δ
oauth2_provider/management/commands/cleartokens.py 100.00% <0.00%> (+100.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68da292...372074d. Read the comment docs.

application=app,
expires=later,
redirect_uri="https://localhost/redirect",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

lint not running?

Copy link
Contributor Author

@n2ygk n2ygk Jan 11, 2022

Choose a reason for hiding this comment

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

It's what black appears to want. I always run tox -e flake8 before committing. Also the pre-commit hooks do that as well I believe.

Also, what specifically did you see there that caused you to ask?

new = AccesstokenModel.objects.create(token="current access token {}".format(i), expires=later)
# make half of these Access Tokens have related Refresh Tokens, which prevent their deletion.
if i % 2:
RefreshtokenModel.objects.create(
Copy link
Contributor

Choose a reason for hiding this comment

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

Use bulk_create. Use list comprehensions with RefreshtokenModel(...) and run RefreshtokenModel.objects.bulk_create The order in id increment should remain the same.


Application = get_application_model()
AccesstokenModel = get_access_token_model()
RefreshtokenModel = get_refresh_token_model()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
RefreshtokenModel = get_refresh_token_model()
RefreshTokenModel = get_refresh_token_model()

camel case



Application = get_application_model()
AccesstokenModel = get_access_token_model()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
AccesstokenModel = get_access_token_model()
AccessTokenModel = get_access_token_model()

camel case

self.assertEqual(RefreshtokenModel.objects.count(), 100)
self.assertEqual(GrantModel.objects.count(), 200)
call_command(
"cleartokens",
Copy link
Contributor

Choose a reason for hiding this comment

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

lint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I blame black although this was me:-)

@n2ygk
Copy link
Contributor Author

n2ygk commented Jan 11, 2022

On second thought clear_tokens is already tested in test_models so maybe just pragma: no cover?

Might want to enhance the tests there though....

auvipy and others added 2 commits January 11, 2022 09:12
Co-authored-by: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com>
Co-authored-by: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com>
@n2ygk
Copy link
Contributor Author

n2ygk commented Jan 11, 2022

@auvipy please stop pushing commits

@n2ygk n2ygk changed the title Add test for cleartokens management command. WIP: Add test for cleartokens management command. Jan 11, 2022
@n2ygk n2ygk closed this Jan 11, 2022
@n2ygk
Copy link
Contributor Author

n2ygk commented Jan 11, 2022

Closing in lieu of the simpler approach mentioned above.

n2ygk added a commit to n2ygk/django-oauth-toolkit that referenced this pull request Jan 11, 2022
@n2ygk n2ygk mentioned this pull request Jan 11, 2022
5 tasks
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.

Write a test for cleartokens management command

3 participants