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.

36 lines
1.2 KiB

  1. from hc.api.models import Channel
  2. from hc.test import BaseTestCase
  3. from mock import patch
  4. class AddHipChatTestCase(BaseTestCase):
  5. url = "/integrations/add_hipchat/"
  6. def test_instructions_work(self):
  7. self.client.login(username="[email protected]", password="password")
  8. r = self.client.get(self.url)
  9. self.assertContains(r, "appropriate HipChat room")
  10. def test_it_returns_capabilities(self):
  11. r = self.client.get("/integrations/hipchat/capabilities/")
  12. self.assertContains(r, "installedUrl")
  13. @patch("hc.front.views.Channel.refresh_hipchat_access_token")
  14. @patch("hc.front.views.requests.get")
  15. def test_it_adds_channel(self, mock_get, mock_refresh):
  16. mock_get.return_value.json.return_value = {
  17. "oauthId": "test-id"
  18. }
  19. mock_get.return_value.text = "{}"
  20. self.client.login(username="[email protected]", password="password")
  21. s = "https://api.hipchat.com/foo"
  22. r = self.client.post(self.url + "?installable_url=%s" % s)
  23. self.assertEqual(r.status_code, 302)
  24. self.assertTrue(mock_refresh.called)
  25. c = Channel.objects.get()
  26. self.assertEqual(c.kind, "hipchat")
  27. self.assertEqual(c.value, "{}")