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.

61 lines
1.9 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().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. "token": "0" * 64,
  17. "board_name": "My Board",
  18. "list_name": "My List",
  19. "list_id": "1" * 32,
  20. }
  21. self.client.login(username="[email protected]", password="password")
  22. r = self.client.post(self.url, form)
  23. self.assertRedirects(r, self.channels_url)
  24. c = Channel.objects.get()
  25. self.assertEqual(c.kind, "trello")
  26. self.assertEqual(c.trello_token, "0" * 64)
  27. self.assertEqual(c.project, self.project)
  28. @override_settings(TRELLO_APP_KEY=None)
  29. def test_it_requires_trello_app_key(self):
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.get(self.url)
  32. self.assertEqual(r.status_code, 404)
  33. def test_it_requires_rw_access(self):
  34. self.bobs_membership.rw = False
  35. self.bobs_membership.save()
  36. self.client.login(username="[email protected]", password="password")
  37. r = self.client.get(self.url)
  38. self.assertEqual(r.status_code, 403)
  39. def test_it_requires_board_name(self):
  40. self.client.login(username="[email protected]", password="password")
  41. form = {
  42. "token": "0" * 64,
  43. "board_name": "",
  44. "list_name": "My List",
  45. "list_id": "1" * 32,
  46. }
  47. r = self.client.post(self.url, form)
  48. self.assertEqual(r.status_code, 400)