qvm-template: Mock print_table in tests for consistent output
This commit is contained in:
parent
20443d5c6f
commit
63f488f64c
@ -15,10 +15,18 @@ import qubesadmin.tools.qvm_template
|
|||||||
|
|
||||||
class TC_00_qvm_template(qubesadmin.tests.QubesTestCase):
|
class TC_00_qvm_template(qubesadmin.tests.QubesTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.maxDiff = 1e9
|
# Print str(list) directly so that the output is consistent no matter
|
||||||
|
# which implementation of `column` we use
|
||||||
|
self.mock_table = mock.patch('qubesadmin.tools.print_table')
|
||||||
|
mock_table = self.mock_table.start()
|
||||||
|
def print_table(table, *args):
|
||||||
|
print(str(table))
|
||||||
|
mock_table.side_effect = print_table
|
||||||
|
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
self.mock_table.stop()
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def test_000_verify_rpm_success(self):
|
def test_000_verify_rpm_success(self):
|
||||||
@ -2239,7 +2247,7 @@ qubes-template-fedora-32|0|4.1|20200101|qubes-templates-itl|1048576|2020-01-23 0
|
|||||||
args, self.app, 'list')
|
args, self.app, 'list')
|
||||||
self.assertEqual(mock_out.getvalue(),
|
self.assertEqual(mock_out.getvalue(),
|
||||||
'''Installed Templates
|
'''Installed Templates
|
||||||
test-vm 2:4.1-2020 @commandline
|
[('test-vm', '2:4.1-2020', '@commandline')]
|
||||||
''')
|
''')
|
||||||
self.assertEqual(mock_disk.mock_calls, [mock.call()])
|
self.assertEqual(mock_disk.mock_calls, [mock.call()])
|
||||||
self.assertEqual(mock_query.mock_calls, [])
|
self.assertEqual(mock_query.mock_calls, [])
|
||||||
@ -2297,15 +2305,17 @@ test-vm 2:4.1-2020 @commandline
|
|||||||
qubesadmin.tools.qvm_template.list_templates(
|
qubesadmin.tools.qvm_template.list_templates(
|
||||||
args, self.app, 'list')
|
args, self.app, 'list')
|
||||||
# Order not determinstic because of sets
|
# Order not determinstic because of sets
|
||||||
|
expected = [
|
||||||
|
('fedora-31', '1:4.1-20200101', 'qubes-templates-itl'),
|
||||||
|
('fedora-32', '0:4.2-20200201', 'qubes-templates-itl-testing')
|
||||||
|
]
|
||||||
self.assertTrue(mock_out.getvalue() == \
|
self.assertTrue(mock_out.getvalue() == \
|
||||||
'''Available Templates
|
f'''Available Templates
|
||||||
fedora-31 1:4.1-20200101 qubes-templates-itl
|
{str([expected[1], expected[0]])}
|
||||||
fedora-32 0:4.2-20200201 qubes-templates-itl-testing
|
|
||||||
''' \
|
''' \
|
||||||
or mock_out.getvalue() == \
|
or mock_out.getvalue() == \
|
||||||
'''Available Templates
|
f'''Available Templates
|
||||||
fedora-32 0:4.2-20200201 qubes-templates-itl-testing
|
{str([expected[0], expected[1]])}
|
||||||
fedora-31 1:4.1-20200101 qubes-templates-itl
|
|
||||||
''')
|
''')
|
||||||
self.assertEqual(mock_query.mock_calls, [
|
self.assertEqual(mock_query.mock_calls, [
|
||||||
mock.call(args, self.app, 'fedora-32'),
|
mock.call(args, self.app, 'fedora-32'),
|
||||||
@ -2345,7 +2355,7 @@ fedora-31 1:4.1-20200101 qubes-templates-itl
|
|||||||
args, self.app, 'list')
|
args, self.app, 'list')
|
||||||
self.assertEqual(mock_out.getvalue(),
|
self.assertEqual(mock_out.getvalue(),
|
||||||
'''Available Templates
|
'''Available Templates
|
||||||
fedora-31 1:4.1-20200101 qubes-templates-itl
|
[('fedora-31', '1:4.1-20200101', 'qubes-templates-itl')]
|
||||||
''')
|
''')
|
||||||
self.assertEqual(mock_query.mock_calls, [
|
self.assertEqual(mock_query.mock_calls, [
|
||||||
mock.call(args, self.app)
|
mock.call(args, self.app)
|
||||||
@ -2432,7 +2442,7 @@ fedora-31 1:4.1-20200101 qubes-templates-itl
|
|||||||
args, self.app, 'list')
|
args, self.app, 'list')
|
||||||
self.assertEqual(mock_out.getvalue(),
|
self.assertEqual(mock_out.getvalue(),
|
||||||
'''Extra Templates
|
'''Extra Templates
|
||||||
test-vm-2 1:4.0-2019 qubes-template-itl
|
[('test-vm-2', '1:4.0-2019', 'qubes-template-itl')]
|
||||||
''')
|
''')
|
||||||
self.assertEqual(mock_disk.mock_calls, [mock.call()])
|
self.assertEqual(mock_disk.mock_calls, [mock.call()])
|
||||||
self.assertEqual(mock_query.mock_calls, [
|
self.assertEqual(mock_query.mock_calls, [
|
||||||
@ -2534,7 +2544,7 @@ test-vm-2 1:4.0-2019 qubes-template-itl
|
|||||||
args, self.app, 'list')
|
args, self.app, 'list')
|
||||||
self.assertEqual(mock_out.getvalue(),
|
self.assertEqual(mock_out.getvalue(),
|
||||||
'''Available Upgrades
|
'''Available Upgrades
|
||||||
test-vm 2:4.1-2020 qubes-templates-itl
|
[('test-vm', '2:4.1-2020', 'qubes-templates-itl')]
|
||||||
''')
|
''')
|
||||||
self.assertEqual(mock_disk.mock_calls, [])
|
self.assertEqual(mock_disk.mock_calls, [])
|
||||||
self.assertEqual(mock_query.mock_calls, [
|
self.assertEqual(mock_query.mock_calls, [
|
||||||
@ -2606,9 +2616,9 @@ test-vm 2:4.1-2020 qubes-templates-itl
|
|||||||
)
|
)
|
||||||
expected = \
|
expected = \
|
||||||
'''Installed Templates
|
'''Installed Templates
|
||||||
test-vm-2 1:4.0-2019 @commandline
|
[('test-vm-2', '1:4.0-2019', '@commandline')]
|
||||||
Available Templates
|
Available Templates
|
||||||
test-vm 2:4.1-2020 qubes-templates-itl
|
[('test-vm', '2:4.1-2020', 'qubes-templates-itl')]
|
||||||
'''
|
'''
|
||||||
self.__test_list_templates_all_success('list', args, expected)
|
self.__test_list_templates_all_success('list', args, expected)
|
||||||
|
|
||||||
@ -2625,9 +2635,9 @@ test-vm 2:4.1-2020 qubes-templates-itl
|
|||||||
)
|
)
|
||||||
expected = \
|
expected = \
|
||||||
'''Installed Templates
|
'''Installed Templates
|
||||||
test-vm-2 1:4.0-2019 @commandline
|
[('test-vm-2', '1:4.0-2019', '@commandline')]
|
||||||
Available Templates
|
Available Templates
|
||||||
test-vm 2:4.1-2020 qubes-templates-itl
|
[('test-vm', '2:4.1-2020', 'qubes-templates-itl')]
|
||||||
'''
|
'''
|
||||||
self.__test_list_templates_all_success('list', args, expected)
|
self.__test_list_templates_all_success('list', args, expected)
|
||||||
|
|
||||||
@ -2644,34 +2654,9 @@ test-vm 2:4.1-2020 qubes-templates-itl
|
|||||||
)
|
)
|
||||||
expected = \
|
expected = \
|
||||||
'''Installed Templates
|
'''Installed Templates
|
||||||
Name : test-vm-2
|
[('Name', ':', 'test-vm-2'), ('Epoch', ':', '1'), ('Version', ':', '4.0'), ('Release', ':', '2019'), ('Size', ':', '1.2 MiB'), ('Repository', ':', '@commandline'), ('Buildtime', ':', '2020-09-02 14:30:00'), ('Install time', ':', '2020-09-02 15:30:00'), ('URL', ':', 'https://qubes-os.org'), ('License', ':', 'GPL'), ('Summary', ':', 'Summary'), ('Description', ':', 'Desc'), ('', ':', 'desc'), (' ', ' ', ' ')]
|
||||||
Epoch : 1
|
|
||||||
Version : 4.0
|
|
||||||
Release : 2019
|
|
||||||
Size : 1.2 MiB
|
|
||||||
Repository : @commandline
|
|
||||||
Buildtime : 2020-09-02 14:30:00
|
|
||||||
Install time : 2020-09-02 15:30:00
|
|
||||||
URL : https://qubes-os.org
|
|
||||||
License : GPL
|
|
||||||
Summary : Summary
|
|
||||||
Description : Desc
|
|
||||||
: desc
|
|
||||||
|
|
||||||
Available Templates
|
Available Templates
|
||||||
Name : test-vm
|
[('Name', ':', 'test-vm'), ('Epoch', ':', '2'), ('Version', ':', '4.1'), ('Release', ':', '2020'), ('Size', ':', '1.0 MiB'), ('Repository', ':', 'qubes-templates-itl'), ('Buildtime', ':', '2020-09-01 14:30:00+00:00'), ('URL', ':', 'https://qubes-os.org'), ('License', ':', 'GPL'), ('Summary', ':', 'Qubes template for fedora-31'), ('Description', ':', 'Qubes template'), ('', ':', ' for fedora-31'), (' ', ' ', ' ')]
|
||||||
Epoch : 2
|
|
||||||
Version : 4.1
|
|
||||||
Release : 2020
|
|
||||||
Size : 1.0 MiB
|
|
||||||
Repository : qubes-templates-itl
|
|
||||||
Buildtime : 2020-09-01 14:30:00+00:00
|
|
||||||
URL : https://qubes-os.org
|
|
||||||
License : GPL
|
|
||||||
Summary : Qubes template for fedora-31
|
|
||||||
Description : Qubes template
|
|
||||||
: for fedora-31
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
self.__test_list_templates_all_success('info', args, expected)
|
self.__test_list_templates_all_success('info', args, expected)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user