test_killswitches.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from sentry.killswitches import _value_matches, normalize_value
  2. def test_normalize_value():
  3. assert normalize_value("store.load-shed-group-creation-projects", [1, 2, 3]) == [
  4. {"project_id": "1", "platform": None},
  5. {"project_id": "2", "platform": None},
  6. {"project_id": "3", "platform": None},
  7. ]
  8. assert normalize_value("store.load-shed-group-creation-projects", [{"project_id": 123}]) == [
  9. {"project_id": "123", "platform": None}, # match any platform
  10. ]
  11. def test_value_matches():
  12. assert _value_matches(
  13. "store.load-shed-group-creation-projects",
  14. [
  15. {"project_id": "1"},
  16. {"project_id": "2"},
  17. {"project_id": "3"},
  18. ],
  19. {"project_id": 2},
  20. )
  21. assert _value_matches(
  22. "store.load-shed-group-creation-projects",
  23. [
  24. {"project_id": 1},
  25. {"project_id": 2},
  26. {"project_id": 3},
  27. ],
  28. {"project_id": 2},
  29. )
  30. assert not _value_matches(
  31. "store.load-shed-group-creation-projects",
  32. [
  33. {"project_id": "1"},
  34. {"project_id": "2"},
  35. {"project_id": "3"},
  36. ],
  37. {"project_id": 4},
  38. )
  39. assert not _value_matches("store.load-shed-group-creation-projects", [], {"project_id": 3})
  40. assert not _value_matches(
  41. "store.load-shed-group-creation-projects",
  42. [{"project_id": 2, "platform": None}],
  43. {"project_id": 3},
  44. )
  45. assert not _value_matches(
  46. "store.load-shed-group-creation-projects",
  47. [
  48. {"project_id": "1"},
  49. {"project_id": "2"},
  50. {"project_id": "3"},
  51. ],
  52. {},
  53. )
  54. for conditions in [
  55. [{}], # [{}] corresponds to any([all([])]), which is True
  56. [{"project_id": None}],
  57. [{"project_id": None, "platform": None}],
  58. [{"project_id": 3, "platform": None, "event_type": None}],
  59. ]:
  60. assert _value_matches(
  61. "store.load-shed-group-creation-projects", conditions, {"project_id": 3}
  62. ) # type: ignore
  63. assert _value_matches(
  64. "store.load-shed-group-creation-projects",
  65. [{"project_id": 3, "platform": None}],
  66. {"project_id": 3},
  67. ) # type: ignore
  68. assert _value_matches(
  69. "store.load-shed-group-creation-projects",
  70. [{"event_type": "transaction"}],
  71. {"project_id": 3, "event_type": "transaction"},
  72. )