test_referrer.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from unittest import TestCase
  2. from unittest.mock import patch
  3. from sentry.snuba.referrer import Referrer, validate_referrer
  4. from sentry.tsdb.base import TSDBModel
  5. class ReferrerTest(TestCase):
  6. @patch("sentry.snuba.referrer.logger.warning")
  7. def test_referrer_validate_not_exist(self, warn_log):
  8. assert warn_log.call_count == 0
  9. validate_referrer("does_not_exist")
  10. assert warn_log.call_count == 1
  11. @patch("sentry.snuba.referrer.logger.warning")
  12. def test_referrer_validate_dynamic_tsdb_model(self, warn_log):
  13. assert warn_log.call_count == 0
  14. for model in TSDBModel:
  15. validate_referrer(f"tsdb-modelid:{model.value}")
  16. assert warn_log.call_count == 0
  17. @patch("sentry.snuba.referrer.logger.warning")
  18. def test_referrer_validate_tsdb_model_with_suffix(self, warn_log):
  19. assert warn_log.call_count == 0
  20. validate_referrer("tsdb-modelid:300.user_count_snoozes")
  21. assert warn_log.call_count == 0
  22. validate_referrer("tsdb-modelid:4.frequency_snoozes")
  23. assert warn_log.call_count == 0
  24. # tsdb-modelid:4 doesn't use the `user_count_snoozes` suffix
  25. validate_referrer("tsdb-modelid:4.user_count_snoozes")
  26. assert warn_log.call_count == 1
  27. @patch("sentry.snuba.referrer.logger.warning")
  28. def test_referrer_validate_tsdb_models(self, warn_log):
  29. assert warn_log.call_count == 0
  30. for model in TSDBModel:
  31. assert hasattr(Referrer, f"TSDB_MODELID_{model.value}")
  32. assert (
  33. getattr(Referrer, f"TSDB_MODELID_{model.value}").value
  34. == f"tsdb-modelid:{model.value}"
  35. )
  36. assert warn_log.call_count == 0
  37. @patch("sentry.snuba.referrer.logger.warning")
  38. def test_referrer_validate_base_enum_values(self, warn_log):
  39. assert warn_log.call_count == 0
  40. for i in Referrer:
  41. validate_referrer(i.value)
  42. assert warn_log.call_count == 0