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

improved code of user.py with dict.get() and suggestions #1124

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

aakankshaagr
Copy link
Contributor

Description

Fixes #1065

Type of Change:

  • Code
  • Quality Assurance

How Has This Been Tested?

Tested on my local pc

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials

Code/Quality Assurance Only

  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been published in downstream modules

@codecov
Copy link

codecov bot commented Jun 20, 2021

Codecov Report

Merging #1124 (6f6df83) into develop (c154317) will increase coverage by 1.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
app/api/dao/user.py 95.32% <100.00%> (+9.49%) ⬆️

@aakankshaagr
Copy link
Contributor Author

@devkapilbansal I have rebased my branch to master and have made all changes suggested by you. Please review my changes

password = data["password"]
email = data["email"]
terms_and_conditions_checked = data["terms_and_conditions_checked"]
name = data.get("name", None)
Copy link
Member

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

user.username = username

if "name" in data and data["name"]:
user.name = data["name"]
user.name = data.get("name", None)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

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

@@ -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"]
Copy link
Member

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.

@epicadk epicadk added the Status: Changes Requested Changes are required to be done by the PR author. label Jun 21, 2021
Copy link
Member

@devkapilbansal devkapilbansal left a 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.

@aakankshaagr
Copy link
Contributor Author

Sure @devkapilbansal @epicadk I will keep these things in mind.

@aakankshaagr
Copy link
Contributor Author

Shall I merge all commit in a single commit as I haven't created a new branch ?

user.username = username

if "name" in data and data["name"]:
user.name = data["name"]
user.name = data.get("name", None)
Copy link
Member

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

Suggested change
user.name = data.get("name", None)
user.name = data.get("name")

user.bio = data["bio"]
else:
user.bio = None
user.bio = data.get("bio", None)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

user.organization = data["organization"]
else:
user.organization = None
user.organization = data.get("organization", None) or None
Copy link
Member

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

Suggested change
user.organization = data.get("organization", None) or None
user.organization = data.get("organization")

Copy link
Contributor Author

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.

@devkapilbansal
Copy link
Member

Shall I merge all commit in a single commit as I haven't created a new branch ?

No, you don't need to. Just keep this in mind from next time

@aakankshaagr
Copy link
Contributor Author

Sorry for the inconvenience

@devkapilbansal
Copy link
Member

@aakankshaagr there are some suggestions above. Once done, this PR may get completed. Look into them once you have some time.

@vj-codes
Copy link
Member

@aakankshaagr any updates about this PR?

@aakankshaagr
Copy link
Contributor Author

@devkapilbansal @vj-codes I have made changes as you have asked but on removing none in organization and occupation test cases are failing

@devkapilbansal
Copy link
Member

devkapilbansal commented Jul 25, 2021

@aakankshaagr make changes in this line

data = dict(occupation="", organization="")

Pass occupation and organization as None here. Then your tests will not fail

@aakankshaagr
Copy link
Contributor Author

Thanks, @devkapilbansal. I thought I can't edit the test cases and have to code such that the test passes.

Copy link
Member

@devkapilbansal devkapilbansal left a 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

@devkapilbansal devkapilbansal added Status: Needs Review PR needs an additional review or a maintainer's review. and removed Status: Changes Requested Changes are required to be done by the PR author. labels Jul 26, 2021
Copy link
Member

@vj-codes vj-codes left a 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:)

@vj-codes vj-codes added Status: Needs Testing Work has been reviewed and needs the code tested by the quality assurance team. and removed Status: Needs Review PR needs an additional review or a maintainer's review. labels Jul 29, 2021
Copy link
Member

@isabelcosta isabelcosta left a 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 🤗

@isabelcosta isabelcosta temporarily deployed to ms-backend-review-pr-1124 July 29, 2021 22:05 Inactive
@isabelcosta
Copy link
Member

The changes made in this PR were tested locally. Following are the results:

  1. Code review - Done

  2. All possible responses (positive and negative tests) were tested as below:

    • Update my user's location
      Screenshot/gif:

      my location was null

      location appears as null

      I updated it

      updated user location

      then the location changed

      image

      Expected Result: Only Location should change from "null" to "UK"
      Actual Result: When 1 field is sent and other fields are not being sent, it is setting the user attributes as None anyways. This is a breaking change 🤔

  3. Additional Comments: tested at https://ms-backend-review-pr-1124.herokuapp.com/ This will break the current functionality.

  4. Status of PR Changed to: Changes requested :/

@isabelcosta isabelcosta added Status: Needs Review PR needs an additional review or a maintainer's review. and removed Status: Needs Testing Work has been reviewed and needs the code tested by the quality assurance team. labels Jul 29, 2021
Copy link
Member

@isabelcosta isabelcosta left a 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

@isabelcosta isabelcosta self-requested a review July 29, 2021 22:25
@vj-codes vj-codes added Status: On Hold Issue or PR needs more info, a discussion, a review or approval from a Maintainer/Code Owner. and removed Status: Needs Review PR needs an additional review or a maintainer's review. labels Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: On Hold Issue or PR needs more info, a discussion, a review or approval from a Maintainer/Code Owner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improvement: Refactor code to use dict.get() method
5 participants