• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python common.mock_http_component_app函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.common.mock_http_component_app函数的典型用法代码示例。如果您正苦于以下问题:Python mock_http_component_app函数的具体用法?Python mock_http_component_app怎么用?Python mock_http_component_app使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_get_groups

def test_get_groups(hass, test_client):
    """Test getting groupdata on node."""
    app = mock_http_component_app(hass)
    ZWaveNodeGroupView().register(app.router)

    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=2)
    node.groups.associations = 'assoc'
    node.groups.associations_instances = 'inst'
    node.groups.label = 'the label'
    node.groups.max_associations = 'max'
    node.groups = {1: node.groups}
    network.nodes = {2: node}

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/groups/2')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {
        '1': {
            'association_instances': 'inst',
            'associations': 'assoc',
            'label': 'the label',
            'max_associations': 'max'
        }
    }
开发者ID:tedstriker,项目名称:home-assistant,代码行数:29,代码来源:test_api.py


示例2: test_get_config

def test_get_config(hass, test_client):
    """Test getting config on node."""
    app = mock_http_component_app(hass)
    ZWaveNodeConfigView().register(app.router)

    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=2)
    value = MockValue(
        index=12,
        command_class=const.COMMAND_CLASS_CONFIGURATION)
    value.label = 'label'
    value.help = 'help'
    value.type = 'type'
    value.data = 'data'
    value.data_items = ['item1', 'item2']
    value.max = 'max'
    value.min = 'min'
    node.values = {12: value}
    network.nodes = {2: node}
    node.get_values.return_value = node.values

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/config/2')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {'12': {'data': 'data',
                             'data_items': ['item1', 'item2'],
                             'help': 'help',
                             'label': 'label',
                             'max': 'max',
                             'min': 'min',
                             'type': 'type'}}
开发者ID:tedstriker,项目名称:home-assistant,代码行数:35,代码来源:test_api.py


示例3: test_validate_config_ok

def test_validate_config_ok(hass, test_client):
    """Test checking config."""
    app = mock_http_component_app(hass)
    with patch.object(config, 'SECTIONS', ['core']):
        yield from async_setup_component(hass, 'config', {})

    hass.http.views[CheckConfigView.name].register(app.router)
    client = yield from test_client(app)

    with patch(
        'homeassistant.components.config.core.async_check_ha_config_file',
            return_value=mock_coro()):
        resp = yield from client.post('/api/config/core/check_config')

    assert resp.status == 200
    result = yield from resp.json()
    assert result['result'] == 'valid'
    assert result['errors'] is None

    with patch(
        'homeassistant.components.config.core.async_check_ha_config_file',
            return_value=mock_coro('beer')):
        resp = yield from client.post('/api/config/core/check_config')

    assert resp.status == 200
    result = yield from resp.json()
    assert result['result'] == 'invalid'
    assert result['errors'] == 'beer'
开发者ID:danieljkemp,项目名称:home-assistant,代码行数:28,代码来源:test_core.py


示例4: test_get_values

def test_get_values(hass, test_client):
    """Test getting values on node."""
    app = mock_http_component_app(hass)
    ZWaveNodeValueView().register(app.router)

    node = MockNode(node_id=1)
    value = MockValue(value_id=123456, node=node, label='Test Label')
    values = MockEntityValues(primary=value)
    node2 = MockNode(node_id=2)
    value2 = MockValue(value_id=234567, node=node2, label='Test Label 2')
    values2 = MockEntityValues(primary=value2)
    hass.data[const.DATA_ENTITY_VALUES] = [values, values2]

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/values/1')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {
        '123456': {
            'label': 'Test Label',
        }
    }
开发者ID:tedstriker,项目名称:home-assistant,代码行数:25,代码来源:test_api.py


示例5: test_get_usercodes_no_genreuser

def test_get_usercodes_no_genreuser(hass, test_client):
    """Test getting usercodes on node missing genre user."""
    app = mock_http_component_app(hass)
    ZWaveUserCodeView().register(app.router)

    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=18,
                    command_classes=[const.COMMAND_CLASS_USER_CODE])
    value = MockValue(
        index=0,
        command_class=const.COMMAND_CLASS_USER_CODE)
    value.genre = const.GENRE_SYSTEM
    value.label = 'label'
    value.data = '1234'
    node.values = {0: value}
    network.nodes = {18: node}
    node.get_values.return_value = node.values

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/usercodes/18')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {}
开发者ID:tedstriker,项目名称:home-assistant,代码行数:26,代码来源:test_api.py


示例6: test_get_device_config

