test_referrer.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_common_suffixes(self, warn_log):
  29. assert warn_log.call_count == 0
  30. validate_referrer("api.performance.http.domain-summary-transactions-list")
  31. validate_referrer("api.performance.http.domain-summary-transactions-list.primary")
  32. validate_referrer("api.performance.http.domain-summary-transactions-list.secondary")
  33. assert warn_log.call_count == 0
  34. @patch("sentry.snuba.referrer.logger.warning")
  35. def test_referrer_validate_uncommon_suffixes(self, warn_log):
  36. assert warn_log.call_count == 0
  37. validate_referrer("api.performance.http.domain-summary-transactions-list.special")
  38. validate_referrer("api.performance.http.domain-summary-transactions-list.airyrpm")
  39. assert warn_log.call_count == 2
  40. @patch("sentry.snuba.referrer.logger.warning")
  41. def test_referrer_validate_tsdb_models(self, warn_log):
  42. assert warn_log.call_count == 0
  43. for model in TSDBModel:
  44. assert hasattr(Referrer, f"TSDB_MODELID_{model.value}")
  45. assert (
  46. getattr(Referrer, f"TSDB_MODELID_{model.value}").value
  47. == f"tsdb-modelid:{model.value}"
  48. )
  49. assert warn_log.call_count == 0
  50. @patch("sentry.snuba.referrer.logger.warning")
  51. def test_referrer_validate_base_enum_values(self, warn_log):
  52. assert warn_log.call_count == 0
  53. for i in Referrer:
  54. validate_referrer(i.value)
  55. assert warn_log.call_count == 0