You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.5 KiB

  1. import json
  2. from django.test.utils import override_settings
  3. from hc.api.models import Channel
  4. from hc.test import BaseTestCase
  5. from mock import patch
  6. @override_settings(PUSHBULLET_CLIENT_ID="t1", PUSHBULLET_CLIENT_SECRET="s1")
  7. class AddPushbulletTestCase(BaseTestCase):
  8. def test_it_shows_instructions(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.get("/integrations/add_pushbullet/")
  11. self.assertContains(r, "www.pushbullet.com/authorize", status_code=200)
  12. @override_settings(PUSHBULLET_CLIENT_ID=None)
  13. def test_it_requires_client_id(self):
  14. self.client.login(username="[email protected]", password="password")
  15. r = self.client.get("/integrations/add_pushbullet/")
  16. self.assertEqual(r.status_code, 404)
  17. @patch("hc.front.views.requests.post")
  18. def test_it_handles_oauth_response(self, mock_post):
  19. oauth_response = {"access_token": "test-token"}
  20. mock_post.return_value.text = json.dumps(oauth_response)
  21. mock_post.return_value.json.return_value = oauth_response
  22. url = "/integrations/add_pushbullet/?code=12345678"
  23. self.client.login(username="[email protected]", password="password")
  24. r = self.client.get(url, follow=True)
  25. self.assertRedirects(r, "/integrations/")
  26. self.assertContains(r, "The Pushbullet integration has been added!")
  27. ch = Channel.objects.get()
  28. self.assertEqual(ch.value, "test-token")