18
18
from __future__ import absolute_import
19
19
from __future__ import unicode_literals
20
20
from tests import support
21
- from tests .support import mock
21
+ from tests .support import mock , mockSwdbPkg
22
22
23
23
import dnf .cli .commands
24
24
import dnf .cli .commands .group
@@ -192,6 +192,26 @@ def test_run_notinstalled(self):
192
192
self .assertResult (self ._cmd .cli .base ,
193
193
self ._cmd .cli .base .sack .query ().installed ())
194
194
195
+ @mock .patch ('dnf.cli.commands.reinstall._' , dnf .pycomp .NullTranslations ().ugettext )
196
+ def test_run_notavailable (self ):
197
+ """ Test whether it fails if the package is not available. """
198
+ base = self ._cmd .cli .base
199
+ holes_query = dnf .subject .Subject ('hole' ).get_best_query (base .sack )
200
+ history = self ._cmd .base .history
201
+ for pkg in holes_query .installed ():
202
+ mockSwdbPkg (history , pkg )
203
+
204
+ stdout = dnf .pycomp .StringIO ()
205
+
206
+ with support .wiretap_logs ('dnf' , logging .INFO , stdout ):
207
+ self .assertRaises (dnf .exceptions .Error , support .command_run , self ._cmd , ['hole' ])
208
+
209
+ self .assertEqual (
210
+ stdout .getvalue (),
211
+ 'Installed package hole-1-1.x86_64 (from unknown) not available.\n ' )
212
+ self .assertResult (base , base .sack .query ().installed ())
213
+
214
+
195
215
class RepoPkgsCommandTest (unittest .TestCase ):
196
216
197
217
"""Tests of ``dnf.cli.commands.RepoPkgsCommand`` class."""
@@ -214,6 +234,34 @@ class RepoPkgsCheckUpdateSubCommandTest(unittest.TestCase):
214
234
215
235
"""Tests of ``dnf.cli.commands.RepoPkgsCommand.CheckUpdateSubCommand`` class."""
216
236
237
+ def test (self ):
238
+ """ Test whether only upgrades in the repository are listed. """
239
+ history = self .cli .base .history
240
+ for pkg in self .cli .base .sack .query ().installed ().filter (name = 'tour' ):
241
+ mockSwdbPkg (history , pkg , repo = 'updates' )
242
+
243
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
244
+ with support .patch_std_streams () as (stdout , _ ):
245
+ support .command_run (cmd , ['updates' , 'check-update' ])
246
+
247
+ self .assertEqual (
248
+ stdout .getvalue (),
249
+ u'\n '
250
+ u'hole.x86_64 2-1'
251
+ u' updates \n '
252
+ u'pepper.x86_64 20-1'
253
+ u' updates \n '
254
+ u'Obsoleting Packages\n '
255
+ u'hole.i686 2-1'
256
+ u' updates \n '
257
+ u' tour.noarch 5-0'
258
+ u' @updates\n '
259
+ u'hole.x86_64 2-1'
260
+ u' updates \n '
261
+ u' tour.noarch 5-0'
262
+ u' @updates\n ' )
263
+ self .assertEqual (self .cli .demands .success_exit_status , 100 )
264
+
217
265
def setUp (self ):
218
266
"""Prepare the test fixture."""
219
267
super (RepoPkgsCheckUpdateSubCommandTest , self ).setUp ()
@@ -287,6 +335,45 @@ def setUp(self):
287
335
base .conf .recent = 7
288
336
self .cli = base .mock_cli ()
289
337
338
+ def test_info_all (self ):
339
+ """Test whether only packages related to the repository are listed."""
340
+ history = self .cli .base .history
341
+ for pkg in self .cli .base .sack .query ().installed ().filter (name = 'pepper' ):
342
+ mockSwdbPkg (history , pkg , repo = 'main' )
343
+
344
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
345
+ with support .patch_std_streams () as (stdout , _ ):
346
+ support .command_run (cmd , ['main' , 'info' , 'all' , '*p*' ])
347
+
348
+ self .assertEqual (
349
+ stdout .getvalue (),
350
+ '' .join ((
351
+ self .INSTALLED_TITLE ,
352
+ self .PEPPER_SYSTEM_INFO ,
353
+ self .AVAILABLE_TITLE ,
354
+ u'Name : pepper\n '
355
+ u'Version : 20\n '
356
+ u'Release : 0\n '
357
+ u'Arch : src\n '
358
+ u'Size : 0.0 \n '
359
+ u'Source : None\n '
360
+ u'Repo : main\n '
361
+ u'Summary : \n '
362
+ u'License : \n '
363
+ u'Description : \n '
364
+ u'\n ' ,
365
+ u'Name : trampoline\n '
366
+ u'Version : 2.1\n '
367
+ u'Release : 1\n '
368
+ u'Arch : noarch\n '
369
+ u'Size : 0.0 \n '
370
+ u'Source : None\n '
371
+ u'Repo : main\n '
372
+ u'Summary : \n '
373
+ u'License : \n '
374
+ u'Description : \n '
375
+ u'\n ' )))
376
+
290
377
def test_info_available (self ):
291
378
"""Test whether only packages in the repository are listed."""
292
379
cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
@@ -301,6 +388,45 @@ def test_info_available(self):
301
388
self .HOLE_X86_64_INFO ,
302
389
self .PEPPER_UPDATES_INFO )))
303
390
391
+ def test_info_extras (self ):
392
+ """Test whether only extras installed from the repository are listed."""
393
+ history = self .cli .base .history
394
+ for pkg in self .cli .base .sack .query ().installed ().filter (name = 'tour' ):
395
+ mockSwdbPkg (history , pkg , repo = 'main' )
396
+
397
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
398
+ with support .patch_std_streams () as (stdout , _ ):
399
+ support .command_run (cmd , ['main' , 'info' , 'extras' ])
400
+
401
+ self .assertEqual (
402
+ stdout .getvalue (),
403
+ u'Extra Packages\n '
404
+ u'Name : tour\n '
405
+ u'Version : 5\n '
406
+ u'Release : 0\n '
407
+ u'Arch : noarch\n '
408
+ u'Size : 0.0 \n '
409
+ u'Source : None\n '
410
+ u'Repo : @System\n '
411
+ u'From repo : main\n '
412
+ u'Summary : \n '
413
+ u'License : \n '
414
+ u'Description : \n \n ' )
415
+
416
+ def test_info_installed (self ):
417
+ """Test whether only packages installed from the repository are listed."""
418
+ history = self .cli .base .history
419
+ for pkg in self .cli .base .sack .query ().installed ().filter (name = 'pepper' ):
420
+ mockSwdbPkg (history , pkg , repo = 'main' )
421
+
422
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
423
+ with support .patch_std_streams () as (stdout , _ ):
424
+ support .command_run (cmd , ['main' , 'info' , 'installed' ])
425
+
426
+ self .assertEqual (
427
+ stdout .getvalue (),
428
+ '' .join ((self .INSTALLED_TITLE , self .PEPPER_SYSTEM_INFO )))
429
+
304
430
def test_info_obsoletes (self ):
305
431
"""Test whether only obsoletes in the repository are listed."""
306
432
cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
@@ -381,6 +507,34 @@ def test_all(self):
381
507
dnf .subject .Subject ('tour-5-0' ).get_best_query (self .cli .base .sack )
382
508
.available ()))
383
509
510
+ class RepoPkgsReinstallOldSubCommandTest (support .ResultTestCase ):
511
+
512
+ """Tests of ``dnf.cli.commands.RepoPkgsCommand.ReinstallOldSubCommand`` class."""
513
+
514
+ def setUp (self ):
515
+ """Prepare the test fixture."""
516
+ super (RepoPkgsReinstallOldSubCommandTest , self ).setUp ()
517
+ base = support .BaseCliStub ('main' )
518
+ base .init_sack ()
519
+ self .cli = base .mock_cli ()
520
+
521
+ def test_all (self ):
522
+ """Test whether all packages from the repository are reinstalled."""
523
+ history = self .cli .base .history
524
+ for pkg in self .cli .base .sack .query ().installed ():
525
+ reponame = 'main' if pkg .name != 'pepper' else 'non-main'
526
+ mockSwdbPkg (history , pkg , repo = reponame )
527
+
528
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
529
+ support .command_run (cmd , ['main' , 'reinstall-old' ])
530
+
531
+ self .assertResult (self .cli .base , itertools .chain (
532
+ self .cli .base .sack .query ().installed ().filter (name__neq = 'librita' ),
533
+ dnf .subject .Subject ('librita.i686' ).get_best_query (self .cli .base .sack )
534
+ .installed (),
535
+ dnf .subject .Subject ('librita' ).get_best_query (self .cli .base .sack )
536
+ .available ()))
537
+
384
538
385
539
class RepoPkgsReinstallSubCommandTest (unittest .TestCase ):
386
540
@@ -445,6 +599,52 @@ def setUp(self):
445
599
self .cli = support .BaseCliStub ('distro' ).mock_cli ()
446
600
self .cli .base .init_sack ()
447
601
602
+ def test_run_on_repo_spec_sync (self ):
603
+ """Test running with a package which can be synchronized."""
604
+ history = self .cli .base .history
605
+ for pkg in self .cli .base .sack .query ().installed ():
606
+ reponame = 'non-distro' if pkg .name == 'pepper' else 'distro'
607
+ mockSwdbPkg (history , pkg , repo = reponame )
608
+
609
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
610
+ support .command_run (cmd , ['non-distro' , 'remove-or-distro-sync' , 'pepper' ])
611
+
612
+ self .assertResult (self .cli .base , itertools .chain (
613
+ self .cli .base .sack .query ().installed ().filter (name__neq = 'pepper' ),
614
+ dnf .subject .Subject ('pepper' ).get_best_query (self .cli .base .sack )
615
+ .available ()))
616
+
617
+ def test_run_on_repo_spec_remove (self ):
618
+ """Test running with a package which must be removed."""
619
+ history = self .cli .base .history
620
+ for pkg in self .cli .base .sack .query ().installed ():
621
+ reponame = 'non-distro' if pkg .name == 'hole' else 'distro'
622
+ mockSwdbPkg (history , pkg , repo = reponame )
623
+
624
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
625
+ support .command_run (cmd , ['non-distro' , 'remove-or-distro-sync' , 'hole' ])
626
+
627
+ self .assertResult (
628
+ self .cli .base ,
629
+ self .cli .base .sack .query ().installed ().filter (name__neq = 'hole' ))
630
+
631
+ def test_run_on_repo_all (self ):
632
+ """Test running without a package specification."""
633
+ nondist = {'pepper' , 'hole' }
634
+ history = self .cli .base .history
635
+ for pkg in self .cli .base .sack .query ().installed ():
636
+ reponame = 'non-distro' if pkg .name in nondist else 'distro'
637
+ mockSwdbPkg (history , pkg , repo = reponame )
638
+
639
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
640
+ support .command_run (cmd , ['non-distro' , 'remove-or-distro-sync' ])
641
+
642
+ self .assertResult (self .cli .base , itertools .chain (
643
+ self .cli .base .sack .query ().installed ().filter (name__neq = 'pepper' )
644
+ .filter (name__neq = 'hole' ),
645
+ dnf .subject .Subject ('pepper' ).get_best_query (self .cli .base .sack )
646
+ .available ()))
647
+
448
648
@mock .patch ('dnf.cli.commands._' , dnf .pycomp .NullTranslations ().ugettext )
449
649
def test_run_on_repo_spec_notinstalled (self ):
450
650
"""Test running with a package which is not installed."""
@@ -484,6 +684,70 @@ def setUp(self):
484
684
base .init_sack ()
485
685
self .cli = base .mock_cli ()
486
686
687
+ def test_all_not_installed (self ):
688
+ """Test whether it fails if no package is installed from the repository."""
689
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
690
+ self .assertRaises (dnf .exceptions .Error ,
691
+ support .command_run , cmd ,
692
+ ['non-distro' , 'remove-or-distro-sync' ])
693
+
694
+ self .assertResult (self .cli .base , self .cli .base .sack .query ().installed ())
695
+
696
+ def test_all_reinstall (self ):
697
+ """Test whether all packages from the repository are reinstalled."""
698
+ history = self .cli .base .history
699
+ for pkg in self .cli .base .sack .query ().installed ():
700
+ reponame = 'distro' if pkg .name != 'tour' else 'non-distro'
701
+ mockSwdbPkg (history , pkg , repo = reponame )
702
+
703
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
704
+ support .command_run (cmd , ['non-distro' , 'remove-or-reinstall' ])
705
+
706
+ self .assertResult (self .cli .base , itertools .chain (
707
+ self .cli .base .sack .query ().installed ().filter (name__neq = 'tour' ),
708
+ dnf .subject .Subject ('tour' ).get_best_query (self .cli .base .sack )
709
+ .available ()))
710
+
711
+ def test_all_remove (self ):
712
+ """Test whether all packages from the repository are removed."""
713
+ history = self .cli .base .history
714
+ for pkg in self .cli .base .sack .query ().installed ():
715
+ reponame = 'distro' if pkg .name != 'hole' else 'non-distro'
716
+ mockSwdbPkg (history , pkg , repo = reponame )
717
+
718
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
719
+ support .command_run (cmd , ['non-distro' , 'remove-or-reinstall' ])
720
+
721
+ self .assertResult (
722
+ self .cli .base ,
723
+ self .cli .base .sack .query ().installed ().filter (name__neq = 'hole' ))
724
+
725
+
726
+ class RepoPkgsRemoveSubCommandTest (support .ResultTestCase ):
727
+
728
+ """Tests of ``dnf.cli.commands.RepoPkgsCommand.RemoveSubCommand`` class."""
729
+
730
+ def setUp (self ):
731
+ """Prepare the test fixture."""
732
+ super (RepoPkgsRemoveSubCommandTest , self ).setUp ()
733
+ base = support .BaseCliStub ('main' )
734
+ base .init_sack ()
735
+ self .cli = base .mock_cli ()
736
+
737
+ def test_all (self ):
738
+ """Test whether only packages from the repository are removed."""
739
+ history = self .cli .base .history
740
+ for pkg in self .cli .base .sack .query ().installed ():
741
+ reponame = 'main' if pkg .name == 'pepper' else 'non-main'
742
+ mockSwdbPkg (history , pkg , repo = reponame )
743
+
744
+ cmd = dnf .cli .commands .RepoPkgsCommand (self .cli )
745
+ support .command_run (cmd , ['main' , 'remove' ])
746
+
747
+ self .assertResult (
748
+ self .cli .base ,
749
+ self .cli .base .sack .query ().installed ().filter (name__neq = 'pepper' ))
750
+
487
751
488
752
class RepoPkgsUpgradeSubCommandTest (support .ResultTestCase ):
489
753
0 commit comments