135
152
layer = DatabaseFunctionalLayer
137
def _setupDifferences(self, name, parent_name, nb_diff_versions,
154
def _setupDifferences(self, name, parent_names, nb_diff_versions,
138
155
nb_diff_child, nb_diff_parent):
139
# Helper to create DSD of the different types.
140
derived_series = self.factory.makeDistroSeries(
142
previous_series=self.factory.makeDistroSeries(name=parent_name))
156
# Helper to create DSDs of the different types.
157
derived_series = self.factory.makeDistroSeries(name=name)
143
158
self.simple_user = self.factory.makePerson()
159
# parent_names can be a list of parent names or a single name
160
# for a single parent (e.g. ['parent1_name', 'parent2_name'] or
162
# If multiple parents are created, the DSDs will be created with
164
if type(parent_names) == str:
165
parent_names = [parent_names]
167
for parent_name in parent_names:
168
parent_series = self.factory.makeDistroSeries(name=parent_name)
169
dsps.append(self.factory.makeDistroSeriesParent(
170
derived_series=derived_series, parent_series=parent_series))
171
first_parent_series = dsps[0].parent_series
144
172
for i in range(nb_diff_versions):
145
173
diff_type = DistroSeriesDifferenceType.DIFFERENT_VERSIONS
146
174
self.factory.makeDistroSeriesDifference(
147
175
derived_series=derived_series,
148
difference_type=diff_type)
176
difference_type=diff_type,
177
parent_series=first_parent_series)
149
178
for i in range(nb_diff_child):
150
179
diff_type = DistroSeriesDifferenceType.MISSING_FROM_DERIVED_SERIES
151
180
self.factory.makeDistroSeriesDifference(
152
181
derived_series=derived_series,
153
difference_type=diff_type)
182
difference_type=diff_type,
183
parent_series=first_parent_series)
154
184
for i in range(nb_diff_parent):
155
185
diff_type = DistroSeriesDifferenceType.UNIQUE_TO_DERIVED_SERIES
156
186
self.factory.makeDistroSeriesDifference(
157
187
derived_series=derived_series,
158
difference_type=diff_type)
188
difference_type=diff_type,
189
parent_series=first_parent_series)
159
190
return derived_series
161
192
def test_differences_no_flag_no_portlet(self):
213
244
self.assertThat(html_content, portlet_display)
246
def test_differences_portlet_all_differences_multiple_parents(self):
247
# The difference portlet shows the differences with the multiple
249
set_derived_series_ui_feature_flag(self)
250
derived_series = self._setupDifferences(
251
'deri', ['sid1', 'sid2'], 0, 1, 0)
252
portlet_display = soupmatchers.HTMLContains(
254
'Derivation portlet header', 'h2',
255
text='Derived from 2 parents'),
257
'Parent diffs link', 'a',
258
text=re.compile('\s*1 package only in a parent series\s*'),
259
attrs={'href': re.compile('.*/\+missingpackages')}))
261
with person_logged_in(self.simple_user):
262
view = create_initialized_view(
265
principal=self.simple_user)
266
# XXX rvb 2011-04-12 bug=758649: LaunchpadTestRequest overrides
267
# self.features to NullFeatureController.
268
view.request.features = get_relevant_feature_controller()
271
self.assertThat(html_text, portlet_display)
215
273
def test_differences_portlet_no_differences(self):
216
274
# The difference portlet displays 'No differences' if there is no
217
275
# differences with the parent.
486
553
self.factory.makePackageset(
488
555
packages=[ds_diff.source_package_name],
489
distroseries=ds_diff.derived_series.previous_series)
556
distroseries=ds_diff.parent_series)
491
558
with person_logged_in(self.simple_user):
492
559
view = create_initialized_view(
493
560
ds_diff.derived_series,
494
561
'+localpackagediffs',
495
562
principal=self.simple_user)
563
html_content = view()
498
565
packageset_text = re.compile(
499
566
'\s*' + ', '.join(sorted(unsorted_names)))
500
567
self._test_packagesets(
501
html, packageset_text, 'parent-packagesets', 'Parent packagesets')
503
def test_queries(self):
568
html_content, packageset_text, 'parent-packagesets',
569
'Parent packagesets')
572
class TestDistroSeriesLocalDiffPerformance(TestCaseWithFactory,
573
DistroSeriesDifferenceMixin):
574
"""Test the distroseries +localpackagediffs page's performance."""
576
layer = DatabaseFunctionalLayer
579
super(TestDistroSeriesLocalDiffPerformance,
580
self).setUp('foo.bar@canonical.com')
581
set_derived_series_ui_feature_flag(self)
582
self.simple_user = self.factory.makePerson()
584
def _assertQueryCount(self, derived_series):
504
585
# With no DistroSeriesDifferences the query count should be low and
505
586
# fairly static. However, with some DistroSeriesDifferences the query
506
587
# count will be higher, but it should remain the same no matter how
507
588
# many differences there are.
508
derived_series = self.factory.makeDistroSeries(
509
previous_series=self.factory.makeDistroSeries())
510
589
ArchivePermission(
511
590
archive=derived_series.main_archive, person=self.simple_user,
512
591
component=getUtility(IComponentSet)["main"],
605
684
"statement-count-per-row-average",
606
685
text_content(u"%.2f" % statement_count_per_row))
607
# XXX: GavinPanella 2011-04-12 bug=760733: Reducing the query count
608
# further needs work. Ideally this test would be along the lines of
609
# recorder3.count == recorder2.count. 4 queries above the recorder2
610
# count is 2 queries per difference which is not acceptable, but is
611
# *far* better than without the changes introduced by landing this.
612
compromise_statement_count = recorder2.count + 4
686
# Query count is ~O(1) (i.e. not dependent of the number of
687
# differences displayed).
614
recorder3, HasQueryCount(
615
LessThan(compromise_statement_count + 1)))
618
class TestDistroSeriesLocalDifferencesZopeless(TestCaseWithFactory):
689
recorder3, HasQueryCount(Equals(recorder2.count)))
691
def test_queries_single_parent(self):
692
dsp = self.factory.makeDistroSeriesParent()
693
derived_series = dsp.derived_series
694
self._assertQueryCount(derived_series)
696
def test_queries_multiple_parents(self):
697
dsp = self.factory.makeDistroSeriesParent()
698
derived_series = dsp.derived_series
699
self.factory.makeDistroSeriesParent(
700
derived_series=derived_series)
701
self._assertQueryCount(derived_series)
704
class TestDistroSeriesLocalDifferencesZopeless(TestCaseWithFactory,
705
DistroSeriesDifferenceMixin):
619
706
"""Test the distroseries +localpackagediffs view."""
621
layer = LaunchpadZopelessLayer
708
layer = LaunchpadFunctionalLayer
710
def makePackageUpgrade(self, derived_series=None):
711
"""Create a `DistroSeriesDifference` for a package upgrade."""
712
base_version = '1.%d' % self.factory.getUniqueInteger()
714
'base': base_version,
715
'parent': base_version + '-' + self.factory.getUniqueString(),
716
'derived': base_version,
718
return self.factory.makeDistroSeriesDifference(
719
derived_series=derived_series, versions=versions,
720
set_base_version=True)
722
def makeView(self, distroseries=None):
723
"""Create a +localpackagediffs view for `distroseries`."""
724
if distroseries is None:
726
self.factory.makeDistroSeriesParent().derived_series)
727
# current_request=True causes the current interaction to end so we
728
# must explicitly ask that the current principal be used for the
730
return create_initialized_view(
731
distroseries, '+localpackagediffs',
732
principal=get_current_principal(),
733
current_request=True)
623
735
def test_view_redirects_without_feature_flag(self):
624
# If the feature flag soyuz.derived-series-ui.enabled is not set the
736
# If the feature flag soyuz.derived_series_ui.enabled is not set the
625
737
# view simply redirects to the derived series.
626
derived_series = self.factory.makeDistroSeries(
627
name='derilucid', previous_series=self.factory.makeDistroSeries(
738
derived_series, parent_series = self._createChildAndParent()
631
None, getFeatureFlag('soyuz.derived-series-ui.enabled'))
632
view = create_initialized_view(
633
derived_series, '+localpackagediffs')
741
None, getFeatureFlag('soyuz.derived_series_ui.enabled'))
742
view = self.makeView(derived_series)
635
744
response = view.request.response
636
745
self.assertEqual(302, response.getStatus())
640
749
def test_label(self):
641
750
# The view label includes the names of both series.
642
derived_series = self.factory.makeDistroSeries(
643
name='derilucid', previous_series=self.factory.makeDistroSeries(
751
derived_series, parent_series = self._createChildAndParent()
646
view = create_initialized_view(
647
derived_series, '+localpackagediffs')
753
view = self.makeView(derived_series)
649
755
self.assertEqual(
650
756
"Source package differences between 'Derilucid' and "
651
757
"parent series 'Lucid'",
760
def test_label_multiple_parents(self):
761
# If the series has multiple parents, the view label mentions
762
# the generic term 'parent series'.
763
derived_series, parent_series = self._createChildAndParents()
765
view = create_initialized_view(
766
derived_series, '+localpackagediffs')
769
"Source package differences between 'Derilucid' and "
654
773
def test_batch_includes_needing_attention_only(self):
655
774
# The differences attribute includes differences needing
656
775
# attention only.
657
derived_series = self.factory.makeDistroSeries(
658
name='derilucid', previous_series=self.factory.makeDistroSeries(
776
derived_series, parent_series = self._createChildAndParent()
660
777
current_difference = self.factory.makeDistroSeriesDifference(
661
778
derived_series=derived_series)
662
779
self.factory.makeDistroSeriesDifference(
663
780
derived_series=derived_series,
664
781
status=DistroSeriesDifferenceStatus.RESOLVED)
666
view = create_initialized_view(
667
derived_series, '+localpackagediffs')
783
view = self.makeView(derived_series)
669
785
self.assertContentEqual(
670
786
[current_difference], view.cached_differences.batch)
672
788
def test_batch_includes_different_versions_only(self):
673
789
# The view contains differences of type DIFFERENT_VERSIONS only.
674
derived_series = self.factory.makeDistroSeries(
675
name='derilucid', previous_series=self.factory.makeDistroSeries(
790
derived_series, parent_series = self._createChildAndParent()
677
791
different_versions_diff = self.factory.makeDistroSeriesDifference(
678
792
derived_series=derived_series)
679
793
self.factory.makeDistroSeriesDifference(
729
836
def test_diff_row_links_to_extra_details(self):
730
837
# The source package name links to the difference details.
731
derived_series = self.factory.makeDistroSeries(
732
name='derilucid', previous_series=self.factory.makeDistroSeries(
838
derived_series, parent_series = self._createChildAndParent()
734
839
difference = self.factory.makeDistroSeriesDifference(
735
840
derived_series=derived_series)
737
842
set_derived_series_ui_feature_flag(self)
738
view = create_initialized_view(
739
derived_series, '+localpackagediffs')
843
view = self.makeView(derived_series)
740
844
soup = BeautifulSoup(view())
741
845
diff_table = soup.find('table', {'class': 'listing'})
742
846
row = diff_table.tbody.findAll('tr')[0]
744
href = canonical_url(difference).replace('http://launchpad.dev', '')
745
links = row.findAll('a', href=href)
848
links = row.findAll('a', href=canonical_url(difference))
746
849
self.assertEqual(1, len(links))
747
850
self.assertEqual(difference.source_package_name.name, links[0].string)
852
def test_multiple_parents_display(self):
853
package_name = 'package-1'
854
other_parent_series = self.factory.makeDistroSeries(name='other')
855
derived_series, parent_series = self._createChildAndParents(
856
other_parent_series=other_parent_series)
859
'derived': u'1.0derived1',
863
self.factory.makeDistroSeriesDifference(
865
parent_series=other_parent_series,
866
source_package_name_str=package_name,
867
derived_series=derived_series)
868
self.factory.makeDistroSeriesDifference(
870
parent_series=parent_series,
871
source_package_name_str=package_name,
872
derived_series=derived_series)
873
set_derived_series_ui_feature_flag(self)
874
view = create_initialized_view(
875
derived_series, '+localpackagediffs')
876
multiple_parents_matches = soupmatchers.HTMLContains(
878
"Parent table header", 'th',
879
text=re.compile("\s*Parent\s")),
881
"Parent version table header", 'th',
882
text=re.compile("\s*Parent version\s*")),
885
attrs={'class': 'parent-name'},
886
text=re.compile("\s*Other\s*")),
888
self.assertThat(view.render(), multiple_parents_matches)
749
890
def test_diff_row_shows_version_attached(self):
750
891
# The +localpackagediffs page shows the version attached to the
751
892
# DSD and not the last published version (bug=745776).
752
893
package_name = 'package-1'
753
derived_series = self.factory.makeDistroSeries(
754
name='derilucid', previous_series=self.factory.makeDistroSeries(
894
derived_series, parent_series = self._createChildAndParent()
758
897
'derived': u'1.0derived1',
836
974
self.assertEqual(versions['derived'], derived_span[0].string.strip())
837
975
self.assertEqual(versions['parent'], parent_span[0].string.strip())
840
class TestDistroSeriesLocalDifferencesFunctional(TestCaseWithFactory):
977
def test_getUpgrades_shows_updates_in_parent(self):
978
# The view's getUpgrades methods lists packages that can be
979
# trivially upgraded: changed in the parent, not changed in the
980
# derived series, but present in both.
981
dsd = self.makePackageUpgrade()
982
view = self.makeView(dsd.derived_series)
983
self.assertContentEqual([dsd], view.getUpgrades())
985
def enableDerivedSeriesSyncFeature(self):
988
{u'soyuz.derived_series_sync.enabled': u'on'}))
990
@with_celebrity_logged_in("admin")
991
def test_upgrades_offered_only_with_feature_flag(self):
992
# The "Upgrade Packages" button will only be shown when a specific
993
# feature flag is enabled.
994
view = self.makeView()
995
self.makePackageUpgrade(view.context)
996
self.assertFalse(view.canUpgrade())
997
self.enableDerivedSeriesSyncFeature()
998
self.assertTrue(view.canUpgrade())
1000
def test_upgrades_are_offered_if_appropriate(self):
1001
# The "Upgrade Packages" button will only be shown to privileged
1003
self.enableDerivedSeriesSyncFeature()
1004
dsd = self.makePackageUpgrade()
1005
view = self.makeView(dsd.derived_series)
1006
with celebrity_logged_in("admin"):
1007
self.assertTrue(view.canUpgrade())
1008
with person_logged_in(self.factory.makePerson()):
1009
self.assertFalse(view.canUpgrade())
1010
with anonymous_logged_in():
1011
self.assertFalse(view.canUpgrade())
1013
@with_celebrity_logged_in("admin")
1014
def test_upgrades_offered_only_if_available(self):
1015
# If there are no upgrades, the "Upgrade Packages" button won't
1017
self.enableDerivedSeriesSyncFeature()
1018
view = self.makeView()
1019
self.assertFalse(view.canUpgrade())
1020
self.makePackageUpgrade(view.context)
1021
self.assertTrue(view.canUpgrade())
1023
@with_celebrity_logged_in("admin")
1024
def test_upgrades_not_offered_after_feature_freeze(self):
1025
# There won't be an "Upgrade Packages" button once feature
1026
# freeze has occurred. Mass updates would not make sense after
1028
self.enableDerivedSeriesSyncFeature()
1030
for status in SeriesStatus.items:
1031
dsd = self.makePackageUpgrade()
1032
dsd.derived_series.status = status
1033
view = self.makeView(dsd.derived_series)
1034
upgradeable[status] = view.canUpgrade()
1036
SeriesStatus.FUTURE: True,
1037
SeriesStatus.EXPERIMENTAL: True,
1038
SeriesStatus.DEVELOPMENT: True,
1039
SeriesStatus.FROZEN: False,
1040
SeriesStatus.CURRENT: False,
1041
SeriesStatus.SUPPORTED: False,
1042
SeriesStatus.OBSOLETE: False,
1044
self.assertEqual(expected, upgradeable)
1046
def test_upgrade_creates_sync_jobs(self):
1047
# requestUpgrades generates PackageCopyJobs for the upgrades
1049
dsd = self.makePackageUpgrade()
1050
series = dsd.derived_series
1051
view = self.makeView(series)
1052
view.requestUpgrades()
1053
job_source = getUtility(IPlainPackageCopyJobSource)
1055
job_source.getActiveJobs(series.distribution.main_archive))
1056
self.assertEquals(1, len(jobs))
1058
self.assertEquals(series, job.target_distroseries)
1059
source_package_info = list(job.source_packages)
1060
self.assertEquals(1, len(source_package_info))
1062
(dsd.source_package_name.name, dsd.parent_source_version),
1063
source_package_info[0][:2])
1065
def test_upgrade_gives_feedback(self):
1066
# requestUpgrades doesn't instantly perform package upgrades,
1067
# but it shows the user a notice that the upgrades have been
1069
dsd = self.makePackageUpgrade()
1070
view = self.makeView(dsd.derived_series)
1071
view.requestUpgrades()
1073
"level": BrowserNotificationLevel.INFO,
1075
("Upgrades of {0.displayname} packages have been "
1076
"requested. Please give Launchpad some time to "
1077
"complete these.").format(dsd.derived_series),
1079
observed = map(vars, view.request.response.notifications)
1080
self.assertEqual([expected], observed)
1082
def test_requestUpgrade_is_efficient(self):
1083
# A single web request may need to schedule large numbers of
1084
# package upgrades. It must do so without issuing large numbers
1085
# of database queries.
1086
derived_series, parent_series = self._createChildAndParent()
1087
# Take a baseline measure of queries.
1088
self.makePackageUpgrade(derived_series=derived_series)
1089
flush_database_caches()
1090
with StormStatementRecorder() as recorder1:
1091
self.makeView(derived_series).requestUpgrades()
1092
self.assertThat(recorder1, HasQueryCount(LessThan(10)))
1093
# The query count does not increase with more differences.
1094
for index in xrange(3):
1095
self.makePackageUpgrade(derived_series=derived_series)
1096
flush_database_caches()
1097
with StormStatementRecorder() as recorder2:
1098
self.makeView(derived_series).requestUpgrades()
1099
self.assertThat(recorder2, HasQueryCount(Equals(recorder1.count)))
1102
class TestDistroSeriesLocalDifferencesFunctional(TestCaseWithFactory,
1103
DistroSeriesDifferenceMixin):
842
1105
layer = LaunchpadFunctionalLayer
1107
def makeDSDJob(self, dsd):
1108
"""Create a `DistroSeriesDifferenceJob` to update `dsd`."""
1109
job_source = getUtility(IDistroSeriesDifferenceJobSource)
1110
jobs = job_source.createForPackagePublication(
1111
dsd.derived_series, dsd.source_package_name,
1112
PackagePublishingPocket.RELEASE)
844
1115
def test_higher_radio_mentions_parent(self):
1116
# The user is shown an option to display only the blacklisted
1117
# package with a higer version than in the parent.
845
1118
set_derived_series_ui_feature_flag(self)
846
previous_series = self.factory.makeDistroSeries(
847
name='lucid', displayname='Lucid')
848
derived_series = self.factory.makeDistroSeries(
849
name='derilucid', previous_series=previous_series)
1119
derived_series, parent_series = self._createChildAndParent()
850
1120
self.factory.makeDistroSeriesDifference(
851
1121
derived_series=derived_series,
852
1122
source_package_name_str="my-src-package")
1009
1288
difference_type=None, distribution=None):
1010
1289
# Helper to create a derived series with fixed names and proper
1011
1290
# source package format selection along with a DSD.
1012
previous_series = self.factory.makeDistroSeries(name='warty')
1291
parent_series = self.factory.makeDistroSeries(name='warty')
1013
1292
if distribution == None:
1014
1293
distribution = self.factory.makeDistribution('deribuntu')
1015
1294
derived_series = self.factory.makeDistroSeries(
1016
1295
distribution=distribution,
1017
name='derilucid', previous_series=previous_series)
1297
self.factory.makeDistroSeriesParent(
1298
derived_series=derived_series, parent_series=parent_series)
1018
1299
self._set_source_selection(derived_series)
1019
self.factory.makeDistroSeriesDifference(
1300
diff = self.factory.makeDistroSeriesDifference(
1020
1301
source_package_name_str=src_name,
1021
1302
derived_series=derived_series, versions=versions,
1022
1303
difference_type=difference_type)
1023
1304
sourcepackagename = self.factory.getOrMakeSourcePackageName(
1025
1306
set_derived_series_ui_feature_flag(self)
1026
return derived_series, previous_series, sourcepackagename
1307
return derived_series, parent_series, sourcepackagename, str(diff.id)
1028
1309
def test_canPerformSync_anon(self):
1029
1310
# Anonymous users cannot sync packages.
1082
1363
self.assertFalse(view.canPerformSync())
1365
def test_hasPendingDSDUpdate_returns_False_if_no_pending_update(self):
1366
dsd = self.factory.makeDistroSeriesDifference()
1367
view = create_initialized_view(
1368
dsd.derived_series, '+localpackagediffs')
1369
self.assertFalse(view.hasPendingDSDUpdate(dsd))
1371
def test_hasPendingDSDUpdate_returns_True_if_pending_update(self):
1372
set_derived_series_difference_jobs_feature_flag(self)
1373
dsd = self.factory.makeDistroSeriesDifference()
1374
self.makeDSDJob(dsd)
1375
view = create_initialized_view(
1376
dsd.derived_series, '+localpackagediffs')
1377
self.assertTrue(view.hasPendingDSDUpdate(dsd))
1379
def test_hasPendingSync_returns_False_if_no_pending_sync(self):
1380
dsd = self.factory.makeDistroSeriesDifference()
1381
view = create_initialized_view(
1382
dsd.derived_series, '+localpackagediffs')
1383
self.assertFalse(view.hasPendingSync(dsd))
1385
def test_hasPendingSync_returns_True_if_pending_sync(self):
1386
dsd = self.factory.makeDistroSeriesDifference()
1387
view = create_initialized_view(
1388
dsd.derived_series, '+localpackagediffs')
1389
view.pending_syncs = {specify_dsd_package(dsd): object()}
1390
self.assertTrue(view.hasPendingSync(dsd))
1392
def test_isNewerThanParent_compares_versions_not_strings(self):
1393
# isNewerThanParent compares Debian-style version numbers, not
1394
# raw version strings. So it's possible for a child version to
1395
# be considered newer than the corresponding parent version even
1396
# though a string comparison goes the other way.
1397
versions = dict(base='1.0', parent='1.1c', derived='1.10')
1398
dsd = self.factory.makeDistroSeriesDifference(versions=versions)
1399
view = create_initialized_view(
1400
dsd.derived_series, '+localpackagediffs')
1402
# Assumption for the test: the child version is greater than the
1403
# parent version, but a string comparison puts them the other
1405
self.assertFalse(versions['parent'] < versions['derived'])
1407
Version(versions['parent']) < Version(versions['derived']))
1409
# isNewerThanParent is not fooled by the misleading string
1411
self.assertTrue(view.isNewerThanParent(dsd))
1413
def test_isNewerThanParent_is_False_for_parent_update(self):
1414
dsd = self.factory.makeDistroSeriesDifference(
1415
versions=dict(base='1.0', parent='1.1', derived='1.0'))
1416
view = create_initialized_view(
1417
dsd.derived_series, '+localpackagediffs')
1418
self.assertFalse(view.isNewerThanParent(dsd))
1420
def test_isNewerThanParent_is_False_for_equivalent_updates(self):
1421
# Some non-identical version numbers compare as "equal." If the
1422
# child and parent versions compare as equal, the child version
1423
# is not considered newer.
1424
dsd = self.factory.makeDistroSeriesDifference(
1425
versions=dict(base='1.0', parent='1.1', derived='1.1'))
1426
view = create_initialized_view(
1427
dsd.derived_series, '+localpackagediffs')
1428
self.assertFalse(view.isNewerThanParent(dsd))
1430
def test_isNewerThanParent_is_True_for_child_update(self):
1431
dsd = self.factory.makeDistroSeriesDifference(
1432
versions=dict(base='1.0', parent='1.0', derived='1.1'))
1433
view = create_initialized_view(
1434
dsd.derived_series, '+localpackagediffs')
1435
self.assertTrue(view.isNewerThanParent(dsd))
1437
def test_canRequestSync_returns_False_if_pending_sync(self):
1438
dsd = self.factory.makeDistroSeriesDifference()
1439
view = create_initialized_view(
1440
dsd.derived_series, '+localpackagediffs')
1441
view.pending_syncs = {specify_dsd_package(dsd): object()}
1442
self.assertFalse(view.canRequestSync(dsd))
1444
def test_canRequestSync_returns_False_if_child_is_newer(self):
1445
dsd = self.factory.makeDistroSeriesDifference(
1446
versions=dict(base='1.0', parent='1.0', derived='1.1'))
1447
view = create_initialized_view(
1448
dsd.derived_series, '+localpackagediffs')
1449
self.assertFalse(view.canRequestSync(dsd))
1451
def test_canRequestSync_returns_True_if_sync_makes_sense(self):
1452
dsd = self.factory.makeDistroSeriesDifference()
1453
view = create_initialized_view(
1454
dsd.derived_series, '+localpackagediffs')
1455
self.assertTrue(view.canRequestSync(dsd))
1457
def test_canRequestSync_ignores_DSDJobs(self):
1458
dsd = self.factory.makeDistroSeriesDifference()
1459
view = create_initialized_view(
1460
dsd.derived_series, '+localpackagediffs')
1461
view.hasPendingDSDUpdate = FakeMethod(result=True)
1462
self.assertTrue(view.canRequestSync(dsd))
1464
def test_describeJobs_returns_None_if_no_jobs(self):
1465
dsd = self.factory.makeDistroSeriesDifference()
1466
view = create_initialized_view(
1467
dsd.derived_series, '+localpackagediffs')
1468
self.assertIs(None, view.describeJobs(dsd))
1470
def test_describeJobs_reports_pending_update(self):
1471
dsd = self.factory.makeDistroSeriesDifference()
1472
view = create_initialized_view(
1473
dsd.derived_series, '+localpackagediffs')
1474
view.hasPendingDSDUpdate = FakeMethod(result=True)
1475
view.hasPendingSync = FakeMethod(result=False)
1476
self.assertEqual("updating…", view.describeJobs(dsd))
1478
def test_describeJobs_reports_pending_sync(self):
1479
dsd = self.factory.makeDistroSeriesDifference()
1480
view = create_initialized_view(
1481
dsd.derived_series, '+localpackagediffs')
1482
view.hasPendingDSDUpdate = FakeMethod(result=False)
1483
view.hasPendingSync = FakeMethod(result=True)
1484
self.assertEqual("synchronizing…", view.describeJobs(dsd))
1486
def test_describeJobs_reports_pending_sync_and_update(self):
1487
dsd = self.factory.makeDistroSeriesDifference()
1488
view = create_initialized_view(
1489
dsd.derived_series, '+localpackagediffs')
1490
view.hasPendingDSDUpdate = FakeMethod(result=True)
1491
view.hasPendingSync = FakeMethod(result=True)
1493
"updating and synchronizing…", view.describeJobs(dsd))
1084
1495
def _syncAndGetView(self, derived_series, person, sync_differences,
1085
1496
difference_type=None, view_name='+localpackagediffs'):
1086
1497
# A helper to get the POST'ed sync view.
1143
1557
def test_sync_success_perm_component(self):
1144
1558
# A user with upload rights on the destination component
1145
1559
# can sync packages.
1146
derived_series, previous_series, sourcepackagename = self._setUpDSD(
1560
derived_series, parent_series, sp_name, diff_id = self._setUpDSD(
1148
1562
person, _ = self.makePersonWithComponentPermission(
1149
1563
derived_series.main_archive,
1150
1564
derived_series.getSourcePackage(
1151
sourcepackagename).latest_published_component)
1565
sp_name).latest_published_component)
1152
1566
view = self._syncAndGetView(
1153
derived_series, person, ['my-src-name'])
1567
derived_series, person, [diff_id])
1155
1569
self.assertEqual(0, len(view.errors))
1157
1571
def test_sync_error_no_perm_component(self):
1158
1572
# A user without upload rights on the destination component
1159
1573
# will get an error when he syncs packages to this component.
1160
derived_series, previous_series, sourcepackagename = self._setUpDSD(
1574
derived_series, parent_series, unused, diff_id = self._setUpDSD(
1162
1576
person, another_component = self.makePersonWithComponentPermission(
1163
1577
derived_series.main_archive)
1164
1578
set_derived_series_sync_feature_flag(self)
1165
1579
view = self._syncAndGetView(
1166
derived_series, person, ['my-src-name'])
1580
derived_series, person, [diff_id])
1168
1582
self.assertEqual(1, len(view.errors))
1169
1583
self.assertTrue(
1235
1649
'parent': '1.0-1',
1237
1651
missing = DistroSeriesDifferenceType.MISSING_FROM_DERIVED_SERIES
1238
derived_series, previous_series, sourcepackagename = self._setUpDSD(
1652
derived_series, parent_series, unused, diff_id = self._setUpDSD(
1239
1653
'my-src-name', difference_type=missing, versions=versions)
1240
1654
person, another_component = self.makePersonWithComponentPermission(
1241
1655
derived_series.main_archive)
1242
1656
set_derived_series_sync_feature_flag(self)
1243
1657
view = self._syncAndGetView(
1244
derived_series, person, ['my-src-name'],
1658
derived_series, person, [diff_id],
1245
1659
view_name='+missingpackages')
1247
1661
self.assertPackageCopied(
1248
1662
derived_series, 'my-src-name', versions['parent'], view)
1251
1664
def test_sync_in_released_series_in_updates(self):
1252
1665
# If the destination series is released, the sync packages end
1253
1666
# up in the updates pocket.
1255
1668
'parent': '1.0-1',
1257
derived_series, previous_series, sourcepackagename = self._setUpDSD(
1670
derived_series, parent_series, sp_name, diff_id = self._setUpDSD(
1258
1671
'my-src-name', versions=versions)
1259
1672
# Update destination series status to current and update