Skip to content

Commit 4952752

Browse files
committed
add check to process flakes using accounts if existing
1 parent c8018ba commit 4952752

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

apps/worker/services/test_results.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,11 @@ def upgrade_comment(self):
498498

499499

500500
def not_private_and_free_or_team(repo: Repository):
501-
plan = Plan.objects.select_related("tier").get(name=repo.author.plan)
501+
plan_name = repo.author.plan
502+
if repo.author.account:
503+
plan_name = repo.author.account.plan
504+
505+
plan = Plan.objects.select_related("tier").get(name=plan_name)
502506

503507
return not (
504508
repo.private

apps/worker/services/tests/test_test_results.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,40 @@ def test_should_do_flake_detection(dbsession, mocker, config, private, plan, ex_
326326
assert result == ex_result
327327

328328

329+
@pytest.mark.django_db
330+
@pytest.mark.parametrize(
331+
"config,private,owner_plan,account_plan,ex_result",
332+
[
333+
# Account with free plan should override owner's paid plan
334+
(True, True, "users-inappm", DEFAULT_FREE_PLAN, False),
335+
# Account with paid plan should override owner's free plan
336+
(True, True, DEFAULT_FREE_PLAN, "users-inappm", True),
337+
# Account with paid plan, private repo, should work
338+
(True, False, DEFAULT_FREE_PLAN, "users-inappm", True),
339+
# Account with free plan, public repo, should work
340+
(True, False, "users-inappm", DEFAULT_FREE_PLAN, True),
341+
],
342+
)
343+
def test_should_do_flake_detection_with_account(
344+
dbsession, mocker, config, private, owner_plan, account_plan, ex_result
345+
):
346+
mock_all_plans_and_tiers()
347+
account = Account(name="testaccount", plan=account_plan, is_active=True)
348+
dbsession.add(account)
349+
dbsession.flush()
350+
351+
owner = OwnerFactory(plan=owner_plan, account=account)
352+
repo = RepositoryFactory(private=private, author=owner)
353+
dbsession.add(repo)
354+
dbsession.flush()
355+
356+
yaml = {"test_analytics": {"flake_detection": config}}
357+
358+
result = should_do_flaky_detection(repo, UserYaml.from_dict(yaml))
359+
360+
assert result == ex_result
361+
362+
329363
def test_specific_error_message(mocker, snapshot):
330364
mock_repo_service = mock.AsyncMock()
331365
mocker.patch(

0 commit comments

Comments
 (0)