Merge lp:~wgrant/launchpad/dont-overrideFromAncestry into lp:launchpad

Proposed by William Grant
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 16609
Proposed branch: lp:~wgrant/launchpad/dont-overrideFromAncestry
Merge into: lp:launchpad
Diff against target: 573 lines (+11/-461)
5 files modified
lib/lp/soyuz/doc/publishing.txt (+0/-114)
lib/lp/soyuz/interfaces/publishing.py (+0/-56)
lib/lp/soyuz/model/publishing.py (+0/-86)
lib/lp/soyuz/scripts/packagecopier.py (+11/-9)
lib/lp/soyuz/tests/test_publishing.py (+0/-196)
To merge this branch: bzr merge lp:~wgrant/launchpad/dont-overrideFromAncestry
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+162933@code.launchpad.net

Commit message

Drop overrideFromAncestry, getNearestAncestor, and getAncestry.

Description of the change

Stop calling overrideFromAncestry and getNearestAncestor in do_copy. overrideFromAncestry is redundant with the modern overrides in _do_direct_copy, and getNearestAncestor can be replaced with getPublishedSources. Those two methods and getAncestry can then go away, saving a lot of code.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/soyuz/doc/publishing.txt'
--- lib/lp/soyuz/doc/publishing.txt 2013-03-12 01:07:49 +0000
+++ lib/lp/soyuz/doc/publishing.txt 2013-05-08 06:29:28 +0000
@@ -1756,117 +1756,3 @@
1756 ... [firefox_source_pub.id, foo_pub.id],1756 ... [firefox_source_pub.id, foo_pub.id],
1757 ... archive=ubuntu.main_archive)1757 ... archive=ubuntu.main_archive)
1758 >>> print_build_summaries(build_summaries)1758 >>> print_build_summaries(build_summaries)
1759
1760
1761IPublishing ancestry lookup and override
1762========================================
1763
1764`IPublishing` is implemented by both kinds of package publications we
1765have `SourcePackagePublishingHistory` and
1766`BinaryPackagePublishingHistory`.
1767
1768This interface allows, among other features, easy ancestry lookup and
1769pre-publication overrides via:
1770
1771 * getAncestry
1772 * overrideFromAncestry
1773
1774 # Setup a publishing scenario for illustrating ancestry lookup.
1775 >>> ubuntu_source_ancestry = test_publisher.getPubSource(
1776 ... sourcename='testing', version='1.0',
1777 ... architecturehintlist='i386', component='multiverse',
1778 ... status=PackagePublishingStatus.PUBLISHED)
1779 >>> ubuntu_binary_ancestry = test_publisher.getPubBinaries(
1780 ... binaryname='testing-bin', pub_source=ubuntu_source_ancestry,
1781 ... status=PackagePublishingStatus.PUBLISHED)[0]
1782 >>> ppa_source_ancestry = test_publisher.getPubSource(
1783 ... sourcename='testing', version='1.1', component='main',
1784 ... architecturehintlist='i386', archive=cprov.archive,
1785 ... status=PackagePublishingStatus.PUBLISHED)
1786 >>> ppa_binary_ancestry = test_publisher.getPubBinaries(
1787 ... binaryname='testing-bin', pub_source=ppa_source_ancestry,
1788 ... status=PackagePublishingStatus.PUBLISHED)[0]
1789 >>> test_source = test_publisher.getPubSource(
1790 ... sourcename='testing', version='2.0', component='universe',
1791 ... architecturehintlist='i386')
1792 >>> test_binary = test_publisher.getPubBinaries(
1793 ... binaryname='testing-bin', pub_source=test_source)[0]
1794
1795We will create a helper function to inspect ancestries. It simply pass
1796any given keyword argument to 'test_source' and 'test_binary'
1797getAncestry() method.
1798
1799 >>> def print_ancestries(**kwargs):
1800 ... def print_displayname(pub):
1801 ... if pub is not None:
1802 ... print pub.displayname
1803 ... else:
1804 ... print pub
1805 ... print_displayname(test_source.getAncestry(**kwargs))
1806 ... print_displayname(test_binary.getAncestry(**kwargs))
1807
1808The 'test_source' and 'test_binary' ancestries in the same context,
1809i.e. ubuntu primary archive.
1810
1811 >>> print_ancestries()
1812 testing 1.0 in breezy-autotest
1813 testing-bin 1.0 in breezy-autotest i386
1814
1815Call sites may quickly adjust the context where the ancestries are
1816looked up.
1817
1818 >>> print_ancestries(archive=cprov.archive)
1819 testing 1.1 in breezy-autotest
1820 testing-bin 1.1 in breezy-autotest i386
1821
1822 >>> print_ancestries(distroseries=test_source.distroseries)
1823 testing 1.0 in breezy-autotest
1824 testing-bin 1.0 in breezy-autotest i386
1825
1826 >>> print_ancestries(pocket=test_source.pocket)
1827 testing 1.0 in breezy-autotest
1828 testing-bin 1.0 in breezy-autotest i386
1829
1830The default 'status' filter is set to PUBLISHED ancestries, however
1831call sites may decide differently.
1832
1833 >>> print_ancestries(status=PackagePublishingStatus.PUBLISHED)
1834 testing 1.0 in breezy-autotest
1835 testing-bin 1.0 in breezy-autotest i386
1836
1837On the lack of ancestry, None is returned.
1838
1839 >>> from lp.soyuz.interfaces.publishing import (
1840 ... inactive_publishing_status)
1841 >>> print_ancestries(status=inactive_publishing_status)
1842 None
1843 None
1844
1845`overrideFromAncestry` operates directly on top of the default
1846behavior of `getAncestry`. It looks up the most recent ancestry for a
1847publication and override it in place. If there is no previous publication
1848then the package's component is used.
1849
1850 >>> print test_source.component.name
1851 universe
1852
1853 >>> test_source.overrideFromAncestry()
1854 >>> print test_source.component.name
1855 multiverse
1856
1857It works in the same way for binaries.
1858
1859 >>> multiverse = getUtility(IComponentSet)['multiverse']
1860 >>> test_binary.binarypackagerelease.component = multiverse
1861
1862 >>> print test_binary.component.name
1863 universe
1864
1865 >>> copied_binary = test_binary.copyTo(
1866 ... hoary_test, test_source.pocket, archive=test_binary.archive)[0]
1867 >>> print copied_binary.component.name
1868 universe
1869
1870 >>> copied_binary.overrideFromAncestry()
1871 >>> print copied_binary.component.name
1872 multiverse
18731759
=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
--- lib/lp/soyuz/interfaces/publishing.py 2013-05-03 00:07:30 +0000
+++ lib/lp/soyuz/interfaces/publishing.py 2013-05-08 06:29:28 +0000
@@ -221,34 +221,6 @@
221 `IBinaryPackagePublishingHistory`.221 `IBinaryPackagePublishingHistory`.
222 """222 """
223223
224 def getAncestry(archive=None, distroseries=None, pocket=None,
225 status=None):
226 """Return the most recent publication of the same source or binary.
227
228 If a suitable ancestry could not be found, None is returned.
229
230 It optionally accepts parameters for adjusting the publishing
231 context, if not given they default to the current context.
232
233 :param archive: optional `IArchive`, defaults to the context archive.
234 :param distroseries: optional `IDistroSeries`, defaults to the
235 context distroseries.
236 :param pocket: optional `PackagePublishingPocket`, defaults to any
237 pocket.
238 :param status: optional `PackagePublishingStatus` or a collection of
239 them, defaults to `PackagePublishingStatus.PUBLISHED`
240 """
241
242 def overrideFromAncestry():
243 """Set the right published component from publishing ancestry.
244
245 Start with the publishing records and fall back to the original
246 uploaded package if necessary.
247
248 :raise: AssertionError if the context publishing record is not in
249 PENDING status.
250 """
251
252224
253class IPublishingEdit(Interface):225class IPublishingEdit(Interface):
254 """Base interface for writeable Publishing classes."""226 """Base interface for writeable Publishing classes."""
@@ -1343,34 +1315,6 @@
1343 the source_package_pub, allowing the use of the cached results.1315 the source_package_pub, allowing the use of the cached results.
1344 """1316 """
13451317
1346 def getNearestAncestor(
1347 package_name, archive, distroseries, pocket=None, status=None,
1348 binary=False):
1349 """Return the ancestor of the given parkage in a particular archive.
1350
1351 :param package_name: The package name for which we are checking for
1352 an ancestor.
1353 :type package_name: ``string``
1354 :param archive: The archive in which we are looking for an ancestor.
1355 :type archive: `IArchive`
1356 :param distroseries: The particular series in which we are looking for
1357 an ancestor.
1358 :type distroseries: `IDistroSeries`
1359 :param pocket: An optional pocket to restrict the search.
1360 :type pocket: `PackagePublishingPocket`.
1361 :param status: An optional status defaulting to PUBLISHED if not
1362 provided.
1363 :type status: `PackagePublishingStatus`
1364 :param binary: An optional argument to look for a binary ancestor
1365 instead of the default source.
1366 :type binary: ``Boolean``
1367
1368 :return: The most recent publishing history for the given
1369 arguments.
1370 :rtype: `ISourcePackagePublishingHistory` or
1371 `IBinaryPackagePublishingHistory` or None.
1372 """
1373
1374active_publishing_status = (1318active_publishing_status = (
1375 PackagePublishingStatus.PENDING,1319 PackagePublishingStatus.PENDING,
1376 PackagePublishingStatus.PUBLISHED,1320 PackagePublishingStatus.PUBLISHED,
13771321
=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py 2013-05-04 00:37:58 +0000
+++ lib/lp/soyuz/model/publishing.py 2013-05-08 06:29:28 +0000
@@ -847,41 +847,6 @@
847 return getUtility(847 return getUtility(
848 IPublishingSet).getBuildStatusSummaryForSourcePublication(self)848 IPublishingSet).getBuildStatusSummaryForSourcePublication(self)
849849
850 def getAncestry(self, archive=None, distroseries=None, pocket=None,
851 status=None):
852 """See `ISourcePackagePublishingHistory`."""
853 if archive is None:
854 archive = self.archive
855 if distroseries is None:
856 distroseries = self.distroseries
857
858 return getUtility(IPublishingSet).getNearestAncestor(
859 self.source_package_name, archive, distroseries, pocket,
860 status)
861
862 def overrideFromAncestry(self):
863 """See `ISourcePackagePublishingHistory`."""
864 # We don't want to use changeOverride here because it creates a
865 # new publishing record. This code can be only executed for pending
866 # publishing records.
867 assert self.status == PackagePublishingStatus.PENDING, (
868 "Cannot override published records.")
869
870 # If there is published ancestry, use its component, otherwise
871 # use the original upload component. Since PPAs only use main,
872 # we don't need to check the ancestry.
873 if not self.archive.is_ppa:
874 ancestry = self.getAncestry()
875 if ancestry is not None:
876 component = ancestry.component
877 else:
878 component = self.sourcepackagerelease.component
879
880 self.component = component
881
882 assert self.component in (
883 self.archive.getComponentsForSeries(self.distroseries))
884
885 def sourceFileUrls(self):850 def sourceFileUrls(self):
886 """See `ISourcePackagePublishingHistory`."""851 """See `ISourcePackagePublishingHistory`."""
887 source_urls = proxied_urls(852 source_urls = proxied_urls(
@@ -1280,36 +1245,6 @@
1280 return getUtility(IPublishingSet).copyBinariesTo(1245 return getUtility(IPublishingSet).copyBinariesTo(
1281 [self], distroseries, pocket, archive)1246 [self], distroseries, pocket, archive)
12821247
1283 def getAncestry(self, archive=None, distroseries=None, pocket=None,
1284 status=None):
1285 """See `IBinaryPackagePublishingHistory`."""
1286 if archive is None:
1287 archive = self.archive
1288 if distroseries is None:
1289 distroseries = self.distroarchseries.distroseries
1290
1291 return getUtility(IPublishingSet).getNearestAncestor(
1292 self.binary_package_name, archive, distroseries, pocket,
1293 status, binary=True)
1294
1295 def overrideFromAncestry(self):
1296 """See `IBinaryPackagePublishingHistory`."""
1297 # We don't want to use changeOverride here because it creates a
1298 # new publishing record. This code can be only executed for pending
1299 # publishing records.
1300 assert self.status == PackagePublishingStatus.PENDING, (
1301 "Cannot override published records.")
1302
1303 # If there is an ancestry, use its component, otherwise use the
1304 # original upload component.
1305 ancestry = self.getAncestry()
1306 if ancestry is not None:
1307 component = ancestry.component
1308 else:
1309 component = self.binarypackagerelease.component
1310
1311 self.component = component
1312
1313 def _getDownloadCountClauses(self, start_date=None, end_date=None):1248 def _getDownloadCountClauses(self, start_date=None, end_date=None):
1314 clauses = [1249 clauses = [
1315 BinaryPackageReleaseDownloadCount.archive == self.archive,1250 BinaryPackageReleaseDownloadCount.archive == self.archive,
@@ -2109,27 +2044,6 @@
2109 BinaryPackagePublishingHistory, bpph_ids, removed_by,2044 BinaryPackagePublishingHistory, bpph_ids, removed_by,
2110 removal_comment=removal_comment)2045 removal_comment=removal_comment)
21112046
2112 def getNearestAncestor(
2113 self, package_name, archive, distroseries, pocket=None,
2114 status=None, binary=False):
2115 """See `IPublishingSet`."""
2116 if status is None:
2117 status = PackagePublishingStatus.PUBLISHED
2118
2119 if binary:
2120 ancestries = archive.getAllPublishedBinaries(
2121 name=package_name, exact_match=True, pocket=pocket,
2122 status=status, distroarchseries=distroseries.architectures)
2123 else:
2124 ancestries = archive.getPublishedSources(
2125 name=package_name, exact_match=True, pocket=pocket,
2126 status=status, distroseries=distroseries)
2127
2128 try:
2129 return ancestries[0]
2130 except IndexError:
2131 return None
2132
21332047
2134def get_current_source_releases(context_sourcepackagenames, archive_ids_func,2048def get_current_source_releases(context_sourcepackagenames, archive_ids_func,
2135 package_clause_func, extra_clauses, key_col):2049 package_clause_func, extra_clauses, key_col):
21362050
=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
--- lib/lp/soyuz/scripts/packagecopier.py 2013-04-17 23:19:35 +0000
+++ lib/lp/soyuz/scripts/packagecopier.py 2013-05-08 06:29:28 +0000
@@ -38,6 +38,7 @@
38from lp.soyuz.interfaces.queue import IPackageUploadCustom38from lp.soyuz.interfaces.queue import IPackageUploadCustom
39from lp.soyuz.scripts.custom_uploads_copier import CustomUploadsCopier39from lp.soyuz.scripts.custom_uploads_copier import CustomUploadsCopier
4040
41
41# XXX cprov 2009-06-12: this function should be incorporated in42# XXX cprov 2009-06-12: this function should be incorporated in
42# IPublishing.43# IPublishing.
43def update_files_privacy(pub_record):44def update_files_privacy(pub_record):
@@ -181,7 +182,7 @@
181 # implementations of ancestry lookup:182 # implementations of ancestry lookup:
182 # NascentUpload.getSourceAncestry,183 # NascentUpload.getSourceAncestry,
183 # PackageUploadSource.getSourceAncestryForDiffs, and184 # PackageUploadSource.getSourceAncestryForDiffs, and
184 # PublishingSet.getNearestAncestor, none of which is obviously185 # Archive.getPublishedSources, none of which is obviously
185 # correct here. Instead of adding a fourth, we should consolidate186 # correct here. Instead of adding a fourth, we should consolidate
186 # these.187 # these.
187 ancestries = archive.getPublishedSources(188 ancestries = archive.getPublishedSources(
@@ -476,8 +477,10 @@
476 # published in the destination archive.477 # published in the destination archive.
477 self._checkArchiveConflicts(source, series)478 self._checkArchiveConflicts(source, series)
478479
479 ancestry = source.getAncestry(480 ancestry = self.archive.getPublishedSources(
480 self.archive, series, pocket, status=active_publishing_status)481 name=source.source_package_name, exact_match=True,
482 distroseries=series, pocket=pocket,
483 status=active_publishing_status).first()
481 if ancestry is not None:484 if ancestry is not None:
482 ancestry_version = ancestry.sourcepackagerelease.version485 ancestry_version = ancestry.sourcepackagerelease.version
483 copy_version = source.sourcepackagerelease.version486 copy_version = source.sourcepackagerelease.version
@@ -633,13 +636,12 @@
633 announce_from_person=announce_from_person,636 announce_from_person=announce_from_person,
634 previous_version=old_version)637 previous_version=old_version)
635 if not archive.private and has_restricted_files(source):638 if not archive.private and has_restricted_files(source):
636 # Fix copies by overriding them according to the current639 # Fix copies by unrestricting files with privacy mismatch.
637 # ancestry and unrestrict files with privacy mismatch. We must640 # We must do this *after* calling notify (which only
638 # do this *after* calling notify (which only actually sends mail641 # actually sends mail on commit), because otherwise the new
639 # on commit), because otherwise the new changelog LFA won't be642 # changelog LFA won't be visible without a commit, which may
640 # visible without a commit, which may not be safe here.643 # not be safe here.
641 for pub_record in sub_copies:644 for pub_record in sub_copies:
642 pub_record.overrideFromAncestry()
643 for changed_file in update_files_privacy(pub_record):645 for changed_file in update_files_privacy(pub_record):
644 if logger is not None:646 if logger is not None:
645 logger.info("Made %s public" % changed_file.filename)647 logger.info("Made %s public" % changed_file.filename)
646648
=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
--- lib/lp/soyuz/tests/test_publishing.py 2013-05-04 00:37:58 +0000
+++ lib/lp/soyuz/tests/test_publishing.py 2013-05-08 06:29:28 +0000
@@ -31,9 +31,7 @@
31from lp.services.database.constants import UTC_NOW31from lp.services.database.constants import UTC_NOW
32from lp.services.librarian.interfaces import ILibraryFileAliasSet32from lp.services.librarian.interfaces import ILibraryFileAliasSet
33from lp.services.log.logger import DevNullLogger33from lp.services.log.logger import DevNullLogger
34from lp.soyuz.adapters.overrides import UnknownOverridePolicy
35from lp.soyuz.enums import (34from lp.soyuz.enums import (
36 ArchivePurpose,
37 BinaryPackageFormat,35 BinaryPackageFormat,
38 PackageUploadStatus,36 PackageUploadStatus,
39 )37 )
@@ -803,200 +801,6 @@
803 shutil.rmtree(test_temp_dir)801 shutil.rmtree(test_temp_dir)
804802
805803
806class OverrideFromAncestryTestCase(TestCaseWithFactory):
807 """Test `IPublishing.overrideFromAncestry`.
808
809 When called from a `SourcePackagePublishingHistory` or a
810 `BinaryPackagePublishingHistory` it sets the object target component
811 according to its ancestry if available or falls back to the component
812 it was originally uploaded to.
813 """
814 layer = LaunchpadZopelessLayer
815
816 def setUp(self):
817 TestCaseWithFactory.setUp(self)
818 self.test_publisher = SoyuzTestPublisher()
819 self.test_publisher.prepareBreezyAutotest()
820
821 def test_overrideFromAncestry_only_works_for_pending_records(self):
822 # overrideFromAncestry only accepts PENDING publishing records.
823 source = self.test_publisher.getPubSource()
824
825 forbidden_status = [
826 item
827 for item in PackagePublishingStatus.items
828 if item is not PackagePublishingStatus.PENDING]
829
830 for status in forbidden_status:
831 source.status = status
832 self.layer.commit()
833 self.assertRaisesWithContent(
834 AssertionError,
835 'Cannot override published records.',
836 source.overrideFromAncestry)
837
838 def makeSource(self):
839 """Return a 'source' publication.
840
841 It's pending publication with binaries in a brand new PPA
842 and in 'main' component.
843 """
844 test_archive = self.factory.makeArchive(
845 distribution=self.test_publisher.ubuntutest,
846 purpose=ArchivePurpose.PPA)
847 source = self.test_publisher.getPubSource(archive=test_archive)
848 self.test_publisher.getPubBinaries(pub_source=source)
849 return source
850
851 def copyAndCheck(self, pub_record, series, component_name):
852 """Copy and check if overrideFromAncestry is working as expected.
853
854 The copied publishing record is targeted to the same component
855 as its source, but override_from_ancestry changes it to follow
856 the ancestry or fallback to the SPR/BPR original component.
857 """
858 copied = pub_record.copyTo(
859 series, pub_record.pocket, series.main_archive)
860
861 # Cope with heterogeneous results from copyTo().
862 try:
863 copies = tuple(copied)
864 except TypeError:
865 copies = (copied, )
866
867 for copy in copies:
868 self.assertEqual(pub_record.component, copy.component)
869 copy.overrideFromAncestry()
870 self.layer.commit()
871 self.assertEqual("universe", copy.component.name)
872
873 def test_overrideFromAncestry_fallback_to_source_component(self):
874 # overrideFromAncestry on the lack of ancestry, falls back to the
875 # component the source was originally uploaded to.
876 source = self.makeSource()
877
878 # Adjust the source package release original component.
879 universe = getUtility(IComponentSet)['universe']
880 source.sourcepackagerelease.component = universe
881
882 self.copyAndCheck(source, source.distroseries, 'universe')
883
884 def test_overrideFromAncestry_fallback_to_binary_component(self):
885 # overrideFromAncestry on the lack of ancestry, falls back to the
886 # component the binary was originally uploaded to.
887 binary = self.makeSource().getPublishedBinaries()[0]
888
889 # Adjust the binary package release original component.
890 universe = getUtility(IComponentSet)['universe']
891 removeSecurityProxy(binary.binarypackagerelease).component = universe
892
893 self.copyAndCheck(
894 binary, binary.distroarchseries.distroseries, 'universe')
895
896 def test_overrideFromAncestry_follow_ancestry_source_component(self):
897 # overrideFromAncestry finds and uses the component of the most
898 # recent PUBLISHED publication of the same name in the same
899 #location.
900 source = self.makeSource()
901
902 # Create a published ancestry source in the copy destination
903 # targeted to 'universe' and also 2 other noise source
904 # publications, a pending source target to 'restricted' and
905 # a published, but older, one target to 'multiverse'.
906 self.test_publisher.getPubSource(component='restricted')
907
908 self.test_publisher.getPubSource(
909 component='multiverse', status=PackagePublishingStatus.PUBLISHED)
910
911 self.test_publisher.getPubSource(
912 component='universe', status=PackagePublishingStatus.PUBLISHED)
913
914 # Overridden copy it targeted to 'universe'.
915 self.copyAndCheck(source, source.distroseries, 'universe')
916
917 def test_overrideFromAncestry_follow_ancestry_binary_component(self):
918 # overrideFromAncestry finds and uses the component of the most
919 # recent published publication of the same name in the same
920 # location.
921 binary = self.makeSource().getPublishedBinaries()[0]
922
923 # Create a published ancestry binary in the copy destination
924 # targeted to 'universe'.
925 restricted_source = self.test_publisher.getPubSource(
926 component='restricted')
927 self.test_publisher.getPubBinaries(pub_source=restricted_source)
928
929 multiverse_source = self.test_publisher.getPubSource(
930 component='multiverse')
931 self.test_publisher.getPubBinaries(
932 pub_source=multiverse_source,
933 status=PackagePublishingStatus.PUBLISHED)
934
935 ancestry_source = self.test_publisher.getPubSource(
936 component='universe')
937 self.test_publisher.getPubBinaries(
938 pub_source=ancestry_source,
939 status=PackagePublishingStatus.PUBLISHED)
940
941 # Overridden copy it targeted to 'universe'.
942 self.copyAndCheck(
943 binary, binary.distroarchseries.distroseries, 'universe')
944
945 def test_ppa_override_no_ancestry(self):
946 # Test a PPA publication with no ancestry is 'main'
947 ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
948 spr = self.factory.makeSourcePackageRelease()
949 spph = self.factory.makeSourcePackagePublishingHistory(
950 sourcepackagerelease=spr, archive=ppa)
951 spph.overrideFromAncestry()
952 self.assertEqual("main", spph.component.name)
953
954 def test_ppa_override_with_ancestry(self):
955 # Test a PPA publication with ancestry
956 ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
957 spr = self.factory.makeSourcePackageRelease()
958 # We don't reference the first spph so it doesn't get a name.
959 self.factory.makeSourcePackagePublishingHistory(
960 sourcepackagerelease=spr, archive=ppa)
961 spph2 = self.factory.makeSourcePackagePublishingHistory(
962 sourcepackagerelease=spr, archive=ppa)
963 spph2.overrideFromAncestry()
964 self.assertEqual("main", spph2.component.name)
965
966 def test_copyTo_with_overrides(self):
967 # Specifying overrides with copyTo should result in the new
968 # publication having those overrides.
969 archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
970 target_archive = self.factory.makeArchive(
971 purpose=ArchivePurpose.PRIMARY)
972 main_component = getUtility(IComponentSet)['main']
973 spph = self.factory.makeSourcePackagePublishingHistory(
974 archive=archive, component=main_component)
975 name = spph.sourcepackagerelease.sourcepackagename
976
977 # Roll with default overrides to reduce the setup.
978 policy = UnknownOverridePolicy()
979 overrides = policy.calculateSourceOverrides(
980 target_archive, None, None, [name])
981 [override] = overrides
982
983 copy = spph.copyTo(
984 spph.distroseries, spph.pocket, target_archive, override)
985
986 # The component is overridden to the default.
987 self.assertEqual('universe', copy.component.name)
988 # Section has no default so it comes from the old publication.
989 self.assertEqual(spph.section, copy.section)
990
991 def test_copyTo_sets_ancestor(self):
992 # SPPH's ancestor get's populated when a spph is copied over.
993 target_archive = self.factory.makeArchive()
994 spph = self.factory.makeSourcePackagePublishingHistory()
995 copy = spph.copyTo(spph.distroseries, spph.pocket, target_archive)
996
997 self.assertEqual(spph, copy.ancestor)
998
999
1000class BuildRecordCreationTests(TestNativePublishingBase):804class BuildRecordCreationTests(TestNativePublishingBase):
1001 """Test the creation of build records."""805 """Test the creation of build records."""
1002806