Python unittest.mock.assert_called_once_with() Examples

The following are 30 code examples of unittest.mock.assert_called_once_with(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module unittest.mock , or try the search function .
Example #1
Source File: test_keystone.py    From ceph-lcm with Apache License 2.0 6 votes vote down vote up
def test_require_authentication_no_keystone(
        mocked_authenticator, configure_model, sudo_client_v1,
        sudo_user_with_external_id, app):
    now, expired = make_now_expired()
    endpoint = "/" + pytest.faux.gen_alphanumeric()

    mocked_authenticator.client.tokens.get_token_data.side_effect = \
        keystoneauth1.exceptions.ClientException

    @app.route(endpoint)
    @mocked_authenticator.require_authentication
    def testing_endpoint():
        assert int(flask.g.token.expires_at.timestamp()) == int(
            calendar.timegm(expired.timetuple()))
        assert flask.g.token.user_id == sudo_user_with_external_id.model_id
        return flask.jsonify(value=1)

    response = sudo_client_v1.get(endpoint)
    assert response.status_code == 401

    mock = mocked_authenticator.client.tokens.get_token_data
    mock.assert_called_once_with(sudo_client_v1.auth_token) 
Example #2
Source File: test_configcommands.py    From qutebrowser with GNU General Public License v3.0 6 votes vote down vote up
def test_with_sourcing(self, commands, config_stub, patch_editor):
        assert config_stub.val.content.javascript.enabled
        mock = patch_editor('c.content.javascript.enabled = False')

        commands.config_edit()

        mock.assert_called_once_with(unittest.mock.ANY)
        assert not config_stub.val.content.javascript.enabled 
Example #3
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 6 votes vote down vote up
def test_480_vm_device_attach(self):
        self.vm.add_handler('device-list:testclass', self.device_list_testclass)
        mock_attach = unittest.mock.Mock()
        mock_attach.return_value = None
        del mock_attach._is_coroutine
        self.vm.add_handler('device-attach:testclass', mock_attach)
        with unittest.mock.patch.object(qubes.vm.qubesvm.QubesVM,
                'is_halted', lambda _: False):
            value = self.call_mgmt_func(b'admin.vm.device.testclass.Attach',
                b'test-vm1', b'test-vm1+1234')
        self.assertIsNone(value)
        mock_attach.assert_called_once_with(self.vm, 'device-attach:testclass',
            device=self.vm.devices['testclass']['1234'],
            options={})
        self.assertEqual(len(self.vm.devices['testclass'].persistent()), 0)
        self.app.save.assert_called_once_with() 
Example #4
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 6 votes vote down vote up
def test_483_vm_device_attach_persistent(self):
        self.vm.add_handler('device-list:testclass', self.device_list_testclass)
        mock_attach = unittest.mock.Mock()
        mock_attach.return_value = None
        del mock_attach._is_coroutine
        self.vm.add_handler('device-attach:testclass', mock_attach)
        with unittest.mock.patch.object(qubes.vm.qubesvm.QubesVM,
                'is_halted', lambda _: False):
            value = self.call_mgmt_func(b'admin.vm.device.testclass.Attach',
                b'test-vm1', b'test-vm1+1234', b'persistent=yes')
        self.assertIsNone(value)
        dev = self.vm.devices['testclass']['1234']
        mock_attach.assert_called_once_with(self.vm, 'device-attach:testclass',
            device=dev,
            options={})
        self.assertIn(dev, self.vm.devices['testclass'].persistent())
        self.app.save.assert_called_once_with() 
Example #5
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 6 votes vote down vote up
def test_485_vm_device_attach_options(self):
        self.vm.add_handler('device-list:testclass', self.device_list_testclass)
        mock_attach = unittest.mock.Mock()
        mock_attach.return_value = None
        del mock_attach._is_coroutine
        self.vm.add_handler('device-attach:testclass', mock_attach)
        with unittest.mock.patch.object(qubes.vm.qubesvm.QubesVM,
                'is_halted', lambda _: False):
            value = self.call_mgmt_func(b'admin.vm.device.testclass.Attach',
                b'test-vm1', b'test-vm1+1234', b'option1=value2')
        self.assertIsNone(value)
        dev = self.vm.devices['testclass']['1234']
        mock_attach.assert_called_once_with(self.vm, 'device-attach:testclass',
            device=dev,
            options={'option1': 'value2'})
        self.app.save.assert_called_once_with() 
Example #6
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 6 votes vote down vote up
def test_490_vm_device_detach(self):
        self.vm.add_handler('device-list:testclass', self.device_list_testclass)
        self.vm.add_handler('device-list-attached:testclass',
            self.device_list_attached_testclass)
        mock_detach = unittest.mock.Mock()
        mock_detach.return_value = None
        del mock_detach._is_coroutine
        self.vm.add_handler('device-detach:testclass', mock_detach)
        with unittest.mock.patch.object(qubes.vm.qubesvm.QubesVM,
                'is_halted', lambda _: False):
            value = self.call_mgmt_func(b'admin.vm.device.testclass.Detach',
                b'test-vm1', b'test-vm1+1234')
        self.assertIsNone(value)
        mock_detach.assert_called_once_with(self.vm, 'device-detach:testclass',
            device=self.vm.devices['testclass']['1234'])
        self.app.save.assert_called_once_with() 
Example #7
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 6 votes vote down vote up
def test_652_vm_device_set_persistent_false(self):
        self.vm.add_handler('device-list:testclass',
            self.device_list_testclass)
        assignment = qubes.devices.DeviceAssignment(self.vm, '1234', {},
            True)
        self.loop.run_until_complete(
            self.vm.devices['testclass'].attach(assignment))
        self.vm.add_handler('device-list-attached:testclass',
            self.device_list_attached_testclass)
        dev = qubes.devices.DeviceInfo(self.vm, '1234')
        self.assertIn(dev, self.vm.devices['testclass'].persistent())
        with unittest.mock.patch.object(qubes.vm.qubesvm.QubesVM,
                'is_halted', lambda _: False):
            value = self.call_mgmt_func(
                b'admin.vm.device.testclass.Set.persistent',
                b'test-vm1', b'test-vm1+1234', b'False')
        self.assertIsNone(value)
        self.assertNotIn(dev, self.vm.devices['testclass'].persistent())
        self.assertIn(dev, self.vm.devices['testclass'].attached())
        self.app.save.assert_called_once_with() 
Example #8
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 6 votes vote down vote up
def test_653_vm_device_set_persistent_true_unchanged(self):
        self.vm.add_handler('device-list:testclass',
            self.device_list_testclass)
        assignment = qubes.devices.DeviceAssignment(self.vm, '1234', {},
            True)
        self.loop.run_until_complete(
            self.vm.devices['testclass'].attach(assignment))
        self.vm.add_handler('device-list-attached:testclass',
            self.device_list_attached_testclass)
        with unittest.mock.patch.object(qubes.vm.qubesvm.QubesVM,
                'is_halted', lambda _: False):
            value = self.call_mgmt_func(
                b'admin.vm.device.testclass.Set.persistent',
                b'test-vm1', b'test-vm1+1234', b'True')
        self.assertIsNone(value)
        dev = qubes.devices.DeviceInfo(self.vm, '1234')
        self.assertIn(dev, self.vm.devices['testclass'].persistent())
        self.assertIn(dev, self.vm.devices['testclass'].attached())
        self.app.save.assert_called_once_with() 
Example #9
Source File: testmock.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def test_assert_called_once_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_once_with()

        mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock('foo', 'bar', baz=2)
        mock.assert_called_once_with('foo', 'bar', baz=2)

        mock.reset_mock()
        mock('foo', 'bar', baz=2)
        self.assertRaises(
            AssertionError,
            lambda: mock.assert_called_once_with('bob', 'bar', baz=2)
        ) 
Example #10
Source File: testmock.py    From jawfish with MIT License 6 votes vote down vote up
def test_assert_called_once_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_once_with()

        mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock('foo', 'bar', baz=2)
        mock.assert_called_once_with('foo', 'bar', baz=2)

        mock.reset_mock()
        mock('foo', 'bar', baz=2)
        self.assertRaises(
            AssertionError,
            lambda: mock.assert_called_once_with('bob', 'bar', baz=2)
        ) 
Example #11
Source File: testmock.py    From Imogen with MIT License 6 votes vote down vote up
def test_assert_called_once_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_once_with()

        mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock('foo', 'bar', baz=2)
        mock.assert_called_once_with('foo', 'bar', baz=2)

        mock.reset_mock()
        mock('foo', 'bar', baz=2)
        self.assertRaises(
            AssertionError,
            lambda: mock.assert_called_once_with('bob', 'bar', baz=2)
        ) 
Example #12
Source File: testmock.py    From Imogen with MIT License 6 votes vote down vote up
def test_assert_called_once_with_function_spec(self):
        def f(a, b, c, d=None):
            pass

        mock = Mock(spec=f)

        mock(1, b=2, c=3)
        mock.assert_called_once_with(1, 2, 3)
        mock.assert_called_once_with(a=1, b=2, c=3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, b=3, c=2)
        # Expected call doesn't match the spec's signature
        with self.assertRaises(AssertionError) as cm:
            mock.assert_called_once_with(e=8)
        self.assertIsInstance(cm.exception.__cause__, TypeError)
        # Mock called more than once => always fails
        mock(4, 5, 6)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, 2, 3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          4, 5, 6) 
