Skip to content

Commit

Permalink
Merge branch 'develop' into ft-fixing-api-tests-#156687690
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmykamau committed May 2, 2018
2 parents e724b04 + 5357f7c commit 124e609
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 28 deletions.
17 changes: 4 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
POSTGRES_USER: root
POSTGRES_DB: circle_test
steps:

- checkout
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.6/site-packages
Expand All @@ -21,6 +22,7 @@ jobs:
command: |
sudo pip install pipenv
pipenv install
wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
- save_cache:
key: deps9-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
paths:
Expand All @@ -30,21 +32,10 @@ jobs:
- run:
command: |
pipenv run "python manage.py test"
- store_test_results:
path: test-results
- store_artifacts:
path: test-results
destination: tr1
deploy-job:
docker:
- image: my-image
working_directory: /tmp/hc-bulls
steps:
- checkout
- run:
- deploy:
name: Deploy develop to Heroku
command: | # this command is framework-dependent and may vary
command: |
heroku git:remote -a hc-bullss
git push --force https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD:refs/heads/master
sleep 5 # sleep for 5 seconds to wait for dynos
Expand Down
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[report]
omit = *migrations*
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ static-collected

.DS_Store
static/.DS_Store
.vscode/*
.vscode/*
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![CircleCI](https://circleci.com/gh/andela/hc-bulls/tree/develop.svg?style=svg)](https://circleci.com/gh/andela/hc-bulls/tree/develop)
[![Coverage Status](https://coveralls.io/repos/github/andela/hc-bulls/badge.svg?branch=develop)](https://coveralls.io/github/andela/hc-bulls?branch=develop)
# healthchecks

![Screenshot of Welcome page](/stuff/screenshots/welcome.png?raw=true "Welcome Page")
Expand Down Expand Up @@ -178,9 +180,9 @@ There are separate Django management commands for each task:
$ ./manage.py pruneusers
```

When you first try these commands on your data, it is a good idea to
test them on a copy of your database, not on the live database right away.
In a production setup, you should also have regular, automated database
When you first try these commands on your data, it is a good idea to
test them on a copy of your database, not on the live database right away.
In a production setup, you should also have regular, automated database
backups set up.

## Integrations
Expand Down
17 changes: 15 additions & 2 deletions hc/accounts/tests/test_check_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ def test_it_redirects(self):
self.assertEqual(self.profile.token, "")

### Login and test it redirects already logged in
def test_it_redirects_already_logged_in(self):
# Login
self.client.login(username="alice@example.org", password="password")
# Login again, check it redirects
url = "/accounts/check_token/alice/secret-token/"
r = self.client.post(url)
self.assertRedirects(r, "/checks/")

### Login with a bad token and check that it redirects

### Any other tests?
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)
self.assertRedirects(r, "/accounts/login/")
self.assertContains(r, "incorrect or expired")

### Any other tests?
13 changes: 8 additions & 5 deletions hc/accounts/tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ def test_it_sends_link(self):
r = self.client.post("/accounts/login/", form)
assert r.status_code == 302

### Assert that a user was created
# Assert that a user was created
self.assertEqual(User.objects.count(), 1)

# 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
# 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
# Assert that check is associated with the new user
get_check = Check.objects.get(code=check.code)
self.assertEqual(get_check.user, User.objects.get(email='alice@example.org'))

def test_it_pops_bad_link_from_session(self):
self.client.session["bad_link"] = True
self.client.get("/accounts/login/")
assert "bad_link" not in self.client.session

### Any other tests?

# Any other tests?
29 changes: 25 additions & 4 deletions hc/accounts/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(token)

### Assert that the email was sent and check email content
# Assert that the email was sent and check email content
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject,
"Set password on healthchecks.io")

def test_it_sends_report(self):
check = Check(name="Test Check", user=self.alice)
check.save()

self.alice.profile.send_report()

###Assert that the email was sent and check email content
### Assert that the email was sent and check email content
self.assertEqual(len(mail.outbox), 1)
message = mail.outbox[0]

self.assertEqual(message.subject, 'Monthly Report')
self.assertIn("This is a monthly report sent by healthchecks.io", message.body)

def test_it_adds_team_member(self):
self.client.login(username="alice@example.org", password="password")
Expand All @@ -41,10 +50,12 @@ 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)

self.assertTrue("frank@example.org" in member_emails)

###Assert that the email was sent and check email content
### Assert that the email was sent and check email content
self.assertEqual(mail.outbox[0].subject, 'You have been invited to join alice@example.org on healthchecks.io')

def test_add_team_member_checks_team_access_allowed_flag(self):
self.client.login(username="charlie@example.org", password="password")
Expand Down Expand Up @@ -108,3 +119,13 @@ def test_it_shows_badges(self):
self.assertNotContains(r, "bobs-tag.svg")

### Test it creates and revokes API key
def test_it_revokes_api_key(self):
self.client.login(username="alice@example.org", password="password")

form = {"revoke_api_key": "1"}
r = self.client.post("/accounts/profile/", form)
assert r.status_code == 200

self.profile.refresh_from_db()
self.assertEqual(self.profile.api_key, "")

3 changes: 3 additions & 0 deletions hc/accounts/tests/test_switch_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_it_switches(self):
r = self.client.get(url, follow=True)

### Assert the contents of r
self.assertContains(r, "This belongs to Alice")


def test_it_checks_team_membership(self):
Expand All @@ -22,10 +23,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
self.assertEqual(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
self.assertEqual(r.status_code, 200)
1 change: 1 addition & 0 deletions hc/accounts/tests/test_team_access_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ def test_it_handles_missing_profile(self):
self.assertEqual(r.status_code, 200)

### Assert the new Profile objects count
self.assertEqual(Profile.objects.count(), 1)
20 changes: 20 additions & 0 deletions hc/front/tests/test_add_channel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.test.utils import override_settings
from django.contrib.auth.models import User

from hc.api.models import Channel
from hc.test import BaseTestCase
Expand Down Expand Up @@ -38,4 +39,23 @@ def test_instructions_work(self):
self.assertContains(r, "Integration Settings", status_code=200)

### Test that the team access works
def test_team_access_works(self):
""" test a team access"""
alice_channel = User.objects.get(email="alice@example.org")
alice_before = Channel.objects.filter(user=alice_channel).count()
self.client.login(username="bob@example.org", password="password")
url = "/integrations/add/"
form = {"kind": "hipchat"}
self.client.post(url, form)
alice_after = Channel.objects.filter(user=alice_channel).count()
self.assertEqual(alice_after, (alice_before + 1))

### Test that bad kinds don't work
def test_bad_kinds_dont_work(self):
"""Test that bad kinds don't work"""
url = "/integrations/add/"
form = {"kind": "bad_kind", "value": "alice@example.org"}
self.client.login(username="alice@example.org", password="password")
response = self.client.post(url, form)
self.assertEquals(response.status_code, 400)

11 changes: 11 additions & 0 deletions hc/front/tests/test_add_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ def test_it_works(self):
assert Check.objects.count() == 1

### Test that team access works
def test_team_work_access(self):
'''Checks that people of the same team can see each others checks'''
url = "/checks/add/"
self.client.login(username="alice@example.org", password="password")
self.client.post(url)
self.client.logout()

# login another user
self.client.login(username="bob@example.org", password="password")
self.client.post(url)
assert Check.objects.count() == 2
10 changes: 10 additions & 0 deletions hc/front/tests/test_add_pushbover.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ def test_it_validates_nonce(self):
assert r.status_code == 403

### Test that pushover validates priority
def test_it_validates_priority(self):
self.client.login(username="alice@example.org", password="password")

session = self.client.session
session["pushover"] = "foo"
session.save()

params = "pushover_user_key=a&state=foo&prio=abc"
r = self.client.get("/integrations/add_pushover/?%s" % params)
self.assertEqual(r.status_code, 400)

0 comments on commit 124e609

Please sign in to comment.