209
210
self.assertIs(None, ds_diff.package_diff)
210
211
self.assertIs(None, ds_diff.parent_package_diff)
212
def test_update_re_opens_difference(self):
213
# The status of a resolved difference will updated with new
215
ds_diff = self.factory.makeDistroSeriesDifference(
216
source_package_name_str="foonew",
221
status=DistroSeriesDifferenceStatus.RESOLVED)
222
new_derived_pub = self.factory.makeSourcePackagePublishingHistory(
213
def test_parent_update_re_opens_difference(self):
214
# The status of a resolved difference will be updated to
215
# NEEDS_ATTENTION with parent uploads.
216
ds_diff = self.factory.makeDistroSeriesDifference(
217
source_package_name_str="foonew",
218
versions=dict(parent='1.0', derived='1.0'),
219
status=DistroSeriesDifferenceStatus.RESOLVED)
220
new_parent_pub = self.factory.makeSourcePackagePublishingHistory(
221
sourcepackagename=ds_diff.source_package_name,
222
distroseries=ds_diff.parent_series,
223
status=PackagePublishingStatus.PENDING,
226
was_updated = ds_diff.update()
228
self.assertTrue(was_updated)
230
DistroSeriesDifferenceStatus.NEEDS_ATTENTION,
233
def test_child_update_re_opens_difference(self):
234
# The status of a resolved difference will updated to
235
# BLACKLISTED_CURRENT with child uploads.
236
ds_diff = self.factory.makeDistroSeriesDifference(
237
source_package_name_str="foonew",
238
versions=dict(parent='1.0', derived='1.0'),
239
status=DistroSeriesDifferenceStatus.RESOLVED)
240
self.factory.makeSourcePackagePublishingHistory(
223
241
sourcepackagename=ds_diff.source_package_name,
224
242
distroseries=ds_diff.derived_series,
225
243
status=PackagePublishingStatus.PENDING,
409
427
packagesets.append(ps)
410
428
return packagesets
412
def test_getParentPackageSets(self):
430
def test_parent_packagesets(self):
413
431
# All parent's packagesets are returned ordered alphabetically.
414
432
ds_diff = self.factory.makeDistroSeriesDifference()
415
433
packagesets = self._setupPackageSets(
416
ds_diff, ds_diff.derived_series.previous_series, 5)
417
parent_packagesets = ds_diff.getParentPackageSets()
434
ds_diff, ds_diff.parent_series, 5)
435
parent_packagesets = ds_diff.parent_packagesets
418
436
self.assertEquals(
419
437
sorted([packageset.name for packageset in packagesets]),
420
438
[packageset.name for packageset in parent_packagesets])
422
def test_getPackageSets(self):
440
def test_packagesets(self):
423
441
# All the packagesets are returned ordered alphabetically.
424
442
ds_diff = self.factory.makeDistroSeriesDifference()
425
443
packagesets = self._setupPackageSets(
426
444
ds_diff, ds_diff.derived_series, 5)
427
445
self.assertEquals(
428
446
sorted([packageset.name for packageset in packagesets]),
429
[packageset.name for packageset in ds_diff.getPackageSets()])
447
[packageset.name for packageset in ds_diff.packagesets])
449
def test_blacklist_unauthorised(self):
450
# If you're not an archive admin, you don't get to blacklist or
452
ds_diff = self.factory.makeDistroSeriesDifference()
453
random_joe = self.factory.makePerson()
454
with person_logged_in(random_joe):
455
self.assertRaises(Unauthorized, getattr, ds_diff, 'blacklist')
456
self.assertRaises(Unauthorized, getattr, ds_diff, 'unblacklist')
431
458
def test_blacklist_default(self):
432
459
# By default the current version is blacklisted.
433
460
ds_diff = self.factory.makeDistroSeriesDifference()
461
admin = self.factory.makeArchiveAdmin(
462
ds_diff.derived_series.main_archive)
435
with person_logged_in(self.factory.makePerson()):
464
with person_logged_in(admin):
436
465
ds_diff.blacklist()
438
467
self.assertEqual(
508
543
def test_base_version_none(self):
509
544
# The attribute is set to None if there is no common base version.
510
545
# Publish different versions in the series.
511
derived_series = self.factory.makeDistroSeries(
512
previous_series=self.factory.makeDistroSeries())
546
dsp = self.factory.makeDistroSeriesParent()
513
547
source_package_name = self.factory.getOrMakeSourcePackageName('foo')
514
548
self.factory.makeSourcePackagePublishingHistory(
515
distroseries=derived_series,
549
distroseries=dsp.derived_series,
516
550
version='1.0deri1',
517
551
sourcepackagename=source_package_name,
518
552
status=PackagePublishingStatus.PUBLISHED)
519
553
self.factory.makeSourcePackagePublishingHistory(
520
distroseries=derived_series.previous_series,
554
distroseries=dsp.parent_series,
521
555
version='1.0ubu2',
522
556
sourcepackagename=source_package_name,
523
557
status=PackagePublishingStatus.PUBLISHED)
528
562
def test_base_version_multiple(self):
529
563
# The latest common base version is set as the base-version.
530
derived_series = self.factory.makeDistroSeries(
531
previous_series=self.factory.makeDistroSeries())
532
source_package_name = self.factory.getOrMakeSourcePackageName('foo')
564
dsp = self.factory.makeDistroSeriesParent()
565
self.factory.getOrMakeSourcePackageName('foo')
533
566
# Create changelogs for both.
534
567
changelog_lfa = self.factory.makeChangelog('foo', ['1.2', '1.1'])
535
568
parent_changelog_lfa = self.factory.makeChangelog('foo', ['1.1'])
536
transaction.commit() # Yay, librarian.
569
transaction.commit() # Yay, librarian.
538
571
ds_diff = self.factory.makeDistroSeriesDifference(
539
derived_series=derived_series, source_package_name_str='foo',
572
derived_series=dsp.derived_series, source_package_name_str='foo',
541
574
'derived': '1.2',
550
583
def test_base_version_invalid(self):
551
584
# If the maximum base version is invalid, it is discarded and not
552
585
# set as the base version.
553
derived_series = self.factory.makeDistroSeries(
554
previous_series=self.factory.makeDistroSeries())
555
source_package_name = self.factory.getOrMakeSourcePackageName('foo')
586
dsp = self.factory.makeDistroSeriesParent()
587
self.factory.getOrMakeSourcePackageName('foo')
556
588
# Create changelogs for both.
557
589
changelog_lfa = self.factory.makeChangelog(
558
590
'foo', ['1:2.0-1', 'a1:1.8.8-070403-1~priv1', '1:1.7-1'])
559
591
parent_changelog_lfa = self.factory.makeChangelog(
560
592
'foo', ['1:2.0-2', 'a1:1.8.8-070403-1~priv1', '1:1.7-1'])
561
transaction.commit() # Yay, librarian.
593
transaction.commit() # Yay, librarian.
563
595
ds_diff = self.factory.makeDistroSeriesDifference(
564
derived_series=derived_series, source_package_name_str='foo',
596
derived_series=dsp.derived_series, source_package_name_str='foo',
566
598
'derived': '1:2.0-1',
567
599
'parent': '1:2.0-2',
743
774
def test_source_package_release_pending(self):
744
775
# source_package_release returns the package release of version
745
776
# source_version with status PUBLISHED or PENDING.
746
derived_series = self.factory.makeDistroSeries(
747
previous_series=self.factory.makeDistroSeries())
777
dsp = self.factory.makeDistroSeriesParent()
748
778
source_package_name = self.factory.getOrMakeSourcePackageName('foo')
749
779
versions = {'derived': u'1.2', 'parent': u'1.3'}
751
781
ds_diff = self.factory.makeDistroSeriesDifference(
752
derived_series=derived_series,
782
derived_series=dsp.derived_series,
753
783
source_package_name_str=source_package_name.name,
754
784
versions=versions)
756
786
# Create pending source package releases.
757
787
self.factory.makeSourcePackagePublishingHistory(
758
distroseries=derived_series,
788
distroseries=dsp.derived_series,
760
790
sourcepackagename=source_package_name,
761
791
status=PackagePublishingStatus.PENDING)
762
792
self.factory.makeSourcePackagePublishingHistory(
763
distroseries=derived_series.previous_series,
793
distroseries=dsp.parent_series,
765
795
sourcepackagename=source_package_name,
766
796
status=PackagePublishingStatus.PENDING)
789
819
def test_existing_packagediff_is_linked_when_dsd_created(self):
790
820
# When a relevant packagediff already exists, it is linked to the
791
821
# DSD when it is created.
792
derived_series = self.factory.makeDistroSeries(
793
previous_series=self.factory.makeDistroSeries())
822
dsp = self.factory.makeDistroSeriesParent()
794
823
spn = self.factory.getOrMakeSourcePackageName(
795
824
name=self.factory.getUniqueString())
796
parent_spph = self.createPublication(
797
spn, ['1.2-1', '1.0-1'], derived_series.previous_series)
825
self.createPublication(
826
spn, ['1.2-1', '1.0-1'], dsp.parent_series)
798
827
spph = self.createPublication(
799
spn, ['1.1-1', '1.0-1'], derived_series)
828
spn, ['1.1-1', '1.0-1'], dsp.derived_series)
800
829
base_spph = self.createPublication(
801
spn, ['1.0-1'], derived_series,
830
spn, ['1.0-1'], dsp.derived_series,
802
831
status=PackagePublishingStatus.SUPERSEDED)
803
832
pd = self.factory.makePackageDiff(
804
833
from_source=base_spph.sourcepackagerelease,
887
916
diffs['normal'].append(
888
917
self.factory.makeDistroSeriesDifference(
889
derived_series=derived_series))
918
derived_series=derived_series, parent_series=parent_series))
890
919
diffs['unique'].append(
891
920
self.factory.makeDistroSeriesDifference(
892
921
derived_series=derived_series,
922
parent_series=parent_series,
893
923
difference_type=(
894
924
DistroSeriesDifferenceType.UNIQUE_TO_DERIVED_SERIES)))
895
925
diffs['ignored'].append(
896
926
self.factory.makeDistroSeriesDifference(
897
927
derived_series=derived_series,
928
parent_series=parent_series,
898
929
status=DistroSeriesDifferenceStatus.BLACKLISTED_CURRENT))
901
def makeDerivedSeries(self):
932
def makeDerivedSeries(self, derived_series=None):
902
933
# Keep tests DRY.
903
return self.factory.makeDistroSeries(
904
previous_series=self.factory.makeDistroSeries())
934
dsp = self.factory.makeDistroSeriesParent(
935
derived_series=derived_series)
936
return dsp.derived_series
938
def makeVersionDifference(self, derived_series=None, changed_parent=False,
939
changed_child=False, status=None):
940
"""Create a `DistroSeriesDifference` between package versions.
942
The differing package will exist in both the parent series and in the
945
:param derived_series: Optional `DistroSeries` that the difference is
946
for. If not given, one will be created.
947
:param changed_parent: Whether the difference should show a change in
948
the parent's version of the package.
949
:param changed_child: Whether the difference should show a change in
950
the child's version of the package.
951
:param status: Optional status for the `DistroSeriesDifference`. If
952
not given, defaults to `NEEDS_ATTENTION`.
955
status = DistroSeriesDifferenceStatus.NEEDS_ATTENTION
956
base_version = "1.%d" % self.factory.getUniqueInteger()
957
versions = dict.fromkeys(('base', 'parent', 'derived'), base_version)
959
versions['parent'] += "-%s" % self.factory.getUniqueString()
961
versions['derived'] += "-%s" % self.factory.getUniqueString()
962
return self.factory.makeDistroSeriesDifference(
963
derived_series=derived_series, versions=versions, status=status,
964
set_base_version=True)
906
966
def test_getForDistroSeries_default(self):
907
967
# By default all differences needing attention for the given
977
1039
[result.source_package_name.name for result in results])
979
def test_getByDistroSeriesAndName(self):
1041
def test_getForDistroSeries_filters_by_parent(self):
1042
# The differences can be filtered by parent series.
1043
dsp = self.factory.makeDistroSeriesParent()
1044
derived_series = dsp.derived_series
1045
parent_series = dsp.parent_series
1047
# Add another parent to this series.
1048
parent_series2 = self.factory.makeDistroSeriesParent(
1049
derived_series=derived_series).parent_series
1051
diffs = self.makeDiffsForDistroSeries(
1052
derived_series, parent_series=parent_series)
1053
diffs2 = self.makeDiffsForDistroSeries(
1054
derived_series, parent_series=parent_series2)
1056
results = getUtility(
1057
IDistroSeriesDifferenceSource).getForDistroSeries(
1058
derived_series, parent_series=parent_series)
1059
results2 = getUtility(
1060
IDistroSeriesDifferenceSource).getForDistroSeries(
1061
derived_series, parent_series=parent_series2)
1063
self.assertContentEqual(diffs['normal'], results)
1064
self.assertContentEqual(diffs2['normal'], results2)
1066
def test_getByDistroSeriesNameAndParentSeries(self):
980
1067
# An individual difference is obtained using the name.
981
1068
ds_diff = self.factory.makeDistroSeriesDifference(
982
1069
source_package_name_str='fooname')
984
1071
dsd_source = getUtility(IDistroSeriesDifferenceSource)
985
result = dsd_source.getByDistroSeriesAndName(
986
ds_diff.derived_series, 'fooname')
1072
result = dsd_source.getByDistroSeriesNameAndParentSeries(
1073
ds_diff.derived_series, 'fooname', ds_diff.parent_series)
988
1075
self.assertEqual(ds_diff, result)
1077
def test_getSimpleUpgrades_finds_simple_update(self):
1078
dsd_source = getUtility(IDistroSeriesDifferenceSource)
1079
dsd = self.makeVersionDifference(changed_parent=True)
1080
self.assertEqual(dsd.base_version, dsd.source_version)
1081
self.assertContentEqual(
1082
[dsd], dsd_source.getSimpleUpgrades(dsd.derived_series))
1084
def test_getSimpleUpgrades_ignores_hidden_differences(self):
1085
invisible_statuses = [
1086
DistroSeriesDifferenceStatus.BLACKLISTED_CURRENT,
1087
DistroSeriesDifferenceStatus.BLACKLISTED_ALWAYS,
1088
DistroSeriesDifferenceStatus.RESOLVED,
1090
dsd_source = getUtility(IDistroSeriesDifferenceSource)
1091
series = self.makeDerivedSeries()
1092
for status in invisible_statuses:
1093
self.makeVersionDifference(
1094
derived_series=series, changed_parent=True, status=status)
1095
self.assertContentEqual([], dsd_source.getSimpleUpgrades(series))
1097
def test_getSimpleUpgrades_ignores_other_distroseries(self):
1098
dsd_source = getUtility(IDistroSeriesDifferenceSource)
1099
self.makeVersionDifference(changed_parent=True)
1100
self.assertContentEqual(
1101
[], dsd_source.getSimpleUpgrades(self.factory.makeDistroSeries()))
1103
def test_getSimpleUpgrades_ignores_packages_changed_in_child(self):
1104
dsd_source = getUtility(IDistroSeriesDifferenceSource)
1105
dsd = self.makeVersionDifference(
1106
changed_parent=True, changed_child=True)
1107
self.assertContentEqual(
1108
[], dsd_source.getSimpleUpgrades(dsd.derived_series))
1110
def test_getSimpleUpgrades_ignores_packages_not_updated_in_parent(self):
1111
dsd_source = getUtility(IDistroSeriesDifferenceSource)
1112
dsd = self.makeVersionDifference(changed_parent=False)
1113
self.assertContentEqual(
1114
[], dsd_source.getSimpleUpgrades(dsd.derived_series))
1116
def test_getSimpleUpgrades_ignores_packages_unique_to_child(self):
1117
dsd_source = getUtility(IDistroSeriesDifferenceSource)
1118
diff_type = DistroSeriesDifferenceType.UNIQUE_TO_DERIVED_SERIES
1119
dsd = self.factory.makeDistroSeriesDifference(
1120
difference_type=diff_type)
1121
self.assertContentEqual(
1122
[], dsd_source.getSimpleUpgrades(dsd.derived_series))
1124
def test_getSimpleUpgrades_ignores_packages_missing_from_child(self):
1125
dsd_source = getUtility(IDistroSeriesDifferenceSource)
1126
diff_type = DistroSeriesDifferenceType.MISSING_FROM_DERIVED_SERIES
1127
dsd = self.factory.makeDistroSeriesDifference(
1128
difference_type=diff_type)
1129
self.assertContentEqual(
1130
[], dsd_source.getSimpleUpgrades(dsd.derived_series))
1132
def test_collateDifferencesByParentArchive(self):
1133
dsp1 = self.factory.makeDistroSeriesParent()
1134
dsp2 = self.factory.makeDistroSeriesParent()
1136
self.factory.makeDistroSeriesDifference(dsp1.derived_series),
1137
self.factory.makeDistroSeriesDifference(dsp2.derived_series),
1138
self.factory.makeDistroSeriesDifference(dsp1.derived_series),
1139
self.factory.makeDistroSeriesDifference(dsp2.derived_series),
1141
dsd_source = getUtility(IDistroSeriesDifferenceSource)
1143
dsd_source.collateDifferencesByParentArchive(differences))
1145
dsp1.parent_series.main_archive: differences[0::2],
1146
dsp2.parent_series.main_archive: differences[1::2],
1148
self.assertEqual(observed, expected)
991
1151
class TestMostRecentComments(TestCaseWithFactory):
993
1153
layer = DatabaseFunctionalLayer
995
1155
def test_most_recent_comments(self):
996
derived_series = self.factory.makeDistroSeries(
997
previous_series=self.factory.makeDistroSeries())
1156
dsp = self.factory.makeDistroSeriesParent()
999
1158
self.factory.makeDistroSeriesDifference(
1000
derived_series=derived_series) for index in xrange(5))
1159
derived_series=dsp.derived_series) for index in xrange(5))
1001
1160
expected_comments = set()
1002
1161
for dsd in dsds:
1003
1162
# Add a couple of comments.