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
Add user profile at authentication #447
Add user profile at authentication #447
Conversation
Codecov Report
@@ Coverage Diff @@
## master #447 +/- ##
==========================================
+ Coverage 92.43% 92.47% +0.03%
==========================================
Files 107 107
Lines 3516 3533 +17
==========================================
+ Hits 3250 3267 +17
Misses 266 266
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! <3 Just needs a test since we're now owning the code from DRF and thus responsible for testing the view post doesn't crash and burn.
Oh yeah, the docs should also have a little update where they currently say how to retrieve the token to indicate it now returns also some profile info. |
Right. Added to the tasks. |
c5dffad
to
60abba3
Compare
socialhome/tests/test_viewsets.py
Outdated
self.assertEqual(response.data, {'non_field_errors': ['Unable to log in with provided credentials.']}) | ||
|
||
def test_authentication(self): | ||
self.client.force_authenticate(self.user, token="0ab231f9f7ab63a6f78fd9746b9bdc9926a734fd") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're testing login so you shouldn't be forcing authentication in the test - this line shouldn't be here imho.
socialhome/tests/test_viewsets.py
Outdated
|
||
def test_authentication(self): | ||
self.client.force_authenticate(self.user, token="0ab231f9f7ab63a6f78fd9746b9bdc9926a734fd") | ||
response = self.client.post(reverse("api-token-auth"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a SocialhomeAPITestCase
you don't need to use self.client
. Our test classes use some handy helper stuff which means you can just do self.post("api-token-auth", {"username": self.user.username, "password": self.user.password})
. (see here)
Does that work? If not I'm not sure what could be the problem. The password should be set by the factory so that shouldn't be an issue..
60abba3
to
f67d517
Compare
Done. Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments, then good to go!
docs/changelog.rst
Outdated
@@ -443,6 +443,7 @@ Changed | |||
|
|||
* Create and update content will now redirect to the content created or updated. Previous behaviour was user preferred landing page. | |||
* Delete content will now redirect back to the page where the delete was triggered from. Previous behaviour was user preferred landing page. If the content delete is triggered from the content detail page, redirect will happen to user preferred landing page as before. (`#204 <https://github.com/jaywink/socialhome/issues/204>`_) | |||
* ``/api-token-auth/`` endpoint now returns limited profile information in addition to token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog entry is in the wrong place, it should be in the latest upcoming release (top of file) not first release (bottom of file).
socialhome/views.py
Outdated
token, created = Token.objects.get_or_create(user=user) | ||
data = LimitedProfileSerializer(user.profile, context={"request": self.request}).data | ||
data.update({"token": token.key}) | ||
print(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missed this one after finishing to debug. Nice catch.
f67d517
to
b8dad13
Compare
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks! <3
/api-token-auth/
now returns limited profile infos in addition to token:Refs: #446