-
Notifications
You must be signed in to change notification settings - Fork 73
/
test_packages.py
86 lines (68 loc) · 2.8 KB
/
test_packages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
This module contains tests for the pulp_python.extensions.admin.packages module.
"""
import unittest
from pulp.client.commands import options
import mock
from pulp_python.common import constants
from pulp_python.extensions.admin import packages
class TestPackagesCommand(unittest.TestCase):
"""
This class contains tests for the PackagesCommand class.
"""
@mock.patch('pulp_python.extensions.admin.packages.DisplayUnitAssociationsCommand.__init__')
def test___init__(self, super___init__):
"""
Assert correct behavior from __init__().
"""
context = mock.MagicMock()
c = packages.PackagesCommand(context)
super___init__.assert_called_once_with(c.run, name='packages',
description=packages.DESC_SEARCH)
self.assertEqual(c.context, context)
self.assertEqual(c.prompt, context.prompt)
def test_run_with_details(self):
"""
Test the run() method with the details flag.
"""
_packages = ['package_1', 'package_2']
def search(_repo_id, **_kwargs):
"""
Fakes the server search.
"""
self.assertEqual(_repo_id, 'some_repo')
self.assertEqual(
_kwargs,
{'type_ids': [constants.PACKAGE_TYPE_ID], c.ASSOCIATION_FLAG.keyword: True})
response = mock.MagicMock()
response.response_body = _packages
return response
context = mock.MagicMock()
context.server.repo_unit.search.side_effect = search
c = packages.PackagesCommand(context)
kwargs = {options.OPTION_REPO_ID.keyword: 'some_repo', c.ASSOCIATION_FLAG.keyword: True}
c.run(**kwargs)
c.prompt.render_document_list.assert_called_once_with(_packages, order=[])
def test_run_without_details(self):
"""
Test the run() method without the details flag.
"""
_packages = [{'metadata': 'package_1'}, {'metadata': 'package_2'}]
def search(_repo_id, **_kwargs):
"""
Fakes the server search.
"""
self.assertEqual(_repo_id, 'some_repo')
self.assertEqual(
_kwargs,
{'type_ids': [constants.PACKAGE_TYPE_ID]})
response = mock.MagicMock()
response.response_body = _packages
return response
context = mock.MagicMock()
context.server.repo_unit.search.side_effect = search
c = packages.PackagesCommand(context)
kwargs = {options.OPTION_REPO_ID.keyword: 'some_repo'}
c.run(**kwargs)
c.prompt.render_document_list.assert_called_once_with(['package_1', 'package_2'],
order=['name', 'version', 'author'])