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

enhanced code of user.py with dict.get() #1116

Closed
wants to merge 5 commits into 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

@vj-codes
Copy link
Member

@aakankshaagr the build check is failing , can you please look into it ?

@aakankshaagr
Copy link
Contributor Author

aakankshaagr commented May 26, 2021

sure @vj-codes !! I looked into tests and found that the test case is failing bcz test is to check " " to be treated as none and I guess it's happening bcz of use of dict.get() as it returns none only when the key is absent. If the key is present it will return whatever value user has given.

image

Here there is an error related to timestamp. I don't know how to remove this error.

image

So tests are failing bcz there is an error and a test fail.

@aakankshaagr
Copy link
Contributor Author

image
I tried using dict.get("key",None) or None to save variable with none if any false values are given as input but still test is failing.

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.

Hi @aakankshaagr thanks for this
There are some more places where this method can be used, like from line 42-47 (mentioned in issue too). Kindly look into the same

@aakankshaagr
Copy link
Contributor Author

aakankshaagr commented Jun 9, 2021

Hi @devkapilbansal thanks for helping me out. I thought earlier that its not needed there but I guess using dict.get() there initializes empty values with None. I missed this point earlier

@aakankshaagr
Copy link
Contributor Author

I made the changes but still tests are failing

@devkapilbansal
Copy link
Member

I made the changes but still tests are failing

First of all, please update your code with current develop

@codecov
Copy link

codecov bot commented Jun 10, 2021

Codecov Report

Merging #1116 (2f8713a) into develop (83c64db) will decrease coverage by 1.98%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1116      +/-   ##
===========================================
- Coverage    96.00%   94.01%   -1.99%     
===========================================
  Files           96       38      -58     
  Lines         5309     2040    -3269     
===========================================
- Hits          5097     1918    -3179     
+ Misses         212      122      -90     
Impacted Files Coverage Δ
app/database/models/user.py 98.57% <ø> (ø)
app/api/dao/user.py 95.32% <100.00%> (+10.24%) ⬆️
app/api/resources/mentorship_relation.py 96.51% <0.00%> (-1.24%) ⬇️
app/messages.py 100.00% <0.00%> (ø)
app/api/models/user.py 100.00% <0.00%> (ø)
app/api/api_extension.py 100.00% <0.00%> (ø)
app/api/jwt_extension.py 100.00% <0.00%> (ø)
app/api/models/mentorship_relation.py 100.00% <0.00%> (ø)
app/schedulers/delete_unverified_users_cron_job.py 100.00% <0.00%> (ø)
tests/users/test_api_refresh.py
... and 75 more

@aakankshaagr
Copy link
Contributor Author

aakankshaagr commented Jun 13, 2021

@devkapilbansal @codesankalp please check if any changes are required

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.

Hi @aakankshaagr please rebase your branch to current develop. j
Also, there are some minor changes as suggested below 👇

@@ -244,73 +244,46 @@ def update_user_profile(user_id: int, data: Dict[str, str]):
user.username = username

if "name" in data and 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.

We don't need these if conditions too

@@ -244,73 +244,46 @@ def update_user_profile(user_id: int, data: Dict[str, str]):
user.username = username

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

if "bio" in data:
Copy link
Member

@devkapilbansal devkapilbansal Jun 18, 2021

Choose a reason for hiding this comment

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

Same as above similar for other cases as well

Comment on lines 308 to 309
current_password = data.get("current_password", None)
new_password = data.get("new_password", 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 can be removed here as it is the default value returned

Suggested change
current_password = data.get("current_password", None)
new_password = data.get("new_password", None)
current_password = data.get("current_password")
new_password = data.get("new_password")

@devkapilbansal
Copy link
Member

Hi @aakankshaagr why this PR is closed??

@aakankshaagr
Copy link
Contributor Author

Hi @devkapilbansal earlier my branch wasn't updated with current develop even though I haven't forgotten to do a git pull to update my codebase and here I needed to rebase my branch to current develop.
To simplify my work I merged all my commits of this issue into one commit and then rebased that commit to the current develop and made some changes to the code.
While trying to push all that changes, I can't find my changes here in this PR so I created a new PR.

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.

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