Example #13
Source File: testmock.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def test_assert_called_once_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_once_with()

        mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock('foo', 'bar', baz=2)
        mock.assert_called_once_with('foo', 'bar', baz=2)

        mock.reset_mock()
        mock('foo', 'bar', baz=2)
        self.assertRaises(
            AssertionError,
            lambda: mock.assert_called_once_with('bob', 'bar', baz=2)
        ) 
Example #14
Source File: testmock.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def test_assert_called_once_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_once_with()

        mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock('foo', 'bar', baz=2)
        mock.assert_called_once_with('foo', 'bar', baz=2)

        mock.reset_mock()
        mock('foo', 'bar', baz=2)
        self.assertRaises(
            AssertionError,
            lambda: mock.assert_called_once_with('bob', 'bar', baz=2)
        ) 
Example #15
Source File: testmock.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def test_assert_called_once_with_function_spec(self):
        def f(a, b, c, d=None):
            pass

        mock = Mock(spec=f)

        mock(1, b=2, c=3)
        mock.assert_called_once_with(1, 2, 3)
        mock.assert_called_once_with(a=1, b=2, c=3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, b=3, c=2)
        # Expected call doesn't match the spec's signature
        with self.assertRaises(AssertionError) as cm:
            mock.assert_called_once_with(e=8)
        self.assertIsInstance(cm.exception.__cause__, TypeError)
        # Mock called more than once => always fails
        mock(4, 5, 6)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, 2, 3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          4, 5, 6) 
