当前位置: 首页>>代码示例>>Python>>正文


Python Mock.data方法代码示例

本文整理汇总了Python中unittest.mock.Mock.data方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.data方法的具体用法?Python Mock.data怎么用?Python Mock.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.Mock的用法示例。


在下文中一共展示了Mock.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_setup_entry_successful

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_setup_entry_successful(hass):
    """Test setup entry is successful."""
    entry = Mock()
    entry.data = {
        emulated_roku.CONF_NAME: 'Emulated Roku Test',
        emulated_roku.CONF_LISTEN_PORT: 8060,
        emulated_roku.CONF_HOST_IP: '1.2.3.5',
        emulated_roku.CONF_ADVERTISE_IP: '1.2.3.4',
        emulated_roku.CONF_ADVERTISE_PORT: 8071,
        emulated_roku.CONF_UPNP_BIND_MULTICAST: False
    }

    with patch('emulated_roku.EmulatedRokuServer',
               return_value=Mock(start=mock_coro_func(),
                                 close=mock_coro_func())) as instantiate:
        assert await emulated_roku.async_setup_entry(hass, entry) is True

    assert len(instantiate.mock_calls) == 1
    assert hass.data[emulated_roku.DOMAIN]

    roku_instance = hass.data[emulated_roku.DOMAIN]['Emulated Roku Test']

    assert roku_instance.roku_usn == 'Emulated Roku Test'
    assert roku_instance.host_ip == '1.2.3.5'
    assert roku_instance.listen_port == 8060
    assert roku_instance.advertise_ip == '1.2.3.4'
    assert roku_instance.advertise_port == 8071
    assert roku_instance.bind_multicast is False
开发者ID:Martwall,项目名称:home-assistant,代码行数:30,代码来源:test_init.py

示例2: test_setup_entry_successful

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_setup_entry_successful(hass):
    """Test setup entry is successful."""
    entry = Mock()
    entry.data = {'host': '1.2.3.4', 'port': 80, 'api_key': '1234567890ABCDEF'}
    with patch.object(hass, 'async_create_task') as mock_add_job, \
        patch.object(hass, 'config_entries') as mock_config_entries, \
        patch('pydeconz.DeconzSession.async_get_state',
              return_value=mock_coro(CONFIG)), \
        patch('pydeconz.DeconzSession.start', return_value=True), \
        patch('homeassistant.helpers.device_registry.async_get_registry',
              return_value=mock_coro(Mock())):
        assert await deconz.async_setup_entry(hass, entry) is True
    assert hass.data[deconz.DOMAIN]
    assert hass.data[deconz.DATA_DECONZ_ID] == {}
    assert len(hass.data[deconz.DATA_DECONZ_UNSUB]) == 1
    assert len(mock_add_job.mock_calls) == 5
    assert len(mock_config_entries.async_forward_entry_setup.mock_calls) == 5
    assert mock_config_entries.async_forward_entry_setup.mock_calls[0][1] == \
        (entry, 'binary_sensor')
    assert mock_config_entries.async_forward_entry_setup.mock_calls[1][1] == \
        (entry, 'light')
    assert mock_config_entries.async_forward_entry_setup.mock_calls[2][1] == \
        (entry, 'scene')
    assert mock_config_entries.async_forward_entry_setup.mock_calls[3][1] == \
        (entry, 'sensor')
    assert mock_config_entries.async_forward_entry_setup.mock_calls[4][1] == \
        (entry, 'switch')
开发者ID:,项目名称:,代码行数:29,代码来源:

示例3: test_if_do_list_prints_the_channel_list_if_the_channels_arg_is_provided

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
 def test_if_do_list_prints_the_channel_list_if_the_channels_arg_is_provided(self, print_mock, slack_api_mock):
     response_mock = Mock()
     response_mock.data = self._users
     slack_api_mock.call = response_mock
     shell = SlackShell(self._auth_token)
     shell.do_list('channels')
     self.assertTrue(print_mock.called)
