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

#156687691 Fix Accounts Tests #8

Merged
merged 23 commits into from
May 2, 2018

Conversation

ghost
Copy link

@ghost ghost commented Apr 26, 2018

What does this PR do?

Fixes and completes tests in the following modules under accounts/tests/:

  • test_check_token.py
  • test_login.py
  • test_profile.py
  • test_switch_team.py
  • test_team_access_middleware.py

Description of Task to be completed?

Fix accounts tests

How should this be manually tested?

  • In the root module run python manage.py test
  • Or activate the virtualenv environment and run pytest tests in accounts/ folder

What are the relevant pivotal tracker stories?

@coveralls
Copy link

coveralls commented Apr 26, 2018

Pull Request Test Coverage Report for Build 147

  • 0 of 0 (NaN%) changed or added relevant lines in 0 files are covered.
  • 4 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.6%) to 80.613%

Files with Coverage Reduction New Missed Lines %
hc/settings.py 1 97.83%
hc/api/management/commands/ensuretriggers.py 3 100.0%
Totals Coverage Status
Change from base Build 36: 0.6%
Covered Lines: 1551
Relevant Lines: 1924

💛 - Coveralls

Copy link

@jimmykamau jimmykamau left a comment

Choose a reason for hiding this comment

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

See comments

def test_it_redirects_after_login_with_a_bad_token(self):
# Login with a bad token
url = "/accounts/check_token/alice/invalid-token/"
r = self.client.post(url, follow=True)

Choose a reason for hiding this comment

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

You should try logging in with an incorrect token, not call the incorrect token URL

Copy link
Author

@ghost ghost May 1, 2018

Choose a reason for hiding this comment

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

I disagree with you @jimmykamau . The healthchecks login route at /accounts/login/ accepts a form with input email address and password to log in a user with this email address. The login function at hc/accounts/views.py takes this form bundled in a request param. There is no method to login a user using a token other than the check_token(request, username, token) at hc/accounts/views.py. The GET route /accounts/check-token/<username>/<token>/ is the URL that will access this function.

Copy link

@jimmykamau jimmykamau May 2, 2018

Choose a reason for hiding this comment

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

Have you tried calling the function with an incorrect token?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I it says I provide the request param which I dont have

Copy link
Author

Choose a reason for hiding this comment

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

I'm forced to use the GET route to access this function

Choose a reason for hiding this comment

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

Cool

### Assert that check is associated with the new user
# Assert that check is associated with the new user
get_check = Check.objects.get(code=check.code)
assert get_check.user

Choose a reason for hiding this comment

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

This doesn't actually check against the new User, just determines that there's a user

Copy link
Author

Choose a reason for hiding this comment

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

I refactored this. I am now checking whether the user object associated with the check is the actual object created. I had to compare the whole objects, I couldn't find methods to retrieve user attributes in the User model. But I don't think this is a very efficient way @jimmykamau

@@ -17,17 +17,26 @@ def test_it_sends_set_password_link(self):
# profile.token should be set now
self.alice.profile.refresh_from_db()
token = self.alice.profile.token
### Assert that the token is set
# Assert that the token is set
self.assertTrue(len(token) > 10)

Choose a reason for hiding this comment

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

I don't think this is the best way of checking this, what happens when we change the length of the token?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I am now checking whether the token exists

@ghost
Copy link
Author

ghost commented Apr 27, 2018

Thank you for the observations Jimmy, I'll make some changes and update the PR. I'll notify you once I am done

@jimmykamau jimmykamau merged commit e5e0df2 into develop May 2, 2018
@jimmykamau jimmykamau deleted the ch-fix-accounts-tests-#156687691 branch May 2, 2018 09:55
@ghost ghost changed the title #156687691 Chore fix accounts tests #156687691 Fix Accounts Tests May 7, 2018
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.

4 participants