Example #16
Source File: test_keystone.py    From ceph-lcm with Apache License 2.0 6 votes vote down vote up
def test_require_authentication_unknown_user(
        mocked_authenticator, configure_model, sudo_client_v1,
        sudo_user_with_external_id, app):
    now, expired = make_now_expired()
    endpoint = "/" + pytest.faux.gen_alphanumeric()

    mock = mocked_authenticator.client.tokens.get_token_data
    mock.return_value = {
        "token": make_token_data(sudo_user_with_external_id, now, expired)
    }
    mock.return_value["token"]["user"]["id"] += "FAKE"

    @app.route(endpoint)
    @mocked_authenticator.require_authentication
    def testing_endpoint():
        assert int(flask.g.token.expires_at.timestamp()) == int(
            calendar.timegm(expired.timetuple()))
        assert flask.g.token.user_id == sudo_user_with_external_id.model_id
        return flask.jsonify(value=1)

    response = sudo_client_v1.get(endpoint)
    assert response.status_code == 401

    mock = mocked_authenticator.client.tokens.get_token_data
    mock.assert_called_once_with(sudo_client_v1.auth_token) 
Example #17
Source File: test_keystone.py    From ceph-lcm with Apache License 2.0 6 votes vote down vote up
def test_require_authentication_ok(
        mocked_authenticator, configure_model, sudo_client_v1,
        sudo_user_with_external_id, app):
    now, expired = make_now_expired()
    endpoint = "/" + pytest.faux.gen_alphanumeric()

    mock = mocked_authenticator.client.tokens.get_token_data
    mock.return_value = {
        "token": make_token_data(sudo_user_with_external_id, now, expired)
    }

    @app.route(endpoint)
    @mocked_authenticator.require_authentication
    def testing_endpoint():
        assert int(flask.g.token.expires_at.timestamp()) == int(
            calendar.timegm(expired.timetuple()))
        assert flask.g.token.user_id == sudo_user_with_external_id.model_id
        return flask.jsonify(value=1)

    response = sudo_client_v1.get(endpoint)
    assert response.status_code == 200
    assert response.json == {"value": 1}

    mock = mocked_authenticator.client.tokens.get_token_data
    mock.assert_called_once_with(sudo_client_v1.auth_token) 