开发者ID:Nicoretti,项目名称:libslack,代码行数:9,代码来源:sls_tests.py

示例4: test_setup_entry_fails

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_setup_entry_fails(hass):
    """Test setup entry fails if deCONZ is not available."""
    entry = Mock()
    entry.data = {'host': '1.2.3.4', 'port': 80, 'api_key': '1234567890ABCDEF'}
    with patch('pydeconz.DeconzSession.async_load_parameters',
               side_effect=Exception):
        await deconz.async_setup_entry(hass, entry)
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:9,代码来源:test_init.py

示例5: test_device_not_accessible

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_device_not_accessible():
    """Failed setup schedules a retry of setup."""
    hass = Mock()
    hass.data = dict()
    entry = Mock()
    entry.data = ENTRY_CONFIG
    entry.options = ENTRY_OPTIONS

    axis_device = device.AxisNetworkDevice(hass, entry)

    with patch.object(device, 'get_device',
                      side_effect=errors.CannotConnect), \
            pytest.raises(device.ConfigEntryNotReady):
        await axis_device.async_setup()

    assert not hass.helpers.event.async_call_later.mock_calls
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:18,代码来源:test_device.py

示例6: fake_supplier

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
def fake_supplier(seed, fake_data):
	result = Mock()
	result.metadata = {'entries' : len(fake_data)}
	result.data = {'data' : fake_data}
	result.kurfile.get_seed.return_value = seed
	result.downselect = partial(SpeechRecognitionSupplier.downselect, result)
	return result
开发者ID:Navdevl,项目名称:kur,代码行数:9,代码来源:test_speechrec.py

示例7: test_gateway_setup

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_gateway_setup():
    """Successful setup."""
    hass = Mock()
    entry = Mock()
    entry.data = ENTRY_CONFIG
    api = Mock()
    api.async_add_remote.return_value = Mock()
    api.sensors = {}

    deconz_gateway = gateway.DeconzGateway(hass, entry)

    with patch.object(gateway, 'get_gateway', return_value=mock_coro(api)), \
        patch.object(
            gateway, 'async_dispatcher_connect', return_value=Mock()):
        assert await deconz_gateway.async_setup() is True

    assert deconz_gateway.api is api
    assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 7
    assert hass.config_entries.async_forward_entry_setup.mock_calls[0][1] == \
        (entry, 'binary_sensor')
    assert hass.config_entries.async_forward_entry_setup.mock_calls[1][1] == \
        (entry, 'climate')
    assert hass.config_entries.async_forward_entry_setup.mock_calls[2][1] == \
        (entry, 'cover')
    assert hass.config_entries.async_forward_entry_setup.mock_calls[3][1] == \
        (entry, 'light')
    assert hass.config_entries.async_forward_entry_setup.mock_calls[4][1] == \
        (entry, 'scene')
    assert hass.config_entries.async_forward_entry_setup.mock_calls[5][1] == \
        (entry, 'sensor')
    assert hass.config_entries.async_forward_entry_setup.mock_calls[6][1] == \
        (entry, 'switch')
    assert len(api.start.mock_calls) == 1
开发者ID:boced66,项目名称:home-assistant,代码行数:35,代码来源:test_gateway.py

示例8: test_add_new_device

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_add_new_device(hass):
    """Test adding a new device generates a signal for platforms."""
    entry = Mock()
    entry.data = {'host': '1.2.3.4', 'port': 80,
                  'api_key': '1234567890ABCDEF', 'allow_clip_sensor': False}
    new_event = {
        "t": "event",
        "e": "added",
        "r": "sensors",
        "id": "1",
        "sensor": {
            "config": {
                "on": "True",
                "reachable": "True"
            },
            "name": "event",
            "state": {},
            "type": "ZHASwitch"
        }
    }
    with patch.object(deconz, 'async_dispatcher_send') as mock_dispatch_send, \
            patch('pydeconz.DeconzSession.async_get_state',
                  return_value=mock_coro(CONFIG)), \
            patch('pydeconz.DeconzSession.start', return_value=True):
        assert await deconz.async_setup_entry(hass, entry) is True
        hass.data[deconz.DOMAIN].async_event_handler(new_event)
        await hass.async_block_till_done()
        assert len(mock_dispatch_send.mock_calls) == 1
        assert len(mock_dispatch_send.mock_calls[0]) == 3
