Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Last active June 10, 2021 14:25
Show Gist options
  • Select an option

  • Save mgedmin/1a8eaf34cddc07cd8a7c29f13a7b654c to your computer and use it in GitHub Desktop.

Select an option

Save mgedmin/1a8eaf34cddc07cd8a7c29f13a7b654c to your computer and use it in GitHub Desktop.

Revisions

  1. mgedmin revised this gist Jun 10, 2021. No changes.
  2. mgedmin revised this gist Jun 10, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion test_apt_key.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@

    class AptKeyTestCase(unittest.TestCase):

    @mock.patch(apt_key, 'apt_key_bin', '/usr/bin/apt-key')
    @mock.patch.object(apt_key, 'apt_key_bin', '/usr/bin/apt-key')
    @mock.patch.dict(os.environ, {'HTTP_PROXY': 'proxy.example.com'})
    def test_import_key_with_http_proxy(self):
    m_mock = mock.Mock()
  3. mgedmin revised this gist Jun 10, 2021. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions test_apt_key.py
    Original file line number Diff line number Diff line change
    @@ -3,20 +3,22 @@
    from units.compat import mock
    from units.compat import unittest

    from ansible.modules.apt_key import import_key
    from ansible.modules import apt_key


    class AptKeyTestCase(unittest.TestCase):

    @mock.patch.dict(os.environ, 'HTTP_PROXY', 'proxy.example.com')
    @mock.patch(apt_key, 'apt_key_bin', '/usr/bin/apt-key')
    @mock.patch.dict(os.environ, {'HTTP_PROXY': 'proxy.example.com'})
    def test_import_key_with_http_proxy(self):
    m_mock = mock.Mock()
    m_mock.run_command.return_value = (0, '', '')
    import_key(m_mock, keyring=None, keyserver='keyserver.example.com',
    key_id='0xDEADBEEF')
    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 keyring.example.com'
    '/usr/bin/apt-key adv --no-tty --keyserver keyserver.example.com'
    ' --keyserver-options http-proxy=proxy.example.com'
    ' --recv 0xDEADBEEF'
    )
  4. mgedmin revised this gist Jun 10, 2021. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions test_apt_key.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    import os

    from units.compat import mock
    from units.compat import unittest

    @@ -9,11 +11,12 @@ class AptKeyTestCase(unittest.TestCase):
    @mock.patch.dict(os.environ, 'HTTP_PROXY', 'proxy.example.com')
    def test_import_key_with_http_proxy(self):
    m_mock = mock.Mock()
    m.run_command.return_value = (0, '', '')
    m_mock.run_command.return_value = (0, '', '')
    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 keyring.example.com'
    ' --keyserver-options http-proxy=proxy.example.com --recv 0xDEADBEEF'
    ' --keyserver-options http-proxy=proxy.example.com'
    ' --recv 0xDEADBEEF'
    )
  5. mgedmin revised this gist Jun 10, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion test_apt_key.py
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,14 @@

    class AptKeyTestCase(unittest.TestCase):

    @mock.patch.dict(os.environ, 'HTTP_PROXY', 'proxy.example.com')
    def test_import_key_with_http_proxy(self):
    m_mock = mock.Mock()
    m.run_command.return_value = (0, '', '')
    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 keyring.example.com --recv 0xDEADBEEF'
    '/usr/bin/apt-key adv --no-tty --keyserver keyring.example.com'
    ' --keyserver-options http-proxy=proxy.example.com --recv 0xDEADBEEF'
    )
  6. mgedmin created this gist Jun 10, 2021.
    17 changes: 17 additions & 0 deletions test_apt_key.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    from units.compat import mock
    from units.compat import unittest

    from ansible.modules.apt_key import import_key


    class AptKeyTestCase(unittest.TestCase):

    def test_import_key_with_http_proxy(self):
    m_mock = mock.Mock()
    m.run_command.return_value = (0, '', '')
    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 keyring.example.com --recv 0xDEADBEEF'
    )