1
1
import os
2
2
from asyncio import CancelledError
3
3
from asyncio import TimeoutError as AsyncioTimeoutError
4
+ from unittest .mock import patch
4
5
5
6
import mock
6
7
import pytest
7
8
from celery .exceptions import SoftTimeLimitExceeded
8
- from shared .plan .constants import PlanName
9
+ from shared .plan .constants import PlanName , TierName
9
10
from shared .reports .resources import Report , ReportFile , ReportLine
10
11
from shared .torngit .status import Status
11
12
from shared .yaml import UserYaml
16
17
GithubAppInstallation ,
17
18
)
18
19
from database .tests .factories import CommitFactory , PullFactory , RepositoryFactory
20
+ from database .tests .factories .core import PlanFactory , TierFactory
19
21
from services .comparison import ComparisonProxy
20
22
from services .comparison .types import Comparison , EnrichedPull , FullCommit
21
23
from services .notification import NotificationService
@@ -103,9 +105,13 @@ def test_should_use_checks_notifier_yaml_field_false(self, dbsession):
103
105
),
104
106
],
105
107
)
108
+ @patch ("services.notification.Plan.objects.get" )
106
109
def test_should_use_checks_notifier_deprecated_flow (
107
- self , repo_data , outcome , dbsession
110
+ self , plan_objects_get , repo_data , outcome , dbsession
108
111
):
112
+ plan = PlanFactory .create ()
113
+ plan_objects_get .return_value = plan
114
+
109
115
repository = RepositoryFactory .create (** repo_data )
110
116
current_yaml = {"github_checks" : True }
111
117
assert repository .owner .github_app_installations == []
@@ -115,7 +121,12 @@ def test_should_use_checks_notifier_deprecated_flow(
115
121
== outcome
116
122
)
117
123
118
- def test_should_use_checks_notifier_ghapp_all_repos_covered (self , dbsession ):
124
+ @patch ("services.notification.Plan.objects.get" )
125
+ def test_should_use_checks_notifier_ghapp_all_repos_covered (
126
+ self , plan_objects_get , dbsession
127
+ ):
128
+ plan = PlanFactory .create ()
129
+ plan_objects_get .return_value = plan
119
130
repository = RepositoryFactory .create (owner__service = "github" )
120
131
ghapp_installation = GithubAppInstallation (
121
132
name = GITHUB_APP_INSTALLATION_DEFAULT_NAME ,
@@ -133,9 +144,19 @@ def test_should_use_checks_notifier_ghapp_all_repos_covered(self, dbsession):
133
144
== True
134
145
)
135
146
136
- def test_use_checks_notifier_for_team_plan (self , dbsession ):
147
+ @patch ("services.notification.Plan.objects.get" )
148
+ def test_use_checks_notifier_for_team_plan (
149
+ self ,
150
+ plan_objects_get ,
151
+ dbsession ,
152
+ ):
153
+ tier = TierFactory .create (
154
+ tier_name = TierName .TEAM .value ,
155
+ )
156
+ plan = PlanFactory .create (tier = tier , name = PlanName .TEAM_MONTHLY .value )
157
+ plan_objects_get .return_value = plan
137
158
repository = RepositoryFactory .create (
138
- owner__service = "github" , owner__plan = PlanName . TEAM_MONTHLY . value
159
+ owner__service = "github" , owner__plan = plan . name
139
160
)
140
161
ghapp_installation = GithubAppInstallation (
141
162
name = GITHUB_APP_INSTALLATION_DEFAULT_NAME ,
@@ -161,9 +182,16 @@ def test_use_checks_notifier_for_team_plan(self, dbsession):
161
182
== True
162
183
)
163
184
164
- def test_use_status_notifier_for_team_plan (self , dbsession ):
185
+ @patch ("services.notification.Plan.objects.get" )
186
+ def test_use_status_notifier_for_team_plan (self , plan_objects_get , dbsession ):
187
+ tier = TierFactory .create (
188
+ tier_name = TierName .TEAM .value ,
189
+ )
190
+ plan = PlanFactory .create (tier = tier , name = PlanName .TEAM_MONTHLY .value )
191
+ plan_objects_get .return_value = plan
192
+
165
193
repository = RepositoryFactory .create (
166
- owner__service = "github" , owner__plan = PlanName . TEAM_MONTHLY . value
194
+ owner__service = "github" , owner__plan = plan . name
167
195
)
168
196
ghapp_installation = GithubAppInstallation (
169
197
name = GITHUB_APP_INSTALLATION_DEFAULT_NAME ,
@@ -189,9 +217,15 @@ def test_use_status_notifier_for_team_plan(self, dbsession):
189
217
== True
190
218
)
191
219
192
- def test_use_status_notifier_for_non_team_plan (self , dbsession ):
220
+ @patch ("services.notification.Plan.objects.get" )
221
+ def test_use_status_notifier_for_non_team_plan (self , plan_objects_get , dbsession ):
222
+ tier = TierFactory .create (
223
+ tier_name = TierName .PRO .value ,
224
+ )
225
+ plan = PlanFactory .create (tier = tier , name = PlanName .CODECOV_PRO_MONTHLY .value )
226
+ plan_objects_get .return_value = plan
193
227
repository = RepositoryFactory .create (
194
- owner__service = "github" , owner__plan = PlanName . CODECOV_PRO_MONTHLY . value
228
+ owner__service = "github" , owner__plan = plan . name
195
229
)
196
230
ghapp_installation = GithubAppInstallation (
197
231
name = GITHUB_APP_INSTALLATION_DEFAULT_NAME ,
@@ -221,9 +255,12 @@ def test_use_status_notifier_for_non_team_plan(self, dbsession):
221
255
"gh_installation_name" ,
222
256
[GITHUB_APP_INSTALLATION_DEFAULT_NAME , "notifications-app" ],
223
257
)
258
+ @patch ("services.notification.Plan.objects.get" )
224
259
def test_should_use_checks_notifier_ghapp_some_repos_covered (
225
- self , dbsession , gh_installation_name
260
+ self , plan_objects_get , dbsession , gh_installation_name
226
261
):
262
+ plan = PlanFactory .create ()
263
+ plan_objects_get .return_value = plan
227
264
repository = RepositoryFactory .create (owner__service = "github" )
228
265
other_repo_same_owner = RepositoryFactory .create (owner = repository .owner )
229
266
ghapp_installation = GithubAppInstallation (
@@ -281,9 +318,12 @@ def test_get_notifiers_instances_only_third_party(
281
318
assert instance .site_settings == ["slack.com" ]
282
319
assert instance .current_yaml == current_yaml
283
320
321
+ @patch ("services.notification.Plan.objects.get" )
284
322
def test_get_notifiers_instances_checks (
285
- self , dbsession , mock_configuration , mocker
323
+ self , plan_objects_get , dbsession , mock_configuration , mocker
286
324
):
325
+ plan = PlanFactory .create ()
326
+ plan_objects_get .return_value = plan
287
327
repository = RepositoryFactory .create (
288
328
owner__integration_id = 123 ,
289
329
owner__service = "github" ,
@@ -310,9 +350,12 @@ def test_get_notifiers_instances_checks(
310
350
"codecov-slack-app" ,
311
351
]
312
352
353
+ @patch ("services.notification.Plan.objects.get" )
313
354
def test_get_notifiers_instances_slack_app_false (
314
- self , dbsession , mock_configuration , mocker
355
+ self , plan_objects_get , dbsession , mock_configuration , mocker
315
356
):
357
+ plan = PlanFactory .create ()
358
+ plan_objects_get .return_value = plan
316
359
mocker .patch ("services.notification.get_config" , return_value = False )
317
360
repository = RepositoryFactory .create (
318
361
owner__integration_id = 123 ,
@@ -343,9 +386,17 @@ def test_get_notifiers_instances_slack_app_false(
343
386
"gh_installation_name" ,
344
387
[GITHUB_APP_INSTALLATION_DEFAULT_NAME , "notifications-app" ],
345
388
)
389
+ @patch ("services.notification.Plan.objects.get" )
346
390
def test_get_notifiers_instances_checks_percentage_whitelist (
347
- self , dbsession , mock_configuration , mocker , gh_installation_name
391
+ self ,
392
+ plan_objects_get ,
393
+ dbsession ,
394
+ mock_configuration ,
395
+ mocker ,
396
+ gh_installation_name ,
348
397
):
398
+ plan = PlanFactory .create ()
399
+ plan_objects_get .return_value = plan
349
400
repository = RepositoryFactory .create (
350
401
owner__integration_id = 123 ,
351
402
owner__service = "github" ,
0 commit comments