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.

44 lines
1.6 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. url = "/integrations/add_pushbullet/"
  9. def test_instructions_work(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.get(self.url)
  12. self.assertContains(r, "Connect Pushbullet")
  13. def test_it_shows_instructions(self):
  14. self.client.login(username="[email protected]", password="password")
  15. r = self.client.get(self.url)
  16. self.assertContains(r, "www.pushbullet.com/authorize", status_code=200)
  17. @override_settings(PUSHBULLET_CLIENT_ID=None)
  18. def test_it_requires_client_id(self):
  19. self.client.login(username="[email protected]", password="password")
  20. r = self.client.get(self.url)
  21. self.assertEqual(r.status_code, 404)
  22. @patch("hc.front.views.requests.post")
  23. def test_it_handles_oauth_response(self, mock_post):
  24. oauth_response = {"access_token": "test-token"}
  25. mock_post.return_value.text = json.dumps(oauth_response)
  26. mock_post.return_value.json.return_value = oauth_response
  27. url = self.url + "?code=12345678"
  28. self.client.login(username="[email protected]", password="password")
  29. r = self.client.get(url, follow=True)
  30. self.assertRedirects(r, "/integrations/")
  31. self.assertContains(r, "The Pushbullet integration has been added!")
  32. ch = Channel.objects.get()
  33. self.assertEqual(ch.value, "test-token")