本文整理汇总了Python中unittest.mock.Mock.installed_app_id方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.installed_app_id方法的具体用法?Python Mock.installed_app_id怎么用?Python Mock.installed_app_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.installed_app_id方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_smartapp_install_creates_flow
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
async def test_smartapp_install_creates_flow(
hass, smartthings_mock, config_entry, location):
"""Test installation creates flow."""
# Arrange
setattr(hass.config_entries, '_entries', [config_entry])
api = smartthings_mock.return_value
api.create_subscription.return_value = mock_coro()
app = Mock()
app.app_id = config_entry.data['app_id']
request = Mock()
request.installed_app_id = str(uuid4())
request.auth_token = str(uuid4())
request.location_id = location.location_id
# Act
await smartapp.smartapp_install(hass, request, None, app)
# Assert
await hass.async_block_till_done()
entries = hass.config_entries.async_entries('smartthings')
assert len(entries) == 2
assert api.create_subscription.call_count == \
len(SUPPORTED_CAPABILITIES)
assert entries[1].data['app_id'] == app.app_id
assert entries[1].data['installed_app_id'] == request.installed_app_id
assert entries[1].data['location_id'] == request.location_id
assert entries[1].data['access_token'] == \
config_entry.data['access_token']
assert entries[1].title == location.name
示例2: test_smartapp_update_syncs_subs
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
async def test_smartapp_update_syncs_subs(
hass, smartthings_mock, config_entry, location, device_factory):
"""Test update synchronizes subscriptions."""
# Arrange
setattr(hass.config_entries, '_entries', [config_entry])
app = Mock()
app.app_id = config_entry.data['app_id']
api = smartthings_mock.return_value
api.delete_subscriptions = Mock()
api.delete_subscriptions.return_value = mock_coro()
api.create_subscription.return_value = mock_coro()
request = Mock()
request.installed_app_id = str(uuid4())
request.auth_token = str(uuid4())
request.location_id = location.location_id
devices = [
device_factory('', [Capability.battery, 'ping']),
device_factory('', [Capability.switch, Capability.switch_level]),
device_factory('', [Capability.switch])
]
api.devices = Mock()
api.devices.return_value = mock_coro(return_value=devices)
# Act
await smartapp.smartapp_update(hass, request, None, app)
# Assert
assert api.create_subscription.call_count == 3
assert api.delete_subscriptions.call_count == 1
示例3: test_smartapp_install_creates_flow
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
async def test_smartapp_install_creates_flow(
hass, smartthings_mock, config_entry, location, device_factory):
"""Test installation creates flow."""
# Arrange
setattr(hass.config_entries, '_entries', [config_entry])
api = smartthings_mock.return_value
api.create_subscription.return_value = mock_coro()
app = Mock()
app.app_id = config_entry.data['app_id']
request = Mock()
request.installed_app_id = str(uuid4())
request.auth_token = str(uuid4())
request.location_id = location.location_id
devices = [
device_factory('', [Capability.battery, 'ping']),
device_factory('', [Capability.switch, Capability.switch_level]),
device_factory('', [Capability.switch])
]
api.devices = Mock()
api.devices.return_value = mock_coro(return_value=devices)
# Act
await smartapp.smartapp_install(hass, request, None, app)
# Assert
await hass.async_block_till_done()
entries = hass.config_entries.async_entries('smartthings')
assert len(entries) == 2
assert api.create_subscription.call_count == 3
assert entries[1].data['app_id'] == app.app_id
assert entries[1].data['installed_app_id'] == request.installed_app_id
assert entries[1].data['location_id'] == request.location_id
assert entries[1].data['access_token'] == \
config_entry.data['access_token']
assert entries[1].title == location.name
示例4: test_smartapp_install_abort_if_no_other
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
async def test_smartapp_install_abort_if_no_other(
hass, smartthings_mock, device_factory):
"""Test aborts if no other app was configured already."""
# Arrange
api = smartthings_mock.return_value
api.create_subscription.return_value = mock_coro()
app = Mock()
app.app_id = uuid4()
request = Mock()
request.installed_app_id = uuid4()
request.auth_token = uuid4()
request.location_id = uuid4()
devices = [
device_factory('', [Capability.battery, 'ping']),
device_factory('', [Capability.switch, Capability.switch_level]),
device_factory('', [Capability.switch])
]
api.devices = Mock()
api.devices.return_value = mock_coro(return_value=devices)
# Act
await smartapp.smartapp_install(hass, request, None, app)
# Assert
entries = hass.config_entries.async_entries('smartthings')
assert not entries
assert api.create_subscription.call_count == 3
示例5: _factory
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
def _factory(device_ids=None, events=None):
request = Mock()
request.installed_app_id = uuid4()
if events is None:
events = []
if device_ids:
events.extend([event_factory(id) for id in device_ids])
events.append(event_factory(uuid4()))
events.append(event_factory(device_ids[0], event_type="OTHER"))
request.events = events
return request
示例6: test_smartapp_uninstall
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
async def test_smartapp_uninstall(hass, config_entry):
"""Test the config entry is unloaded when the app is uninstalled."""
setattr(hass.config_entries, '_entries', [config_entry])
app = Mock()
app.app_id = config_entry.data['app_id']
request = Mock()
request.installed_app_id = config_entry.data['installed_app_id']
with patch.object(hass.config_entries, 'async_remove',
return_value=mock_coro()) as remove:
await smartapp.smartapp_uninstall(hass, request, None, app)
assert remove.call_count == 1
示例7: test_smartapp_install_abort_if_no_other
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
async def test_smartapp_install_abort_if_no_other(hass, smartthings_mock):
"""Test aborts if no other app was configured already."""
api = smartthings_mock.return_value
api.create_subscription.return_value = mock_coro()
app = Mock()
app.app_id = uuid4()
request = Mock()
request.installed_app_id = uuid4()
request.auth_token = uuid4()
request.location_id = uuid4()
await smartapp.smartapp_install(hass, request, None, app)
entries = hass.config_entries.async_entries('smartthings')
assert not entries
assert api.create_subscription.call_count == \
len(SUPPORTED_CAPABILITIES)
示例8: test_smartapp_install_store_if_no_other
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
async def test_smartapp_install_store_if_no_other(
hass, smartthings_mock, device_factory):
"""Test aborts if no other app was configured already."""
# Arrange
app = Mock()
app.app_id = uuid4()
request = Mock()
request.installed_app_id = str(uuid4())
request.auth_token = str(uuid4())
request.location_id = str(uuid4())
request.refresh_token = str(uuid4())
# Act
await smartapp.smartapp_install(hass, request, None, app)
# Assert
entries = hass.config_entries.async_entries('smartthings')
assert not entries
data = hass.data[DOMAIN][CONF_INSTALLED_APPS][0]
assert data[CONF_REFRESH_TOKEN] == request.refresh_token
assert data[CONF_LOCATION_ID] == request.location_id
assert data[CONF_INSTALLED_APP_ID] == request.installed_app_id
示例9: test_smartapp_update_saves_token
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import installed_app_id [as 别名]
async def test_smartapp_update_saves_token(
hass, smartthings_mock, location, device_factory):
"""Test update saves token."""
# Arrange
entry = Mock()
entry.data = {
'installed_app_id': str(uuid4()),
'app_id': str(uuid4())
}
entry.domain = DOMAIN
setattr(hass.config_entries, '_entries', [entry])
app = Mock()
app.app_id = entry.data['app_id']
request = Mock()
request.installed_app_id = entry.data['installed_app_id']
request.auth_token = str(uuid4())
request.refresh_token = str(uuid4())
request.location_id = location.location_id
# Act
await smartapp.smartapp_update(hass, request, None, app)
# Assert
assert entry.data[CONF_REFRESH_TOKEN] == request.refresh_token