Example #18
Source File: testmock.py    From android_universal with MIT License 6 votes vote down vote up
def test_assert_called_once_with_function_spec(self):
        def f(a, b, c, d=None):
            pass

        mock = Mock(spec=f)

        mock(1, b=2, c=3)
        mock.assert_called_once_with(1, 2, 3)
        mock.assert_called_once_with(a=1, b=2, c=3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, b=3, c=2)
        # Expected call doesn't match the spec's signature
        with self.assertRaises(AssertionError) as cm:
            mock.assert_called_once_with(e=8)
        self.assertIsInstance(cm.exception.__cause__, TypeError)
        # Mock called more than once => always fails
        mock(4, 5, 6)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, 2, 3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          4, 5, 6) 
Example #19
Source File: testmock.py    From android_universal with MIT License 6 votes vote down vote up
def test_assert_called_once_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_once_with()

        mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock('foo', 'bar', baz=2)
        mock.assert_called_once_with('foo', 'bar', baz=2)

        mock.reset_mock()
        mock('foo', 'bar', baz=2)
        self.assertRaises(
            AssertionError,
            lambda: mock.assert_called_once_with('bob', 'bar', baz=2)
        ) 
Example #20
Source File: testmock.py    From odoo13-x64 with GNU General Public License v3.0 6 votes vote down vote up
def test_create_autospec_classmethod_and_staticmethod(self):
        class TestClass:
            @classmethod
            def class_method(cls):
                pass

            @staticmethod
            def static_method():
                pass
        for method in ('class_method', 'static_method'):
            with self.subTest(method=method):
                mock_method = mock.create_autospec(getattr(TestClass, method))
                mock_method()
                mock_method.assert_called_once_with()
                self.assertRaises(TypeError, mock_method, 'extra_arg')

    #Issue21238 
Example #21
Source File: testmock.py    From odoo13-x64 with GNU General Public License v3.0 6 votes vote down vote up
def test_assert_called_once_with_function_spec(self):
        def f(a, b, c, d=None):
            pass

        mock = Mock(spec=f)

        mock(1, b=2, c=3)
        mock.assert_called_once_with(1, 2, 3)
        mock.assert_called_once_with(a=1, b=2, c=3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, b=3, c=2)
        # Expected call doesn't match the spec's signature
        with self.assertRaises(AssertionError) as cm:
            mock.assert_called_once_with(e=8)
        self.assertIsInstance(cm.exception.__cause__, TypeError)
        # Mock called more than once => always fails
        mock(4, 5, 6)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, 2, 3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          4, 5, 6) 
Example #22
Source File: testmock.py    From odoo13-x64 with GNU General Public License v3.0 6 votes vote down vote up
def test_assert_called_once_with(self):
        mock = Mock()
        mock()

        # Will raise an exception if it fails
        mock.assert_called_once_with()

        mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock.reset_mock()
        self.assertRaises(AssertionError, mock.assert_called_once_with)

        mock('foo', 'bar', baz=2)
        mock.assert_called_once_with('foo', 'bar', baz=2)

        mock.reset_mock()
        mock('foo', 'bar', baz=2)
        self.assertRaises(
            AssertionError,
            lambda: mock.assert_called_once_with('bob', 'bar', baz=2)
        ) 
Example #23
Source File: CoreTest.py    From coala with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_existing_cache_with_unrelated_data(self):
        section = Section('test-section')
        filedict = {}

        # Start with some unrelated cache values. Those are ignored as they are
        # never hit during a cache lookup.
        cache = {CustomTasksBear: {b'123456': [100, 101, 102]}}

        task_args = -1, -2, -3
        bear = CustomTasksBear(section, filedict, tasks=[task_args])

        with unittest.mock.patch.object(bear, 'analyze',
                                        wraps=bear.analyze) as mock:
            # First time we have a cache miss.
            results = self.execute_run({bear}, cache)
            mock.assert_called_once_with(*task_args)
            self.assertEqual(results, list(task_args))
            self.assertEqual(len(cache), 1)
            self.assertIn(CustomTasksBear, cache)

            cache_values = next(iter(cache.values()))
            self.assertEqual(len(cache_values), 2)
            # The unrelated data is left untouched.
            self.assertIn(b'123456', cache_values)
            self.assertEqual(cache_values[b'123456'], [100, 101, 102]) 
