|
10 | 10 | CommitFactory, |
11 | 11 | RepositoryFactory, |
12 | 12 | ) |
| 13 | +from shared.django_apps.reports.models import ( |
| 14 | + CommitReport, |
| 15 | + DailyTestRollup, |
| 16 | + Test, |
| 17 | + TestInstance, |
| 18 | +) |
| 19 | +from shared.django_apps.reports.models import ReportSession as Upload |
| 20 | +from shared.django_apps.reports.tests.factories import ( |
| 21 | + CommitReportFactory, |
| 22 | + DailyTestRollupFactory, |
| 23 | + TestFactory, |
| 24 | + TestInstanceFactory, |
| 25 | + UploadFactory, |
| 26 | +) |
13 | 27 |
|
14 | 28 | from services.cleanup.utils import CleanupResult, CleanupSummary |
15 | 29 | from tasks.delete_owner import DeleteOwnerTask |
@@ -53,26 +67,50 @@ def test_delete_owner_deletes_owner_with_commit_compares(mock_storage): |
53 | 67 | compare_commit = CommitFactory(repository=repo, author=user) |
54 | 68 | CommitComparisonFactory(base_commit=base_commit, compare_commit=compare_commit) |
55 | 69 |
|
| 70 | + report = CommitReportFactory(commit=base_commit) |
| 71 | + upload = UploadFactory(report=report) |
| 72 | + test = TestFactory(repository=repo) |
| 73 | + TestInstanceFactory(test=test, upload=upload) |
| 74 | + DailyTestRollupFactory(test=test, repoid=repo.repoid) |
| 75 | + |
| 76 | + # This test factory implicitly creates: |
| 77 | + # - Test with a Repository and an Owner, |
| 78 | + # - An Upload with a CommitReport, a Commit that has a different Owner and |
| 79 | + # one more Repository with yet another different Owner. |
| 80 | + # And then also a Branch and a Pull via DB triggers because of the Commit. |
| 81 | + remaining = TestInstanceFactory() |
| 82 | + |
56 | 83 | res = DeleteOwnerTask().run_impl({}, user.ownerid) |
57 | 84 |
|
58 | 85 | assert res == CleanupSummary( |
59 | | - CleanupResult(7), |
| 86 | + CleanupResult(12), |
60 | 87 | { |
61 | 88 | Branch: CleanupResult(1), |
62 | 89 | Commit: CleanupResult(2), |
63 | 90 | CommitComparison: CleanupResult(1), |
64 | 91 | Owner: CleanupResult(1), |
65 | 92 | Pull: CleanupResult(1), |
66 | 93 | Repository: CleanupResult(1), |
| 94 | + CommitReport: CleanupResult(1), |
| 95 | + Upload: CleanupResult(1), |
| 96 | + Test: CleanupResult(1), |
| 97 | + TestInstance: CleanupResult(1), |
| 98 | + DailyTestRollup: CleanupResult(1), |
67 | 99 | }, |
68 | 100 | ) |
69 | 101 |
|
70 | | - assert Branch.objects.count() == 0 |
71 | | - assert Commit.objects.count() == 0 |
| 102 | + assert list(TestInstance.objects.all()) == [remaining] |
| 103 | + # See the comment above why we have all of these objects |
| 104 | + assert Branch.objects.count() == 1 |
| 105 | + assert Commit.objects.count() == 1 |
72 | 106 | assert CommitComparison.objects.count() == 0 |
73 | | - assert Owner.objects.count() == 0 |
74 | | - assert Pull.objects.count() == 0 |
75 | | - assert Repository.objects.count() == 0 |
| 107 | + assert Owner.objects.count() == 3 |
| 108 | + assert Pull.objects.count() == 1 |
| 109 | + assert Repository.objects.count() == 2 |
| 110 | + assert CommitReport.objects.count() == 1 |
| 111 | + assert Upload.objects.count() == 1 |
| 112 | + assert Test.objects.count() == 1 |
| 113 | + assert DailyTestRollup.objects.count() == 0 |
76 | 114 |
|
77 | 115 |
|
78 | 116 | @pytest.mark.django_db(databases=["timeseries", "default"], transaction=True) |
|
0 commit comments