test_referrer.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from unittest import TestCase
  2. from unittest.mock import patch
  3. from sentry.snuba.referrer import ReferrerBase, 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_base_enum_values(self, warn_log):
  29. assert warn_log.call_count == 0
  30. for i in ReferrerBase:
  31. validate_referrer(i.value)
  32. assert warn_log.call_count == 0