-
Notifications
You must be signed in to change notification settings - Fork 449
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
improved code of user.py with dict.get() and suggestions #1124
base: develop
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1124 +/- ##
===========================================
+ Coverage 93.25% 94.38% +1.12%
===========================================
Files 38 38
Lines 2062 2029 -33
===========================================
- Hits 1923 1915 -8
+ Misses 139 114 -25
|
@devkapilbansal I have rebased my branch to master and have made all changes suggested by you. Please review my changes |
app/api/dao/user.py
Outdated
password = data["password"] | ||
email = data["email"] | ||
terms_and_conditions_checked = data["terms_and_conditions_checked"] | ||
name = data.get("name", None) |
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.
None is default right? I don't think you need this here
app/api/dao/user.py
Outdated
user.username = username | ||
|
||
if "name" in data and data["name"]: | ||
user.name = data["name"] | ||
user.name = data.get("name", None) |
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.
ditto
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.
This will raise a key error if name entered is not found that's why none is required here
app/api/dao/user.py
Outdated
@@ -39,11 +39,11 @@ def create_user(data: Dict[str, str]): | |||
A tuple with two elements. The first element is a dictionary containing a key 'message' containing a string which indicates whether or not the user was created successfully. The second is the HTTP response code. | |||
""" | |||
|
|||
name = data["name"] |
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.
Also please use a different branch for each pr. You've used develop currently, this may cause issues in the future.
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.
@aakankshaagr please remove None
as asked above. I remember asking for this in previous PR too. Also, please try to refrain from closing PR and opening a new one. You can ask for help if you stuck.
P.S.:- Please don't use default branch name from next time.
Sure @devkapilbansal @epicadk I will keep these things in mind. |
Shall I merge all commit in a single commit as I haven't created a new branch ? |
app/api/dao/user.py
Outdated
user.username = username | ||
|
||
if "name" in data and data["name"]: | ||
user.name = data["name"] | ||
user.name = data.get("name", None) |
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.
If you use data["name"], then KeyError will be raised, not with data.get
user.name = data.get("name", None) | |
user.name = data.get("name") |
app/api/dao/user.py
Outdated
user.bio = data["bio"] | ||
else: | ||
user.bio = None | ||
user.bio = data.get("bio", None) |
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.
Same as above
app/api/dao/user.py
Outdated
user.organization = data["organization"] | ||
else: | ||
user.organization = None | ||
user.organization = data.get("organization", None) or None |
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.
Same as above, same for other cases as well
user.organization = data.get("organization", None) or None | |
user.organization = data.get("organization") |
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.
As I have told earlier, on removing none in organization and occupation will fail test cases.
No, you don't need to. Just keep this in mind from next time |
Sorry for the inconvenience |
@aakankshaagr there are some suggestions above. Once done, this PR may get completed. Look into them once you have some time. |
@aakankshaagr any updates about this PR? |
@devkapilbansal @vj-codes I have made changes as you have asked but on removing none in organization and occupation test cases are failing |
@aakankshaagr make changes in this line
Pass occupation and organization as None here. Then your tests will not fail |
Thanks, @devkapilbansal. I thought I can't edit the test cases and have to code such that the test passes. |
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.
LGTM 👍
Thanks a lot @aakankshaagr
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.
@aakankshaagr nice work 🎉
Do remember to commit the changes on a new branch other than develop while working on future issues as mentioned in the community guidelines:)
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 work! Thank you for contributing @aakankshaagr 🤗
The changes made in this PR were tested locally. Following are the results:
|
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.
This changes the functionality of the API at the moment because if we don't send one of the values, these will be set with None 🤔 Could we find a better way to avoid setting these as null.
This also reminds me of the PUT vs PATCH usage in this project right?
cc @anitab-org/mentorship-maintainers
Description
Fixes #1065
Type of Change:
How Has This Been Tested?
Tested on my local pc
Checklist:
Code/Quality Assurance Only