test_helpers.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. from unittest import mock
  2. from sentry.plugins.helpers import get_option, set_option, unset_option
  3. from sentry.testutils.cases import TestCase
  4. class SentryPluginTest(TestCase):
  5. def test_set_option_with_project(self):
  6. with mock.patch("sentry.models.ProjectOption.objects.set_value") as set_value:
  7. project = mock.Mock()
  8. set_option("key", "value", project)
  9. set_value.assert_called_once_with(project, "key", "value")
  10. def test_get_option_with_project(self):
  11. with mock.patch("sentry.models.ProjectOption.objects.get_value") as get_value:
  12. project = mock.Mock()
  13. result = get_option("key", project)
  14. self.assertEqual(result, get_value.return_value)
  15. get_value.assert_called_once_with(project, "key", None)
  16. def test_unset_option_with_project(self):
  17. with mock.patch("sentry.models.ProjectOption.objects.unset_value") as unset_value:
  18. project = mock.Mock()
  19. unset_option("key", project)
  20. unset_value.assert_called_once_with(project, "key")