Example #24
Source File: testmock.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def test_assert_called_once_with_function_spec(self):
        def f(a, b, c, d=None):
            pass

        mock = Mock(spec=f)

        mock(1, b=2, c=3)
        mock.assert_called_once_with(1, 2, 3)
        mock.assert_called_once_with(a=1, b=2, c=3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, b=3, c=2)
        # Expected call doesn't match the spec's signature
        with self.assertRaises(AssertionError) as cm:
            mock.assert_called_once_with(e=8)
        self.assertIsInstance(cm.exception.__cause__, TypeError)
        # Mock called more than once => always fails
        mock(4, 5, 6)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, 2, 3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          4, 5, 6) 
Example #25
Source File: testmock.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def test_assert_called_once_with_function_spec(self):
        def f(a, b, c, d=None):
            pass

        mock = Mock(spec=f)

        mock(1, b=2, c=3)
        mock.assert_called_once_with(1, 2, 3)
        mock.assert_called_once_with(a=1, b=2, c=3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, b=3, c=2)
        # Expected call doesn't match the spec's signature
        with self.assertRaises(AssertionError) as cm:
            mock.assert_called_once_with(e=8)
        self.assertIsInstance(cm.exception.__cause__, TypeError)
        # Mock called more than once => always fails
        mock(4, 5, 6)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          1, 2, 3)
        self.assertRaises(AssertionError, mock.assert_called_once_with,
                          4, 5, 6) 
Example #26
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 5 votes vote down vote up
def test_034_vm_propert_set_bool_true(self):
        with unittest.mock.patch('qubes.property.__set__') as mock:
            value = self.call_mgmt_func(b'admin.vm.property.Set', b'test-vm1',
                b'autostart', b'True')
            self.assertIsNone(value)
            mock.assert_called_once_with(self.vm, True)
        self.app.save.assert_called_once_with() 
Example #27
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 5 votes vote down vote up
def test_031_vm_property_set_vm_none(self):
        netvm = self.app.add_new_vm('AppVM', label='red', name='test-net',
            template='test-template', provides_network=True)

        with unittest.mock.patch('qubes.vm.VMProperty.__set__') as mock:
            value = self.call_mgmt_func(b'admin.vm.property.Set', b'test-vm1',
                b'netvm', b'')
            self.assertIsNone(value)
            mock.assert_called_once_with(self.vm, '')
        self.app.save.assert_called_once_with() 
Example #28
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 5 votes vote down vote up
def test_035_vm_propert_set_bool_false(self):
        with unittest.mock.patch('qubes.property.__set__') as mock:
            value = self.call_mgmt_func(b'admin.vm.property.Set', b'test-vm1',
                b'autostart', b'False')
            self.assertIsNone(value)
            mock.assert_called_once_with(self.vm, False)
        self.app.save.assert_called_once_with() 
Example #29
Source File: api_admin.py    From qubes-core-admin with GNU Lesser General Public License v2.1 5 votes vote down vote up
def test_484_vm_device_attach_persistent_not_running(self):
        self.vm.add_handler('device-list:testclass', self.device_list_testclass)
        mock_attach = unittest.mock.Mock()
        mock_attach.return_value = None
        del mock_attach._is_coroutine
        self.vm.add_handler('device-attach:testclass', mock_attach)
        value = self.call_mgmt_func(b'admin.vm.device.testclass.Attach',
            b'test-vm1', b'test-vm1+1234', b'persistent=yes')
        self.assertIsNone(value)
        dev = self.vm.devices['testclass']['1234']
        mock_attach.assert_called_once_with(self.vm, 'device-attach:testclass',
            device=dev,
            options={})
        self.assertIn(dev, self.vm.devices['testclass'].persistent())
        self.app.save.assert_called_once_with() 
Example #30
Source File: testmock.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def test_assert_called_once_with_message(self):
        mock = Mock(name='geoffrey')
        self.assertRaisesRegex(AssertionError,
                     r"Expected 'geoffrey' to be called once\.",
                     mock.assert_called_once_with)