def test_get_device_config(hass, test_client):
    """Test getting device config."""
    app = mock_http_component_app(hass)

    with patch.object(config, 'SECTIONS', ['group']):
        yield from async_setup_component(hass, 'config', {})

    hass.http.views[VIEW_NAME].register(app.router)

    client = yield from test_client(app)

    def mock_read(path):
        """Mock reading data."""
        return {
            'hello.beer': {
                'free': 'beer',
            },
            'other.entity': {
                'do': 'something',
            },
        }

    with patch('homeassistant.components.config._read', mock_read):
        resp = yield from client.get(
            '/api/config/group/config/hello.beer')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {'free': 'beer'}
开发者ID:danieljkemp,项目名称:home-assistant,代码行数:30,代码来源:test_group.py


示例7: test_registering_existing_device_fails_view

    def test_registering_existing_device_fails_view(self, loop, test_client):
        """Test sub. is not updated when registering existing device fails."""
        hass = MagicMock()
        expected = {
            'unnamed device': SUBSCRIPTION_1,
        }

        hass.config.path.return_value = CONFIG_FILE
        html5.get_service(hass, {})
        view = hass.mock_calls[1][1][0]

        hass.loop = loop
        app = mock_http_component_app(hass)
        view.register(app.router)
        client = yield from test_client(app)
        hass.http.is_banned_ip.return_value = False

        yield from client.post(REGISTER_URL,
                               data=json.dumps(SUBSCRIPTION_1))

        hass.async_add_job.side_effect = HomeAssistantError()
        resp = yield from client.post(REGISTER_URL,
                                      data=json.dumps(SUBSCRIPTION_4))

        content = yield from resp.text()
        assert resp.status == 500, content
        assert view.registrations == expected
开发者ID:devanl,项目名称:home-assistant,代码行数:27,代码来源:test_html5.py


示例8: test_registering_new_device_expiration_view

    def test_registering_new_device_expiration_view(self, loop, test_client):
        """Test that the HTML view works."""
        hass = MagicMock()
        expected = {
            'unnamed device': SUBSCRIPTION_4,
        }

        hass.config.path.return_value = CONFIG_FILE
        service = html5.get_service(hass, {})

        assert service is not None

        # assert hass.called
        assert len(hass.mock_calls) == 3

        view = hass.mock_calls[1][1][0]
        assert view.json_path == hass.config.path.return_value
        assert view.registrations == {}

        hass.loop = loop
        app = mock_http_component_app(hass)
        view.register(app.router)
        client = yield from test_client(app)
        hass.http.is_banned_ip.return_value = False
        resp = yield from client.post(REGISTER_URL,
                                      data=json.dumps(SUBSCRIPTION_4))

        content = yield from resp.text()
        assert resp.status == 200, content
        assert view.registrations == expected

        hass.async_add_job.assert_called_with(save_json, CONFIG_FILE, expected)
开发者ID:devanl,项目名称:home-assistant,代码行数:32,代码来源:test_html5.py


示例9: test_callback_view_no_jwt

    def test_callback_view_no_jwt(self, loop, test_client):
        """Test that the notification callback view works without JWT."""
        hass = MagicMock()

        m = mock_open()
        with patch(
            'homeassistant.util.json.open',
            m, create=True
        ):
            hass.config.path.return_value = 'file.conf'
            service = html5.get_service(hass, {})

            assert service is not None

            # assert hass.called
            assert len(hass.mock_calls) == 3

            view = hass.mock_calls[2][1][0]

            hass.loop = loop
            app = mock_http_component_app(hass)
            view.register(app.router)
            client = yield from test_client(app)
            hass.http.is_banned_ip.return_value = False

            resp = yield from client.post(PUBLISH_URL, data=json.dumps({
                'type': 'push',
                'tag': '3bc28d69-0921-41f1-ac6a-7a627ba0aa72'
            }))

            assert resp.status == 401, resp.response
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:31,代码来源:test_html5.py


