Skip to content

Commit

Permalink
[Fix 155965532] fix tests assertion statement (from inbuilt python to…
Browse files Browse the repository at this point in the history
… django built)
  • Loading branch information
younggeeks committed Apr 4, 2018
1 parent c18c823 commit 01d0ffd
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 47 deletions.
4 changes: 2 additions & 2 deletions hc/front/tests/test_add_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_it_adds_email(self):
user = User.objects.get(email='alice@example.org')

self.assertRedirects(r, "/integrations/")
assert Channel.objects.count() == 1
self.assertEqual(Channel.objects.count(), 1)
self.assertEqual('alice@example.org', user.email)

def test_it_trims_whitespace(self):
Expand Down Expand Up @@ -71,4 +71,4 @@ def test_team_access_works(self):
self.zachary_profile.save()

self.assertEqual(True, self.profile.team_access_allowed)
self.assertEqual("thisisawesomesecretkey",self.zachary_profile.current_team.api_key)
self.assertEqual("thisisawesomesecretkey", self.zachary_profile.current_team.api_key)
8 changes: 3 additions & 5 deletions hc/front/tests/test_add_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ def test_it_works(self):
self.client.login(username="alice@example.org", password="password")
r = self.client.post(url)
self.assertRedirects(r, "/checks/")
assert Check.objects.count() == 1
self.assertEqual(Check.objects.count(), 1)

## Test that team access works
def test_team_access_works(self):
url = "/checks/add/"
self.client.login(username="alice@example.org", password="password")
Expand All @@ -20,13 +19,12 @@ def test_team_access_works(self):

self.client.login(username="bob@example.org", password="password")
self.client.post(url)
assert Check.objects.count() == 2
self.assertEqual(Check.objects.count(), 2)

def test_unauthorized_access_doesnt_work(self):
"""
Test if unauthorized user can add check
"""
url = "/checks/add/"
res = self.client.post(url)
assert res.status_code == 302

self.assertEqual(res.status_code, 302)
8 changes: 4 additions & 4 deletions hc/front/tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def test_it_shows_welcome(self):
def test_welcome_code(self):
r = self.client.get("/")
code = self.client.session["welcome_code"]
assert Check.objects.filter(code=code).exists()
self.assertIsNotNone(Check.objects.filter(code=code))

self.client.session["welcome_code"] = "x"
r = self.client.get("/")
code = self.client.session["welcome_code"]
assert r.status_code == 200
assert code != "x"
assert Check.objects.filter(code=code).exists()
self.assertEqual(r.status_code, 200)
self.assertNotEqual(code, "x")
self.assertIsNotNone(Check.objects.filter(code=code))
4 changes: 2 additions & 2 deletions hc/front/tests/test_channel_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def test_it_checks_owner(self):
url = "/integrations/%s/checks/" % self.channel.code
self.client.login(username="charlie@example.org", password="password")
r = self.client.get(url)
assert r.status_code == 403
self.assertEqual(r.status_code, 403)

def test_missing_channel(self):
# Valid UUID but there is no channel for it:
url = "/integrations/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/checks/"

self.client.login(username="alice@example.org", password="password")
r = self.client.get(url)
assert r.status_code == 404
self.assertEqual(r.status_code, 404)
6 changes: 3 additions & 3 deletions hc/front/tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ def test_it_handles_bad_uuid(self):

self.client.login(username="alice@example.org", password="password")
r = self.client.get(url)
assert r.status_code == 400
self.assertEqual(r.status_code, 400)

def test_it_handles_missing_uuid(self):
# Valid UUID but there is no check for it:
url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/log/"

self.client.login(username="alice@example.org", password="password")
r = self.client.get(url)
assert r.status_code == 404
self.assertEqual(r.status_code, 404)

def test_it_checks_ownership(self):
url = "/checks/%s/log/" % self.check.code
self.client.login(username="charlie@example.org", password="password")
r = self.client.get(url)
assert r.status_code == 403
self.assertEqual(r.status_code, 403)
10 changes: 5 additions & 5 deletions hc/front/tests/test_remove_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ def test_it_works(self):
r = self.client.post(url)
self.assertRedirects(r, "/integrations/")