开发者ID:,项目名称:,代码行数:31,代码来源:

示例9: _test_assert_not_blacklisted

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
    def _test_assert_not_blacklisted(self, url='http://example.com'):
        """Setup test environment and call the method."""
        form = Mock()
        field = Mock()
        field.data = url

        self.tested_instance.assert_not_blacklisted(form, field)
开发者ID:piotr-rusin,项目名称:url-shortener,代码行数:9,代码来源:test_validation.py

示例10: test_setup_entry_no_available_bridge

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_setup_entry_no_available_bridge(hass):
    """Test setup entry fails if deCONZ is not available."""
    entry = Mock()
    entry.data = {'host': '1.2.3.4', 'port': 80, 'api_key': '1234567890ABCDEF'}
    with patch('pydeconz.DeconzSession.async_load_parameters',
               return_value=mock_coro(False)):
        assert await deconz.async_setup_entry(hass, entry) is False
开发者ID:,项目名称:,代码行数:9,代码来源:

示例11: test_end_instance_no_permission

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
    def test_end_instance_no_permission(self):
        request = Mock(user=self.bad_user)
        recipe_instance = models.RecipeInstance.objects.create(
            recipe=self.recipe, brewhouse=self.brewhouse, active=True)

        request.data = {'recipe_instance': recipe_instance.pk,
                        'name': "nonexisting_sensor"}
        response = views.TimeSeriesIdentifyHandler.post(request)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:11,代码来源:views_test.py

示例12: test_decorated_method_bad_content

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
    def test_decorated_method_bad_content(self):

        json_request = Mock()
        json_request.data = 'wibble'
        json_request.headers = {'Accept': 'application/json', 'Content-Type': 'application/hdf'}

        response = self.decorated_method(self.path, json_request)
        assert_equal(response.status_code, 415)
        assert_equal(response.data, 'Request content type (application/hdf) not supported')
开发者ID:jamesh1999,项目名称:odin,代码行数:11,代码来源:test_adapter.py

示例13: test_decorated_method_bad_accept

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
    def test_decorated_method_bad_accept(self):

        request = Mock()
        request.data = 'Some text'
        request.headers = {'Accept': 'application/hdf', 'Content-Type': 'text/plain'}

        response = self.decorated_method(self.path, request)
        assert_equal(response.status_code, 406)
        assert_equal(response.data, 'Requested content types not supported')
开发者ID:jamesh1999,项目名称:odin,代码行数:11,代码来源:test_adapter.py

示例14: test_setup_entry_no_available_bridge

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_setup_entry_no_available_bridge(hass):
    """Test setup entry fails if deCONZ is not available."""
    entry = Mock()
    entry.data = {'host': '1.2.3.4', 'port': 80, 'api_key': '1234567890ABCDEF'}
    with patch(
        'pydeconz.DeconzSession.async_load_parameters',
        side_effect=asyncio.TimeoutError
    ), pytest.raises(ConfigEntryNotReady):
        await deconz.async_setup_entry(hass, entry)
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:11,代码来源:test_init.py

示例15: test_controller_host

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import data [as 别名]
async def test_controller_host():
    """Config entry host and controller host are the same."""
    hass = Mock()
    entry = Mock()
    entry.data = ENTRY_CONFIG

    unifi_controller = controller.UniFiController(hass, entry)

    assert unifi_controller.host == '1.2.3.4'
开发者ID:ManHammer,项目名称:home-assistant,代码行数:11,代码来源:test_controller.py


注:本文中的unittest.mock.Mock.data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。