503
510
self.layer.commit()
506
def checkSourcePublication(self, source, status):
507
"""Assert the source publications has the given status.
509
Retrieve an up-to-date record corresponding to the given publication,
512
fresh_source = SourcePackagePublishingHistory.get(source.id)
514
fresh_source.status, status, "%s is not %s (%s)" % (
515
fresh_source.displayname, status.name, source.status.name))
518
def checkBinaryPublication(self, binary, status):
519
"""Assert the binary publication has the given status.
521
Retrieve an up-to-date record corresponding to the given publication,
524
fresh_binary = BinaryPackagePublishingHistory.get(binary.id)
526
fresh_binary.status, status, "%s is not %s (%s)" % (
527
fresh_binary.displayname, status.name, fresh_binary.status.name))
530
def checkBinaryPublications(self, binaries, status):
531
"""Assert the binary publications have the given status.
533
See `checkBinaryPublication`.
537
bin = self.checkBinaryPublication(bin, status)
538
fresh_binaries.append(bin)
539
return fresh_binaries
541
def checkPublications(self, source, binaries, status):
542
"""Assert source and binary publications have in the given status.
544
See `checkSourcePublication` and `checkBinaryPublications`.
546
self.checkSourcePublication(source, status)
547
self.checkBinaryPublications(binaries, status)
513
def checkPublication(self, pub, status):
514
"""Assert the publication has the given status."""
516
pub.status, status, "%s is not %s (%s)" % (
517
pub.displayname, status.name, pub.status.name))
519
def checkPublications(self, pubs, status):
520
"""Assert the given publications have the given status.
522
See `checkPublication`.
525
self.checkPublication(pub, status)
549
527
def checkPastDate(self, date, lag=None):
550
528
"""Assert given date is older than 'now'.
1026
1016
record = self.publishing_set.getByIdAndArchive(
1027
1017
binary_publishing.id, wrong_archive, source=False)
1028
1018
self.assertEqual(None, record)
1021
class TestSourceDomination(TestNativePublishingBase):
1022
"""Test SourcePackagePublishingHistory.supersede() operates correctly."""
1024
def testSupersede(self):
1025
"""Check that supersede() without arguments works."""
1026
source = self.getPubSource()
1028
self.checkSuperseded([source])
1030
def testSupersedeWithDominant(self):
1031
"""Check that supersede() with a dominant publication works."""
1032
source = self.getPubSource()
1033
super_source = self.getPubSource()
1034
source.supersede(super_source)
1035
self.checkSuperseded([source], super_source)
1037
def testSupersedingSupersededSourceFails(self):
1038
"""Check that supersede() fails with a superseded source.
1040
Sources should not be superseded twice. If a second attempt is made,
1041
the Dominator's lookups are buggy.
1043
source = self.getPubSource()
1044
super_source = self.getPubSource()
1045
source.supersede(super_source)
1046
self.checkSuperseded([source], super_source)
1048
# Manually set a date in the past, so we can confirm that
1049
# the second supersede() fails properly.
1050
source.datesuperseded = datetime.datetime(
1051
2006, 12, 25, tzinfo=pytz.timezone("UTC"))
1052
super_date = source.datesuperseded
1054
self.assertRaises(AssertionError, source.supersede, super_source)
1055
self.checkSuperseded([source], super_source)
1056
self.assertEquals(super_date, source.datesuperseded)
1059
class TestBinaryDomination(TestNativePublishingBase):
1060
"""Test BinaryPackagePublishingHistory.supersede() operates correctly."""
1062
def testSupersede(self):
1063
"""Check that supersede() without arguments works."""
1064
bins = self.getPubBinaries(architecturespecific=True)
1066
self.checkSuperseded([bins[0]])
1067
self.checkPublication(bins[1], PackagePublishingStatus.PENDING)
1069
def testSupersedeWithDominant(self):
1070
"""Check that supersede() with a dominant publication works."""
1071
bins = self.getPubBinaries(architecturespecific=True)
1072
super_bins = self.getPubBinaries(architecturespecific=True)
1073
bins[0].supersede(super_bins[0])
1074
self.checkSuperseded([bins[0]], super_bins[0])
1075
self.checkPublication(bins[1], PackagePublishingStatus.PENDING)
1077
def testSupersedesArchIndepBinariesAtomically(self):
1078
"""Check that supersede() supersedes arch-indep binaries atomically.
1080
Architecture-independent binaries should be removed from all
1081
architectures when they are superseded on at least one (bug #48760).
1083
bins = self.getPubBinaries(architecturespecific=False)
1084
super_bins = self.getPubBinaries(architecturespecific=False)
1085
bins[0].supersede(super_bins[0])
1086
self.checkSuperseded(bins, super_bins[0])
1088
def testAtomicDominationRespectsOverrides(self):
1089
"""Check that atomic domination only covers identical overrides.
1091
This is important, as otherwise newly-overridden arch-indep binaries
1092
will supersede themselves, and vanish entirely (bug #178102).
1094
bins = self.getPubBinaries(architecturespecific=False)
1096
universe = getUtility(IComponentSet)['universe']
1099
super_bins.append(bin.changeOverride(new_component=universe))
1101
bins[0].supersede(super_bins[0])
1102
self.checkSuperseded(bins, super_bins[0])
1103
self.checkPublications(super_bins, PackagePublishingStatus.PENDING)
1105
def testSupersedingSupersededArchSpecificBinaryFails(self):
1106
"""Check that supersede() fails with a superseded arch-dep binary.
1108
Architecture-specific binaries should not normally be superseded
1109
twice. If a second attempt is made, the Dominator's lookups are buggy.
1111
bin = self.getPubBinaries(architecturespecific=True)[0]
1112
super_bin = self.getPubBinaries(architecturespecific=True)[0]
1113
bin.supersede(super_bin)
1115
# Manually set a date in the past, so we can confirm that
1116
# the second supersede() fails properly.
1117
bin.datesuperseded = datetime.datetime(
1118
2006, 12, 25, tzinfo=pytz.timezone("UTC"))
1119
super_date = bin.datesuperseded
1121
self.assertRaises(AssertionError, bin.supersede, super_bin)
1122
self.checkSuperseded([bin], super_bin)
1123
self.assertEquals(super_date, bin.datesuperseded)
1125
def testSkipsSupersededArchIndependentBinary(self):
1126
"""Check that supersede() skips a superseded arch-indep binary.
1128
Since all publications of an architecture-independent binary are
1129
superseded atomically, they may be superseded again later. In that
1130
case, we skip the domination, leaving the old date unchanged.
1132
bin = self.getPubBinaries(architecturespecific=False)[0]
1133
super_bin = self.getPubBinaries(architecturespecific=False)[0]
1134
bin.supersede(super_bin)
1135
self.checkSuperseded([bin], super_bin)
1137
# Manually set a date in the past, so we can confirm that
1138
# the second supersede() skips properly.
1139
bin.datesuperseded = datetime.datetime(
1140
2006, 12, 25, tzinfo=pytz.timezone("UTC"))
1141
super_date = bin.datesuperseded
1143
bin.supersede(super_bin)
1144
self.checkSuperseded([bin], super_bin)
1145
self.assertEquals(super_date, bin.datesuperseded)
1148
class TestBinaryGetOtherPublications(TestNativePublishingBase):
1149
"""Test BinaryPackagePublishingHistory._getOtherPublications() works."""
1151
def checkOtherPublications(self, this, others):
1153
set(removeSecurityProxy(this)._getOtherPublications()),
1156
def testFindsOtherArchIndepPublications(self):
1157
"""Arch-indep publications with the same overrides should be found."""
1158
bins = self.getPubBinaries(architecturespecific=False)
1159
self.checkOtherPublications(bins[0], bins)
1161
def testDoesntFindArchSpecificPublications(self):
1162
"""Arch-dep publications shouldn't be found."""
1163
bins = self.getPubBinaries(architecturespecific=True)
1164
self.checkOtherPublications(bins[0], [bins[0]])
1166
def testDoesntFindPublicationsInOtherArchives(self):
1167
"""Publications in other archives shouldn't be found."""
1168
bins = self.getPubBinaries(architecturespecific=False)
1169
foreign_bins = bins[0].copyTo(
1170
bins[0].distroarchseries.distroseries, bins[0].pocket,
1171
self.factory.makeArchive())
1172
self.checkOtherPublications(bins[0], bins)
1173
self.checkOtherPublications(foreign_bins[0], foreign_bins)
1175
def testDoesntFindPublicationsWithDifferentOverrides(self):
1176
"""Publications with different overrides shouldn't be found."""
1177
bins = self.getPubBinaries(architecturespecific=False)
1178
universe = getUtility(IComponentSet)['universe']
1179
foreign_bin = bins[0].changeOverride(new_component=universe)
1180
self.checkOtherPublications(bins[0], bins)
1181
self.checkOtherPublications(foreign_bin, [foreign_bin])
1183
def testDoesntFindSupersededPublications(self):
1184
"""Superseded publications shouldn't be found."""
1185
bins = self.getPubBinaries(architecturespecific=False)
1186
self.checkOtherPublications(bins[0], bins)
1187
# This will supersede both atomically.
1189
self.checkOtherPublications(bins[0], [])