assert Channel.objects.count() == 0
self.assertEqual(Channel.objects.count(),0)

def test_team_access_works(self):
url = "/integrations/%s/remove/" % self.channel.code

self.client.login(username="bob@example.org", password="password")
self.client.post(url)
assert Channel.objects.count() == 0
self.assertEqual(Channel.objects.count(),0)

def test_it_handles_bad_uuid(self):
url = "/integrations/not-uuid/remove/"

self.client.login(username="alice@example.org", password="password")
r = self.client.post(url)
assert r.status_code == 400
self.assertEqual(r.status_code,400)

def test_it_checks_owner(self):
url = "/integrations/%s/remove/" % self.channel.code

self.client.login(username="charlie@example.org", password="password")
r = self.client.post(url)
assert r.status_code == 403
self.assertEqual(r.status_code,403)

def test_it_handles_missing_uuid(self):
# Valid UUID but there is no channel for it:
url = "/integrations/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/remove/"

self.client.login(username="alice@example.org", password="password")
r = self.client.post(url)
assert r.status_code == 302
self.assertEqual(r.status_code,302)
10 changes: 5 additions & 5 deletions hc/front/tests/test_remove_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_it_works(self):
r = self.client.post(url)
self.assertRedirects(r, "/checks/")

assert Check.objects.count() == 0
self.assertEqual(Check.objects.count(), 0)

def test_team_access_works(self):
url = "/checks/%s/remove/" % self.check.code
Expand All @@ -25,26 +25,26 @@ def test_team_access_works(self):
# should work.
self.client.login(username="bob@example.org", password="password")
self.client.post(url)
assert Check.objects.count() == 0
self.assertEqual(Check.objects.count(), 0)

def test_it_handles_bad_uuid(self):
url = "/checks/not-uuid/remove/"

self.client.login(username="alice@example.org", password="password")
r = self.client.post(url)
assert r.status_code == 400
self.assertEqual(r.status_code, 400)

def test_it_checks_owner(self):
url = "/checks/%s/remove/" % self.check.code

self.client.login(username="charlie@example.org", password="password")
r = self.client.post(url)
assert r.status_code == 403
self.assertEqual(r.status_code, 403)

def test_it_handles_missing_uuid(self):
# Valid UUID but there is no check for it:
url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/remove/"

self.client.login(username="alice@example.org", password="password")
r = self.client.post(url)
assert r.status_code == 404
self.assertEqual(r.status_code, 404)
12 changes: 6 additions & 6 deletions hc/front/tests/test_update_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_it_works(self):

channel = Channel.objects.get(code=self.channel.code)
checks = channel.checks.all()
assert len(checks) == 1
assert checks[0].code == self.check.code
self.assertEqual(len(checks), 1)
self.assertEqual(checks[0].code, self.check.code)

def test_team_access_works(self):
payload = {
Expand All @@ -47,7 +47,7 @@ def test_it_checks_channel_user(self):
r = self.client.post("/integrations/", data=payload)

# self.channel does not belong to charlie, this should fail--
assert r.status_code == 403
self.assertEqual(r.status_code, 403)

def test_it_checks_check_user(self):
charlies_channel = Channel(user=self.charlie, kind="email")
Expand All @@ -62,15 +62,15 @@ def test_it_checks_check_user(self):
r = self.client.post("/integrations/", data=payload)

# mc belongs to charlie but self.check does not--
assert r.status_code == 403
self.assertEqual(r.status_code, 403)

def test_it_handles_missing_channel(self):
# Correct UUID but there is no channel for it:
payload = {"channel": "6837d6ec-fc08-4da5-a67f-08a9ed1ccf62"}

self.client.login(username="alice@example.org", password="password")
r = self.client.post("/integrations/", data=payload)
assert r.status_code == 400
self.assertEqual(r.status_code, 400)

def test_it_handles_missing_check(self):
# check- key has a correct UUID but there's no check object for it
Expand All @@ -81,4 +81,4 @@ def test_it_handles_missing_check(self):

self.client.login(username="alice@example.org", password="password")
r = self.client.post("/integrations/", data=payload)
assert r.status_code == 400
self.assertEqual(r.status_code, 400)
10 changes: 5 additions & 5 deletions hc/front/tests/test_update_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_it_works(self):
self.assertRedirects(r, "/checks/")

check = Check.objects.get(code=self.check.code)
assert check.name == "Alice Was Here"
self.assertEqual(check.name,"Alice Was Here")

def test_team_access_works(self):
url = "/checks/%s/name/" % self.check.code
Expand All @@ -30,23 +30,23 @@ def test_team_access_works(self):
self.client.post(url, data=payload)

check = Check.objects.get(code=self.check.code)
assert check.name == "Bob Was Here"
self.assertEqual(check.name,"Bob Was Here")

def test_it_checks_ownership(self):
url = "/checks/%s/name/" % self.check.code
payload = {"name": "Charlie Sent This"}

self.client.login(username="charlie@example.org", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 403
self.assertEqual(r.status_code,403)

def test_it_handles_bad_uuid(self):
url = "/checks/not-uuid/name/"
payload = {"name": "Alice Was Here"}

self.client.login(username="alice@example.org", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 400
self.assertEqual(r.status_code,400)

def test_it_handles_missing_uuid(self):
# Valid UUID but there is no check for it:
Expand All @@ -55,7 +55,7 @@ def test_it_handles_missing_uuid(self):

self.client.login(username="alice@example.org", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 404
self.assertEqual(r.status_code,404)

def test_it_sanitizes_tags(self):
url = "/checks/%s/name/" % self.check.code
Expand Down
10 changes: 5 additions & 5 deletions hc/front/tests/test_update_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_it_works(self):

check = Check.objects.get(code=self.check.code)
assert check.timeout.total_seconds() == 3600
assert check.grace.total_seconds() == 60
self.assertEqual(check.grace.total_seconds(),60)

def test_team_access_works(self):
url = "/checks/%s/timeout/" % self.check.code
Expand All @@ -31,15 +31,15 @@ def test_team_access_works(self):
self.client.post(url, data=payload)

check = Check.objects.get(code=self.check.code)
assert check.timeout.total_seconds() == 7200
self.assertEqual(check.timeout.total_seconds(),7200)

def test_it_handles_bad_uuid(self):
url = "/checks/not-uuid/timeout/"
payload = {"timeout": 3600, "grace": 60}

self.client.login(username="alice@example.org", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 400
self.assertEqual(r.status_code,400)

def test_it_handles_missing_uuid(self):
# Valid UUID but there is no check for it:
Expand All @@ -48,12 +48,12 @@ def test_it_handles_missing_uuid(self):

self.client.login(username="alice@example.org", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 404
self.assertEqual(r.status_code,404)

def test_it_checks_ownership(self):
url = "/checks/%s/timeout/" % self.check.code
payload = {"timeout": 3600, "grace": 60}

self.client.login(username="charlie@example.org", password="password")
r = self.client.post(url, data=payload)
assert r.status_code == 403
self.assertEqual(r.status_code,403)
10 changes: 5 additions & 5 deletions hc/front/tests/test_verify_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ def test_it_works(self):
url = "/integrations/%s/verify/%s/" % (self.channel.code, token)

r = self.client.post(url)
assert r.status_code == 200, r.status_code
self.assertEqual(r.status_code,200)

channel = Channel.objects.get(code=self.channel.code)
assert channel.email_verified
self.assertEqual(channel.email_verified,True)

def test_it_handles_bad_token(self):
url = "/integrations/%s/verify/bad-token/" % self.channel.code

r = self.client.post(url)
assert r.status_code == 200, r.status_code
self.assertEqual(r.status_code,200)

channel = Channel.objects.get(code=self.channel.code)
assert not channel.email_verified
self.assertNotEqual(channel.email_verified,True)

def test_missing_channel(self):
# Valid UUID, and even valid token but there is no channel for it:
Expand All @@ -36,4 +36,4 @@ def test_missing_channel(self):
url = "/integrations/%s/verify/%s/" % (code, token)

r = self.client.post(url)
assert r.status_code == 404
self.assertEqual(r.status_code,404)

0 comments on commit 01d0ffd

Please sign in to comment.