示例10: test_callback_view_with_jwt

    def test_callback_view_with_jwt(self, loop, test_client):
        """Test that the notification callback view works with JWT."""
        hass = MagicMock()

        data = {
            'device': SUBSCRIPTION_1,
        }

        m = mock_open(read_data=json.dumps(data))
        with patch(
                'homeassistant.components.notify.html5.open', m, create=True
        ):
            hass.config.path.return_value = 'file.conf'
            with patch('homeassistant.components.notify.html5.os.path.isfile',
                       return_value=True):
                service = html5.get_service(hass, {'gcm_sender_id': '100'})

            assert service is not None

            # assert hass.called
            assert len(hass.mock_calls) == 3

            with patch('pywebpush.WebPusher') as mock_wp:
                service.send_message('Hello', target=['device'],
                                     data={'icon': 'beer.png'})

            assert len(mock_wp.mock_calls) == 3

            # WebPusher constructor
            assert mock_wp.mock_calls[0][1][0] == \
                SUBSCRIPTION_1['subscription']
            # Third mock_call checks the status_code of the response.
            assert mock_wp.mock_calls[2][0] == '().send().status_code.__eq__'

            # Call to send
            push_payload = json.loads(mock_wp.mock_calls[1][1][0])

            assert push_payload['body'] == 'Hello'
            assert push_payload['icon'] == 'beer.png'

            view = hass.mock_calls[2][1][0]
            view.registrations = data

            bearer_token = "Bearer {}".format(push_payload['data']['jwt'])

            hass.loop = loop
            app = mock_http_component_app(hass)
            view.register(app.router)
            client = yield from test_client(app)
            hass.http.is_banned_ip.return_value = False

            resp = yield from client.post(PUBLISH_URL, data=json.dumps({
                'type': 'push',
            }), headers={'Authorization': bearer_token})

            assert resp.status == 200
            body = yield from resp.json()
            assert body == {"event": "push", "status": "ok"}
开发者ID:Khabi,项目名称:home-assistant,代码行数:58,代码来源:test_html5.py


示例11: hue_client

def hue_client(loop, hass_hue, test_client):
    """Create web client for emulated hue api."""
    web_app = mock_http_component_app(hass_hue)
    config = Config(None, {'type': 'alexa'})

    HueUsernameView().register(web_app.router)
    HueAllLightsStateView(config).register(web_app.router)
    HueOneLightStateView(config).register(web_app.router)
    HueOneLightChangeView(config).register(web_app.router)

    return loop.run_until_complete(test_client(web_app))
开发者ID:Teagan42,项目名称:home-assistant,代码行数:11,代码来源:test_hue_api.py


示例12: websocket_client

def websocket_client(loop, hass, test_client):
    """Websocket client fixture connected to websocket server."""
    websocket_app = mock_http_component_app(hass)
    wapi.WebsocketAPIView().register(websocket_app.router)

    client = loop.run_until_complete(test_client(websocket_app))
    ws = loop.run_until_complete(client.ws_connect(wapi.URL))

    auth_ok = loop.run_until_complete(ws.receive_json())
    assert auth_ok['type'] == wapi.TYPE_AUTH_OK

    yield ws

    if not ws.closed:
        loop.run_until_complete(ws.close())
开发者ID:ozzpy,项目名称:home-assistant,代码行数:15,代码来源:test_websocket_api.py


示例13: no_auth_websocket_client

def no_auth_websocket_client(hass, loop, test_client):
    """Websocket connection that requires authentication."""
    websocket_app = mock_http_component_app(hass, API_PASSWORD)
    wapi.WebsocketAPIView().register(websocket_app.router)

    client = loop.run_until_complete(test_client(websocket_app))
    ws = loop.run_until_complete(client.ws_connect(wapi.URL))

    auth_ok = loop.run_until_complete(ws.receive_json())
    assert auth_ok['type'] == wapi.TYPE_AUTH_REQUIRED

    yield ws

    if not ws.closed:
        loop.run_until_complete(ws.close())
开发者ID:ozzpy,项目名称:home-assistant,代码行数:15,代码来源:test_websocket_api.py


示例14: test_update_device_config_invalid_json

def test_update_device_config_invalid_json(hass, test_client):
    """Test updating device config."""
    app = mock_http_component_app(hass)

    with patch.object(config, 'SECTIONS', ['group']):
        yield from async_setup_component(hass, 'config', {})

    hass.http.views[VIEW_NAME].register(app.router)

    client = yield from test_client(app)

    resp = yield from client.post(
        '/api/config/group/config/hello_beer', data='not json')

    assert resp.status == 400
开发者ID:danieljkemp,项目名称:home-assistant,代码行数:15,代码来源:test_group.py


示例15: test_get_groups_nonode

def test_get_groups_nonode(hass, test_client):
    """Test getting groupdata on nonexisting node."""
    app = mock_http_component_app(hass)
    ZWaveNodeGroupView().register(app.router)

    network = hass.data[DATA_NETWORK] = MagicMock()
    network.nodes = {1: 1, 5: 5}

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/groups/2')

    assert resp.status == 404
    result = yield from resp.json()

    assert result == {'message': 'Node not found'}
开发者ID:tedstriker,项目名称:home-assistant,代码行数:16,代码来源:test_api.py


