test_plugin.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from functools import cached_property
  2. import responses
  3. from django.test import RequestFactory
  4. from pytest import raises
  5. from sentry.exceptions import PluginError
  6. from sentry.testutils.cases import PluginTestCase
  7. from sentry.testutils.helpers import override_blocklist
  8. from sentry_plugins.phabricator.plugin import PhabricatorPlugin
  9. class PhabricatorPluginTest(PluginTestCase):
  10. @cached_property
  11. def plugin(self):
  12. return PhabricatorPlugin()
  13. @cached_property
  14. def request(self):
  15. return RequestFactory()
  16. def test_conf_key(self):
  17. assert self.plugin.conf_key == "phabricator"
  18. def test_entry_point(self):
  19. self.assertPluginInstalled("phabricator", self.plugin)
  20. def test_get_issue_label(self):
  21. group = self.create_group(message="Hello world", culprit="foo.bar")
  22. assert self.plugin.get_issue_label(group, 1) == "T1"
  23. @responses.activate
  24. def test_get_issue_url(self):
  25. self.plugin.set_option("host", "http://secure.phabricator.org", self.project)
  26. group = self.create_group(message="Hello world", culprit="foo.bar")
  27. assert self.plugin.get_issue_url(group, "1") == "http://secure.phabricator.org/T1"
  28. def test_is_configured(self):
  29. assert self.plugin.is_configured(None, self.project) is False
  30. self.plugin.set_option("host", "http://secure.phabricator.org", self.project)
  31. assert self.plugin.is_configured(None, self.project) is False
  32. self.plugin.set_option("token", "12345678-1234-1234-1234-1234567890AB", self.project)
  33. assert self.plugin.is_configured(None, self.project) is True
  34. self.plugin.unset_option("token", self.project)
  35. self.plugin.set_option("username", "a-user", self.project)
  36. assert self.plugin.is_configured(None, self.project) is False
  37. self.plugin.set_option("certificate", "a-certificate", self.project)
  38. assert self.plugin.is_configured(None, self.project) is True
  39. @override_blocklist("127.0.0.1")
  40. def test_invalid_url(self):
  41. with raises(PluginError):
  42. self.plugin.validate_config_field(
  43. project=self.project, name="host", value="ftp://example.com"
  44. )
  45. with raises(PluginError):
  46. self.plugin.validate_config_field(
  47. project=self.project, name="host", value="http://127.0.0.1"
  48. )