-
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
Changes from 13 commits
d76b231
ad7464b
fcb696b
07d809b
36977ae
4d7fb5c
6fce4c8
314f09e
5a91463
9930679
eb4e75d
595668c
312bf7b
a89963c
4e67c3f
9613121
8fcd36c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
self.assertEqual(self.test_user.email, "alice@example.org") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
# And email sent | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual(mail.outbox[0].subject, 'Log in to healthchecks.io') | ||
### Assert contents of the email body | ||
self.assertIn("To log into healthchecks.io, please open the link below", | ||
mail.outbox[0].body) | ||
|
||
### Assert that check is associated with the new user | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Try putting in a bad link that gets popped out |
||
assert "bad_link" not in self.client.session | ||
|
||
### Any other tests? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,14 @@ def test_it_sends_set_password_link(self): | |
self.alice.profile.refresh_from_db() | ||
token = self.alice.profile.token | ||
### Assert that the token is set | ||
self.assertTrue(len(token)>10) | ||
|
||
### Assert that the email was sent and check email content | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual("Set password on healthchecks.io", | ||
mail.outbox[0].subject) | ||
self.assertIn("Here's a link to set a password for your account on", | ||
mail.outbox[0].body) | ||
|
||
def test_it_sends_report(self): | ||
check = Check(name="Test Check", user=self.alice) | ||
|
@@ -28,6 +34,10 @@ def test_it_sends_report(self): | |
self.alice.profile.send_report() | ||
|
||
###Assert that the email was sent and check email content | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual("Monthly Report", mail.outbox[0].subject) | ||
self.assertIn("This is a monthly report sent by healthchecks.io.", | ||
mail.outbox[0].body) | ||
|
||
def test_it_adds_team_member(self): | ||
self.client.login(username="alice@example.org", password="password") | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. DOn't hard code the email address |
||
|
||
###Assert that the email was sent and check email content | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertIn("You have been invited to join", mail.outbox[0].subject) | ||
self.assertIn("invites you to their healthchecks.io account", | ||
mail.outbox[0].body) | ||
|
||
def test_add_team_member_checks_team_access_allowed_flag(self): | ||
self.client.login(username="charlie@example.org", password="password") | ||
|
@@ -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 commentThe 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 commentThe 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 |
||
|
||
### Test it creates and revokes API key | ||
def test_it_creates_and_revokes_api_key(self): | ||
self.client.login(username="alice@example.org", password="password") | ||
form = {"create_api_key":"1"} | ||
r = self.client.post("/accounts/profile/", form) | ||
|
||
assert r.status_code==200 | ||
self.assertIsNotNone(self.alice.profile.api_key) | ||
self.assertContains(r, "The API key has been created!") | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what plans do you have for those two spaces? |
||
form_revoke = {"revoke_api_key":"1"} | ||
r = self.client.post("/accounts/profile/", form_revoke) | ||
|
||
assert r.status_code==200 | ||
self.alice.profile.refresh_from_db() | ||
self.assertEqual(self.alice.profile.api_key, "") | ||
self.assertContains(r, "The API key has been revoked!") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ def test_it_switches(self): | |
r = self.client.get(url, follow=True) | ||
|
||
### Assert the contents of r | ||
self.assertEqual(r.status_code, 200) | ||
self.assertTemplateUsed(r, "front/my_checks.html") | ||
|
||
|
||
def test_it_checks_team_membership(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a better name for the test to have it less ambiguous |
||
|
@@ -22,10 +24,12 @@ def test_it_checks_team_membership(self): | |
url = "/accounts/switch_team/%s/" % self.alice.username | ||
r = self.client.get(url) | ||
### Assert the expected error code | ||
assert r.status_code == 403 | ||
|
||
def test_it_switches_to_own_team(self): | ||
self.client.login(username="alice@example.org", password="password") | ||
|
||
url = "/accounts/switch_team/%s/" % self.alice.username | ||
r = self.client.get(url, follow=True) | ||
### Assert the expected error code | ||
assert r.status_code == 200 |
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