示例16: test_update_device_config_invalid_key

def test_update_device_config_invalid_key(hass, test_client):
    """Test updating device config."""
    app = mock_http_component_app(hass)

    with patch.object(config, 'SECTIONS', ['zwave']):
        yield from async_setup_component(hass, 'config', {})

    hass.http.views[VIEW_NAME].register(app.router)

    client = yield from test_client(app)

    resp = yield from client.post(
        '/api/config/zwave/device_config/invalid_entity', data=json.dumps({
            'polling_intensity': 2
        }))

    assert resp.status == 400
开发者ID:azogue,项目名称:home-assistant,代码行数:17,代码来源:test_zwave.py


示例17: test_update_device_config

def test_update_device_config(hass, test_client):
    """Test updating device config."""
    app = mock_http_component_app(hass)

    with patch.object(config, 'SECTIONS', ['group']):
        yield from async_setup_component(hass, 'config', {})

    hass.http.views[VIEW_NAME].register(app.router)

    client = yield from test_client(app)

    orig_data = {
        'hello.beer': {
            'ignored': True,
        },
        'other.entity': {
            'polling_intensity': 2,
        },
    }

    def mock_read(path):
        """Mock reading data."""
        return orig_data

    written = []

    def mock_write(path, data):
        """Mock writing data."""
        written.append(data)

    with patch('homeassistant.components.config._read', mock_read), \
            patch('homeassistant.components.config._write', mock_write):
        resp = yield from client.post(
            '/api/config/group/config/hello_beer', data=json.dumps({
                'name': 'Beer',
                'entities': ['light.top', 'light.bottom'],
            }))

    assert resp.status == 200
    result = yield from resp.json()
    assert result == {'result': 'ok'}

    orig_data['hello_beer']['name'] = 'Beer'
    orig_data['hello_beer']['entities'] = ['light.top', 'light.bottom']

    assert written[0] == orig_data
开发者ID:azogue,项目名称:home-assistant,代码行数:46,代码来源:test_group.py


示例18: test_install_suite

def test_install_suite(hass, test_client):
    """Test getting suites."""
    app = mock_http_component_app(hass)

    with patch.dict(os.environ, {'FORCE_HASSBIAN': '1'}), \
            patch.object(config, 'SECTIONS', ['hassbian']):
        yield from async_setup_component(hass, 'config', {})

    hass.http.views[HassbianSuiteInstallView.name].register(app.router)

    client = yield from test_client(app)
    resp = yield from client.post(
        '/api/config/hassbian/suites/openzwave/install')
    assert resp.status == 200
    result = yield from resp.json()

    assert result == {"status": "ok"}
开发者ID:azogue,项目名称:home-assistant,代码行数:17,代码来源:test_hassbian.py


示例19: test_registering_new_device_validation

    def test_registering_new_device_validation(self, loop, test_client):
        """Test various errors when registering a new device."""
        hass = MagicMock()

        m = mock_open()
        with patch(
            'homeassistant.util.json.open',
            m, create=True
        ):
            hass.config.path.return_value = 'file.conf'
            service = html5.get_service(hass, {})

            assert service is not None

            # assert hass.called
            assert len(hass.mock_calls) == 3

            view = hass.mock_calls[1][1][0]

            hass.loop = loop
            app = mock_http_component_app(hass)
            view.register(app.router)
            client = yield from test_client(app)
            hass.http.is_banned_ip.return_value = False

            resp = yield from client.post(REGISTER_URL, data=json.dumps({
                'browser': 'invalid browser',
                'subscription': 'sub info',
            }))
            assert resp.status == 400

            resp = yield from client.post(REGISTER_URL, data=json.dumps({
                'browser': 'chrome',
            }))
            assert resp.status == 400

            with patch('homeassistant.components.notify.html5.save_json',
                       return_value=False):
                # resp = view.post(Request(builder.get_environ()))
                resp = yield from client.post(REGISTER_URL, data=json.dumps({
                    'browser': 'chrome',
                    'subscription': 'sub info',
                }))

            assert resp.status == 400
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:45,代码来源:test_html5.py


示例20: test_get_groups_nogroups

def test_get_groups_nogroups(hass, test_client):
    """Test getting groupdata on node with no groups."""
    app = mock_http_component_app(hass)
    ZWaveNodeGroupView().register(app.router)

    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=2)

    network.nodes = {2: node}

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/groups/2')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {}
开发者ID:tedstriker,项目名称:home-assistant,代码行数:18,代码来源:test_api.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.mock_mqtt_component函数代码示例发布时间:2022-05-27
下一篇:
Python common.mock_coro函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap