test_pivotal_plugin.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from functools import cached_property
  2. from django.urls import reverse
  3. from sentry.testutils.cases import PluginTestCase
  4. from sentry.utils import json
  5. from sentry_plugins.pivotal.plugin import PivotalPlugin
  6. class PivotalPluginTest(PluginTestCase):
  7. @cached_property
  8. def plugin(self):
  9. return PivotalPlugin()
  10. def test_conf_key(self):
  11. assert self.plugin.conf_key == "pivotal"
  12. def test_entry_point(self):
  13. self.assertPluginInstalled("pivotal", self.plugin)
  14. def test_get_issue_label(self):
  15. group = self.create_group(message="Hello world", culprit="foo.bar")
  16. assert self.plugin.get_issue_label(group, 1) == "#1"
  17. def test_get_issue_url(self):
  18. group = self.create_group(message="Hello world", culprit="foo.bar")
  19. assert self.plugin.get_issue_url(group, 1) == "https://www.pivotaltracker.com/story/show/1"
  20. def test_is_configured(self):
  21. assert self.plugin.is_configured(None, self.project) is False
  22. self.plugin.set_option("token", "1", self.project)
  23. self.plugin.set_option("project", "1", self.project)
  24. assert self.plugin.is_configured(None, self.project) is True
  25. def test_no_secrets(self):
  26. self.user = self.create_user("foo@example.com")
  27. self.org = self.create_organization(owner=self.user, name="Rowdy Tiger")
  28. self.team = self.create_team(organization=self.org, name="Mariachi Band")
  29. self.project = self.create_project(organization=self.org, teams=[self.team], name="Bengal")
  30. self.login_as(self.user)
  31. self.plugin.set_option("token", "abcdef", self.project)
  32. url = reverse(
  33. "sentry-api-0-project-plugin-details",
  34. args=[self.org.slug, self.project.slug, "pivotal"],
  35. )
  36. res = self.client.get(url)
  37. config = json.loads(res.content)["config"]
  38. token_config = [item for item in config if item["name"] == "token"][0]
  39. assert token_config.get("type") == "secret"
  40. assert token_config.get("value") is None
  41. assert token_config.get("hasSavedValue") is True
  42. assert token_config.get("prefix") == "abcd"