Merge ~cjwatson/launchpad:fix-archive-api-tests into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: e63bfb30795c257080e33338bcfe9bd5cff560db
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-archive-api-tests
Merge into: launchpad:master
Diff against target: 114 lines (+26/-11)
2 files modified
lib/lp/soyuz/xmlrpc/tests/test_archive.py (+23/-11)
lib/lp/testing/factory.py (+3/-0)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+437053@code.launchpad.net

Commit message

Fix ArchiveAPI tests to not create bad ArchiveFile combinations

Description of the change

DB patch 2211-15-0 introduces a unique index to ensure that there may be only one non-superseded `ArchiveFile` row for a given path in a given archive at any one time. The `ArchiveAPI` tests unintentionally violated this.

This situation shouldn't happen on production, and I've checked that there are no violations in the most recent production dump that was loaded into staging.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/soyuz/xmlrpc/tests/test_archive.py b/lib/lp/soyuz/xmlrpc/tests/test_archive.py
2index 3d725ce..1dffd43 100644
3--- a/lib/lp/soyuz/xmlrpc/tests/test_archive.py
4+++ b/lib/lp/soyuz/xmlrpc/tests/test_archive.py
5@@ -11,11 +11,11 @@ from zope.security.proxy import removeSecurityProxy
6
7 from lp.buildmaster.enums import BuildStatus
8 from lp.services.database.interfaces import IStore
9+from lp.services.database.sqlbase import get_transaction_timestamp
10 from lp.services.features.testing import FeatureFixture
11 from lp.services.macaroons.interfaces import IMacaroonIssuer
12 from lp.soyuz.enums import ArchiveRepositoryFormat, PackagePublishingStatus
13 from lp.soyuz.interfaces.archive import NAMED_AUTH_TOKEN_FEATURE_FLAG
14-from lp.soyuz.interfaces.archivefile import IArchiveFileSet
15 from lp.soyuz.xmlrpc.archive import ArchiveAPI
16 from lp.testing import TestCaseWithFactory, person_logged_in
17 from lp.testing.layers import LaunchpadFunctionalLayer
18@@ -324,10 +324,13 @@ class TestArchiveAPI(TestCaseWithFactory):
19
20 def test_translatePath_by_hash_checksum_found(self):
21 archive = removeSecurityProxy(self.factory.makeArchive())
22+ now = get_transaction_timestamp(IStore(archive))
23 self.factory.makeArchiveFile(
24 archive=archive,
25 container="release:jammy",
26 path="dists/jammy/InRelease",
27+ date_superseded=now,
28+ scheduled_deletion_date=now + timedelta(days=1),
29 )
30 archive_file = self.factory.makeArchiveFile(
31 archive=archive,
32@@ -349,10 +352,13 @@ class TestArchiveAPI(TestCaseWithFactory):
33
34 def test_translatePath_by_hash_checksum_found_private(self):
35 archive = removeSecurityProxy(self.factory.makeArchive(private=True))
36+ now = get_transaction_timestamp(IStore(archive))
37 self.factory.makeArchiveFile(
38 archive=archive,
39 container="release:jammy",
40 path="dists/jammy/InRelease",
41+ date_superseded=now,
42+ scheduled_deletion_date=now + timedelta(days=1),
43 )
44 archive_file = self.factory.makeArchiveFile(
45 archive=archive,
46@@ -385,15 +391,18 @@ class TestArchiveAPI(TestCaseWithFactory):
47
48 def test_translatePath_non_pool_found(self):
49 archive = removeSecurityProxy(self.factory.makeArchive())
50+ now = get_transaction_timestamp(IStore(archive))
51 self.factory.makeArchiveFile(archive=archive)
52 path = "dists/focal/InRelease"
53 archive_files = [
54- self.factory.makeArchiveFile(archive=archive, path=path)
55- for _ in range(2)
56+ self.factory.makeArchiveFile(
57+ archive=archive,
58+ path=path,
59+ date_superseded=now,
60+ scheduled_deletion_date=now + timedelta(days=1),
61+ ),
62+ self.factory.makeArchiveFile(archive=archive, path=path),
63 ]
64- getUtility(IArchiveFileSet).scheduleDeletion(
65- [archive_files[0]], timedelta(days=1)
66- )
67 self.assertEqual(
68 archive_files[1].library_file.getURL(),
69 self.archive_api.translatePath(archive.reference, path),
70@@ -409,15 +418,18 @@ class TestArchiveAPI(TestCaseWithFactory):
71
72 def test_translatePath_non_pool_found_private(self):
73 archive = removeSecurityProxy(self.factory.makeArchive(private=True))
74+ now = get_transaction_timestamp(IStore(archive))
75 self.factory.makeArchiveFile(archive=archive)
76 path = "dists/focal/InRelease"
77 archive_files = [
78- self.factory.makeArchiveFile(archive=archive, path=path)
79- for _ in range(2)
80+ self.factory.makeArchiveFile(
81+ archive=archive,
82+ path=path,
83+ date_superseded=now,
84+ scheduled_deletion_date=now + timedelta(days=1),
85+ ),
86+ self.factory.makeArchiveFile(archive=archive, path=path),
87 ]
88- getUtility(IArchiveFileSet).scheduleDeletion(
89- [archive_files[0]], timedelta(days=1)
90- )
91 self.assertStartsWith(
92 archive_files[1].library_file.getURL() + "?token=",
93 self.archive_api.translatePath(archive.reference, path),
94diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
95index 9a672aa..62cd634 100644
96--- a/lib/lp/testing/factory.py
97+++ b/lib/lp/testing/factory.py
98@@ -3795,6 +3795,7 @@ class LaunchpadObjectFactory(ObjectFactory):
99 container=None,
100 path=None,
101 library_file=None,
102+ date_superseded=None,
103 scheduled_deletion_date=None,
104 ):
105 if archive is None:
106@@ -3811,6 +3812,8 @@ class LaunchpadObjectFactory(ObjectFactory):
107 path=path,
108 library_file=library_file,
109 )
110+ if date_superseded is not None:
111+ removeSecurityProxy(archive_file).date_superseded = date_superseded
112 if scheduled_deletion_date is not None:
113 removeSecurityProxy(
114 archive_file

Subscribers

People subscribed via source and target branches

to status/vote changes: