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.

35 lines
1.1 KiB

  1. import json
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. from mock import patch
  5. class ChannelModelTestCase(BaseTestCase):
  6. @patch("hc.api.models.requests.post")
  7. @patch("hc.api.models.requests.get")
  8. def test_it_refreshes_hipchat_access_token(self, mock_get, mock_post):
  9. mock_get.return_value.json.return_value = {
  10. "capabilities": {
  11. "oauth2Provider": {"tokenUrl": "http://example.org"}
  12. }
  13. }
  14. mock_post.return_value.json.return_value = {"expires_in": 100}
  15. channel = Channel(kind="hipchat", user=self.alice, value=json.dumps({
  16. "oauthId": "foo",
  17. "oauthSecret": "bar",
  18. "capabilitiesUrl": "http://example.org/capabilities.json"
  19. }))
  20. channel.refresh_hipchat_access_token()
  21. # It should fetch the remote capabilities document
  22. mock_get.assert_called()
  23. # It should request a token using a correct tokenUrl
  24. mock_post.assert_called()
  25. args, kwargs = mock_post.call_args
  26. self.assertEqual(args[0], "http://example.org")
  27. self.assertTrue("expires_at" in channel.value)