summaryrefslogtreecommitdiffstats
path: root/test/units/modules/test_apt_key.py
blob: 37cd53b62d2c21c0ce8864658384ef58af6d1d8d (plain)
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
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os

from units.compat.mock import patch, Mock
from units.compat import unittest

from ansible.modules import apt_key


def returnc(x):
    return 'C'


class AptKeyTestCase(unittest.TestCase):

    @patch.object(apt_key, 'apt_key_bin', '/usr/bin/apt-key')
    @patch.object(apt_key, 'lang_env', returnc)
    @patch.dict(os.environ, {'HTTP_PROXY': 'proxy.example.com'})
    def test_import_key_with_http_proxy(self):
        m_mock = Mock()
        m_mock.run_command.return_value = (0, '', '')
        apt_key.import_key(
            m_mock, keyring=None, keyserver='keyserver.example.com',
            key_id='0xDEADBEEF')
        self.assertEqual(
            m_mock.run_command.call_args_list[0][0][0],
            '/usr/bin/apt-key adv --no-tty --keyserver keyserver.example.com'
            ' --keyserver-options http-proxy=proxy.example.com'
            ' --recv 0xDEADBEEF'
        )