-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bug fix accounts tests #1
Conversation
…ociation ref[#135592991]
…word and send_report methods ref[#135592991]
…t ref[#135592991]
@@ -22,7 +22,15 @@ def test_it_redirects(self): | |||
self.assertEqual(self.profile.token, "") | |||
|
|||
### Login and test it redirects already logged in | |||
def test_it_redirects_if_already_logged_in(self): | |||
self.client.login(username="alice@example.org", password="password") | |||
r = self.client.get("/accounts/check_token/alice/secret-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.
Use something more specific than r
@@ -20,18 +20,23 @@ def test_it_sends_link(self): | |||
assert r.status_code == 302 | |||
|
|||
### Assert that a user was created | |||
self.assertEqual(len(User.objects.filter(email="alice@example.org")), 1) |
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.
Better assertion would be to assert user data rather than length
|
||
### Assert that check is associated with the new user | ||
self.test_user = User.objects.get(email="alice@example.org") | ||
self.test_check = Check.objects.get(user=self.test_user.id) | ||
self.assertEqual(self.test_user.id, self.test_check.user_id) | ||
|
||
def test_it_pops_bad_link_from_session(self): | ||
self.client.session["bad_link"] = True | ||
self.client.get("/accounts/login/") |
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.
Try putting in a bad link that gets popped out
@@ -41,10 +51,15 @@ def test_it_adds_team_member(self): | |||
member_emails.add(member.user.email) | |||
|
|||
### Assert the existence of the member emails | |||
self.assertEqual(len(member_emails), 2) #Alice included as member | |||
|
|||
self.assertTrue("frank@example.org" in member_emails) |
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.
DOn't hard code the email address
@@ -108,3 +123,20 @@ def test_it_shows_badges(self): | |||
self.assertNotContains(r, "bobs-tag.svg") |
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.
Assert that after adding a team member, an access allowed flag is present
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.
After reviewing the code, the user Charlie doesn't have team access enabled hence why the expected error code is a 403
because access is being denied. the test for successful adding of a team member is handled in test_it_adds_team_member
and the expected status code is 200
since Alice has team access enabled.
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.
I have worked on the changes. I believe the branch is ready for merging.
def test_it_redirects_if_already_logged_in(self): | ||
self.client.login(username="alice@example.org", password="password") | ||
response = self.client.get("/accounts/check_token/alice/secret-token/") | ||
assert response.status_code == 302 |
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.
maybe some consistency with the tests. If you are asserting the status code maybe assert for all
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 assert
is the main python assert and not the one for the base test class
@@ -20,18 +20,23 @@ def test_it_sends_link(self): | |||
assert r.status_code == 302 | |||
|
|||
### Assert that a user was created | |||
self.test_user = User.objects.get() |
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 is not a safe query when we have more than 1 user
@@ -20,18 +20,23 @@ def test_it_sends_link(self): | |||
assert r.status_code == 302 | |||
|
|||
### Assert that a user was created | |||
self.test_user = User.objects.get() | |||
self.assertEqual(self.test_user.email, "alice@example.org") |
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.
maybe a better logic to test is assert that there is no user with a particular email, then create a user with that email, then assert that a user with that email now exixts and that the count of User objects has incremented by one.
self.assertIsNotNone(self.alice.profile.api_key) | ||
self.assertContains(response, "The API key has been created!") | ||
|
||
|
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.
what plans do you have for those two spaces?
### Assert the contents of r | ||
### Assert the contents of response | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, "front/my_checks.html") | ||
|
||
|
||
def test_it_checks_team_membership(self): |
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.
maybe a better name for the test to have it less ambiguous
e550151
to
86f11d3
Compare
added uniform assertions for the redirect status code and PEP8 formatting added uniform assertions for the redirect status code and PEP8 formatting modified logic of testing for user creation and code for pep8 compliance minor edits to code to make assertions uniform and pep8 compliance minor edit to code for pep8 compliance and reworked logic for obtaining count of profile objects removed hardcoding of email in assertion test
86f11d3
to
8fcd36c
Compare
The unit tests are in the five files under
hc/accounts/tests
.The assigned tasks are under the comments in the
hc/accounts/tests
files.