test_organization_plugins.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from __future__ import absolute_import
  2. from django.core.urlresolvers import reverse
  3. from sentry.plugins import plugins
  4. from sentry.testutils import APITestCase
  5. class OrganizationPluginsTest(APITestCase):
  6. def setUp(self):
  7. self.projectA = self.create_project()
  8. self.projectB = self.create_project(organization=self.projectA.organization)
  9. plugins.get('webhooks').enable(self.projectA)
  10. plugins.get('mail').enable(self.projectB)
  11. self.login_as(user=self.user)
  12. def test_exposes_plugins_across_all_org_projects(self):
  13. url = reverse(
  14. 'sentry-api-0-organization-plugins',
  15. kwargs={'organization_slug': self.projectA.organization.slug}
  16. )
  17. url = u'{}?{}'.format(url, 'plugins=mail&plugins=webhooks')
  18. response = self.client.get(url)
  19. assert response.status_code == 200, \
  20. (response.status_code, response.content)
  21. enabled_plugins = [
  22. (p['project']['id'], p['slug']) for p in
  23. filter(lambda p: p['enabled'], response.data)
  24. ]
  25. assert (self.projectA.id, 'webhooks') in enabled_plugins
  26. assert (self.projectB.id, 'mail') in enabled_plugins
  27. def test_exposes_specific_plugins_across_all_org_projects(self):
  28. url = reverse(
  29. 'sentry-api-0-organization-plugins',
  30. kwargs={'organization_slug': self.projectA.organization.slug}
  31. )
  32. url = '{}?plugins=mail'.format(url)
  33. response = self.client.get(url)
  34. assert response.status_code == 200, \
  35. (response.status_code, response.content)
  36. enabled_plugins = [
  37. (p['project']['id'], p['slug']) for p in
  38. filter(lambda p: p['enabled'], response.data)
  39. ]
  40. assert (self.projectA.id, 'webhooks') not in enabled_plugins
  41. assert (self.projectB.id, 'mail') in enabled_plugins