test_sdk_updates.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import pytest
  2. from sentry.sdk_updates import SdkIndexState, SdkSetupState, get_suggested_updates
  3. PYTHON_INDEX_STATE = SdkIndexState(sdk_versions={"sentry.python": "0.9.1"})
  4. DOTNET_INDEX_STATE = SdkIndexState(sdk_versions={"sentry.dotnet": "1.2.0"})
  5. def test_too_old_django():
  6. setup = SdkSetupState(
  7. sdk_name="sentry.python", sdk_version="0.9.1", integrations=[], modules={"django": "1.3"}
  8. )
  9. assert list(get_suggested_updates(setup, PYTHON_INDEX_STATE)) == []
  10. def test_too_old_sdk():
  11. setup = SdkSetupState(
  12. sdk_name="sentry.python", sdk_version="0.1.0", integrations=[], modules={"django": "1.8"}
  13. )
  14. assert list(get_suggested_updates(setup, PYTHON_INDEX_STATE)) == [
  15. {
  16. "enables": [
  17. {
  18. "type": "enableIntegration",
  19. "enables": [],
  20. "integrationName": "django",
  21. "integrationUrl": "https://docs.sentry.io/platforms/python/django/",
  22. }
  23. ],
  24. "newSdkVersion": "0.9.1",
  25. "sdkName": "sentry.python",
  26. "sdkUrl": None,
  27. "type": "updateSdk",
  28. }
  29. ]
  30. def test_ignore_patch_version():
  31. setup = SdkSetupState(
  32. sdk_name="sentry.python", sdk_version="0.9.0", integrations=[], modules={}
  33. )
  34. assert len(list(get_suggested_updates(setup, PYTHON_INDEX_STATE))) == 0
  35. def test_ignore_patch_version_explicit():
  36. setup = SdkSetupState(
  37. sdk_name="sentry.python", sdk_version="0.9.0", integrations=[], modules={}
  38. )
  39. assert (
  40. len(list(get_suggested_updates(setup, PYTHON_INDEX_STATE, ignore_patch_version=True))) == 0
  41. )
  42. def test_enable_django_integration():
  43. setup = SdkSetupState(
  44. sdk_name="sentry.python", sdk_version="0.9.1", integrations=[], modules={"django": "1.8"}
  45. )
  46. assert list(get_suggested_updates(setup, PYTHON_INDEX_STATE)) == [
  47. {
  48. "type": "enableIntegration",
  49. "enables": [],
  50. "integrationName": "django",
  51. "integrationUrl": "https://docs.sentry.io/platforms/python/django/",
  52. }
  53. ]
  54. def test_update_sdk():
  55. setup = SdkSetupState(
  56. sdk_name="sentry.python", sdk_version="0.1.0", integrations=[], modules={}
  57. )
  58. assert list(get_suggested_updates(setup, PYTHON_INDEX_STATE)) == [
  59. {
  60. "enables": [],
  61. "newSdkVersion": "0.9.1",
  62. "sdkName": "sentry.python",
  63. "sdkUrl": None,
  64. "type": "updateSdk",
  65. }
  66. ]
  67. def test_enable_two_integrations():
  68. setup = SdkSetupState(
  69. sdk_name="sentry.python",
  70. sdk_version="0.1.0",
  71. integrations=[],
  72. modules={"django": "1.8.0", "flask": "1.0.0"},
  73. )
  74. assert list(get_suggested_updates(setup, PYTHON_INDEX_STATE)) == [
  75. {
  76. "enables": [
  77. {
  78. "type": "enableIntegration",
  79. "enables": [],
  80. "integrationName": "django",
  81. "integrationUrl": "https://docs.sentry.io/platforms/python/django/",
  82. },
  83. {
  84. "type": "enableIntegration",
  85. "enables": [],
  86. "integrationName": "flask",
  87. "integrationUrl": "https://docs.sentry.io/platforms/python/flask/",
  88. },
  89. ],
  90. "newSdkVersion": "0.9.1",
  91. "sdkName": "sentry.python",
  92. "sdkUrl": None,
  93. "type": "updateSdk",
  94. }
  95. ]
  96. @pytest.fixture(
  97. params=[
  98. "sentry.dotnet.serilog",
  99. "sentry.dotnet.aspnetcore",
  100. "sentry.dotnet.foobar",
  101. "sentry.dotnet",
  102. ]
  103. )
  104. def some_dotnet_sdk(request):
  105. return request.param
  106. def test_add_aspnetcore_sdk(some_dotnet_sdk):
  107. setup = SdkSetupState(
  108. sdk_name=some_dotnet_sdk,
  109. sdk_version="1.2.0",
  110. integrations=[],
  111. modules={
  112. "Sentry.Serilog": "1.2.0",
  113. "Microsoft.AspNetCore.Hosting": "2.2.0",
  114. "Serilog": "2.7.1",
  115. },
  116. )
  117. suggestions = list(get_suggested_updates(setup, DOTNET_INDEX_STATE))
  118. if some_dotnet_sdk == "sentry.dotnet.aspnetcore":
  119. assert not suggestions
  120. else:
  121. assert suggestions == [
  122. {
  123. "enables": [],
  124. "newSdkName": "sentry.dotnet.aspnetcore",
  125. "sdkUrl": None,
  126. "type": "changeSdk",
  127. }
  128. ]
  129. def test_add_serilog_sdk(some_dotnet_sdk):
  130. setup = SdkSetupState(
  131. sdk_name=some_dotnet_sdk,
  132. sdk_version="1.2.0",
  133. integrations=[],
  134. modules={"Sentry.AspNetCore": "1.2.0", "Microsoft.AspNetCore": "2.2.0", "Serilog": "2.7.1"},
  135. )
  136. suggestions = list(get_suggested_updates(setup, DOTNET_INDEX_STATE))
  137. if some_dotnet_sdk == "sentry.dotnet.serilog":
  138. assert not suggestions
  139. else:
  140. assert suggestions == [
  141. {
  142. "enables": [],
  143. "newSdkName": "sentry.dotnet.serilog",
  144. "sdkUrl": None,
  145. "type": "changeSdk",
  146. }
  147. ]
  148. def test_add_no_dotnet_sdk(some_dotnet_sdk):
  149. setup = SdkSetupState(
  150. sdk_name=some_dotnet_sdk,
  151. sdk_version="1.2.0",
  152. integrations=[],
  153. modules={
  154. "Sentry.AspNetCore": "1.2.0",
  155. "Sentry.Serilog": "1.2.0",
  156. "Microsoft.AspNetCore": "2.2.0",
  157. "Serilog": "2.7.1",
  158. },
  159. )
  160. suggestions = list(get_suggested_updates(setup, DOTNET_INDEX_STATE))
  161. assert suggestions == []
  162. def test_more_specific_dotnet_sdk(some_dotnet_sdk):
  163. setup = SdkSetupState(
  164. sdk_name=some_dotnet_sdk,
  165. sdk_version="1.2.0",
  166. integrations=[],
  167. modules={
  168. "Microsoft.AspNetCore.Hosting": "2.1.0",
  169. "Microsoft.Extensions.Logging.Configuration": "2.1.0",
  170. },
  171. )
  172. suggestions = list(get_suggested_updates(setup, DOTNET_INDEX_STATE))
  173. if some_dotnet_sdk == "sentry.dotnet.aspnetcore":
  174. assert not suggestions
  175. else:
  176. # Do not show suggestion for sentry.dotnet.extensions.logging. The user
  177. # has a aspnetcore application and the aspnetcore SDK instruments
  178. # logging too.
  179. assert suggestions == [
  180. {
  181. "enables": [],
  182. "newSdkName": "sentry.dotnet.aspnetcore",
  183. "sdkUrl": None,
  184. "type": "changeSdk",
  185. }
  186. ]