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.

59 lines
1.9 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. @override_settings(TRELLO_APP_KEY="foo")
  5. class AddTrelloTestCase(BaseTestCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.url = "/projects/%s/add_trello/" % self.project.code
  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, "Trello")
  13. def test_it_works(self):
  14. form = {
  15. "token": "0" * 64,
  16. "board_name": "My Board",
  17. "list_name": "My List",
  18. "list_id": "1" * 32,
  19. }
  20. self.client.login(username="[email protected]", password="password")
  21. r = self.client.post(self.url, form)
  22. self.assertRedirects(r, self.channels_url)
  23. c = Channel.objects.get()
  24. self.assertEqual(c.kind, "trello")
  25. self.assertEqual(c.trello_token, "0" * 64)
  26. self.assertEqual(c.project, self.project)
  27. @override_settings(TRELLO_APP_KEY=None)
  28. def test_it_requires_trello_app_key(self):
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get(self.url)
  31. self.assertEqual(r.status_code, 404)
  32. def test_it_requires_rw_access(self):
  33. self.bobs_membership.role = "r"
  34. self.bobs_membership.save()
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.get(self.url)
  37. self.assertEqual(r.status_code, 403)
  38. def test_it_requires_board_name(self):
  39. self.client.login(username="[email protected]", password="password")
  40. form = {
  41. "token": "0" * 64,
  42. "board_name": "",
  43. "list_name": "My List",
  44. "list_id": "1" * 32,
  45. }
  46. r = self.client.post(self.url, form)
  47. self.assertEqual(r.status_code, 400)