test_plugin.py 2.2 KB

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