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.

52 lines
1.7 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. @override_settings(TRELLO_APP_KEY="foo")
  6. class AddTrelloTestCase(BaseTestCase):
  7. def setUp(self):
  8. super(AddTrelloTestCase, self).setUp()
  9. self.url = "/projects/%s/add_trello/" % self.project.code
  10. def test_instructions_work(self):
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.get(self.url)
  13. self.assertContains(r, "Trello")
  14. def test_it_works(self):
  15. form = {
  16. "settings": json.dumps(
  17. {
  18. "token": "fake-token",
  19. "board_name": "My Board",
  20. "list_name": "My List",
  21. "list_id": "fake-list-id",
  22. }
  23. )
  24. }
  25. self.client.login(username="[email protected]", password="password")
  26. r = self.client.post(self.url, form)
  27. self.assertRedirects(r, self.channels_url)
  28. c = Channel.objects.get()
  29. self.assertEqual(c.kind, "trello")
  30. self.assertEqual(c.trello_token, "fake-token")
  31. self.assertEqual(c.project, self.project)
  32. @override_settings(TRELLO_APP_KEY=None)
  33. def test_it_requires_trello_app_key(self):
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.get(self.url)
  36. self.assertEqual(r.status_code, 404)
  37. def test_it_requires_rw_access(self):
  38. self.bobs_membership.rw = False
  39. self.bobs_membership.save()
  40. self.client.login(username="[email protected]", password="password")
  41. r = self.client.get(self.url)
  42. self.assertEqual(r.status_code, 403)