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

Python common.get_test_instance_port函数代码示例

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

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



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

示例1: test_registering_view_while_running

def test_registering_view_while_running(hass, test_client):
    """Test that we can register a view while the server is running."""
    yield from setup.async_setup_component(
        hass, http.DOMAIN, {
            http.DOMAIN: {
                http.CONF_SERVER_PORT: get_test_instance_port(),
            }
        }
    )

    yield from setup.async_setup_component(hass, 'api')

    yield from hass.async_start()

    yield from hass.async_block_till_done()

    hass.http.register_view(TestView)

    client = yield from test_client(hass.http.app)

    resp = yield from client.get('/hello')
    assert resp.status == 200

    text = yield from resp.text()
    assert text == 'hello'
开发者ID:Khabi,项目名称:home-assistant,代码行数:25,代码来源:test_init.py


示例2: setup_method

    def setup_method(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()

        setup_component(
            self.hass, http.DOMAIN,
            {http.DOMAIN: {http.CONF_SERVER_PORT: get_test_instance_port()}})

        config = {
            ip.DOMAIN: {
                'platform': 'demo'
            },
            'camera': {
                'platform': 'demo'
            },
        }

        with patch('homeassistant.components.image_processing.demo.'
                   'DemoImageProcessing.should_poll',
                   new_callable=PropertyMock(return_value=False)):
            setup_component(self.hass, ip.DOMAIN, config)

        state = self.hass.states.get('camera.demo_camera')
        self.url = "{0}{1}".format(
            self.hass.config.api.base_url,
            state.attributes.get(ATTR_ENTITY_PICTURE))
开发者ID:Teagan42,项目名称:home-assistant,代码行数:26,代码来源:test_init.py


示例3: setup_method

    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.demo_provider = DemoProvider('en')
        self.default_tts_cache = self.hass.config.path(tts.DEFAULT_CACHE_DIR)

        setup_component(
            self.hass, http.DOMAIN,
            {http.DOMAIN: {http.CONF_SERVER_PORT: get_test_instance_port()}})
开发者ID:arsaboo,项目名称:home-assistant,代码行数:9,代码来源:test_init.py


示例4: setup_method

    def setup_method(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()

        setup_component(
            self.hass, http.DOMAIN,
            {http.DOMAIN: {http.CONF_SERVER_PORT: get_test_instance_port()}})

        config = {
            camera.DOMAIN: {
                'platform': 'demo'
            }
        }

        setup_component(self.hass, camera.DOMAIN, config)

        state = self.hass.states.get('camera.demo_camera')
        self.url = "{0}{1}".format(
            self.hass.config.api.base_url,
            state.attributes.get(ATTR_ENTITY_PICTURE))
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:20,代码来源:test_init.py


示例5: get_test_instance_port

"""The tests for the Home Assistant HTTP component."""
import asyncio
import requests

from homeassistant import setup, const
import homeassistant.components.http as http

from tests.common import get_test_instance_port, get_test_home_assistant

API_PASSWORD = 'test1234'
SERVER_PORT = get_test_instance_port()
HTTP_BASE = '127.0.0.1:{}'.format(SERVER_PORT)
HTTP_BASE_URL = 'http://{}'.format(HTTP_BASE)
HA_HEADERS = {
    const.HTTP_HEADER_HA_AUTH: API_PASSWORD,
    const.HTTP_HEADER_CONTENT_TYPE: const.CONTENT_TYPE_JSON,
}
CORS_ORIGINS = [HTTP_BASE_URL, HTTP_BASE]

hass = None


def _url(path=''):
    """Helper method to generate URLs."""
    return HTTP_BASE_URL + path


# pylint: disable=invalid-name
def setUpModule():
    """Initialize a Home Assistant server."""
    global hass
开发者ID:Khabi,项目名称:home-assistant,代码行数:31,代码来源:test_init.py


示例6: import

from aiohttp.hdrs import CONTENT_TYPE
import pytest
from tests.common import get_test_instance_port

from homeassistant import core, const, setup
import homeassistant.components as core_components
from homeassistant.components import (
    fan, http, light, script, emulated_hue, media_player)
from homeassistant.components.emulated_hue import Config
from homeassistant.components.emulated_hue.hue_api import (
    HUE_API_STATE_ON, HUE_API_STATE_BRI, HueUsernameView, HueOneLightStateView,
    HueAllLightsStateView, HueOneLightChangeView)
from homeassistant.const import STATE_ON, STATE_OFF

HTTP_SERVER_PORT = get_test_instance_port()
BRIDGE_SERVER_PORT = get_test_instance_port()

BRIDGE_URL_BASE = 'http://127.0.0.1:{}'.format(BRIDGE_SERVER_PORT) + '{}'
JSON_HEADERS = {CONTENT_TYPE: const.CONTENT_TYPE_JSON}


@pytest.fixture
def hass_hue(loop, hass):
    """Setup a Home Assistant instance for these tests."""
    # We need to do this to get access to homeassistant/turn_(on,off)
    loop.run_until_complete(
        core_components.async_setup(hass, {core.DOMAIN: {}}))

    loop.run_until_complete(setup.async_setup_component(
        hass, http.DOMAIN,
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:30,代码来源:test_hue_api.py


示例7: test_api_event_forward

    def test_api_event_forward(self):
        """Test setting up event forwarding."""
        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({'host': '127.0.0.1'}),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({'api_password': 'bla-di-bla'}),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'api_password': 'bla-di-bla',
                'host': '127.0.0.1',
                'port': 'abcd'
                }),
            headers=HA_HEADERS)
        self.assertEqual(422, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'api_password': 'bla-di-bla',
                'host': '127.0.0.1',
                'port': get_test_instance_port()
                }),
            headers=HA_HEADERS)
        self.assertEqual(422, req.status_code)

        # TODO disabled because eventlet cannot validate
        # a connection to itself, need a second instance
        # # Setup a real one
        # req = requests.post(
        #     _url(const.URL_API_EVENT_FORWARD),
        #     data=json.dumps({
        #         'api_password': API_PASSWORD,
        #         'host': '127.0.0.1',
        #         'port': SERVER_PORT
        #         }),
        #     headers=HA_HEADERS)
        # self.assertEqual(200, req.status_code)

        # # Delete it again..
        # req = requests.delete(
        #     _url(const.URL_API_EVENT_FORWARD),
        #     data=json.dumps({}),
        #     headers=HA_HEADERS)
        # self.assertEqual(400, req.status_code)

        req = requests.delete(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'host': '127.0.0.1',
                'port': 'abcd'
                }),
            headers=HA_HEADERS)
        self.assertEqual(422, req.status_code)

        req = requests.delete(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'host': '127.0.0.1',
                'port': SERVER_PORT
                }),
            headers=HA_HEADERS)
        self.assertEqual(200, req.status_code)
开发者ID:bdfoster,项目名称:blumate,代码行数:76,代码来源:test_api.py


示例8: import

import threading
import unittest
from unittest.mock import patch

import homeassistant.core as ha
import homeassistant.bootstrap as bootstrap
import homeassistant.remote as remote
import homeassistant.components.http as http
from homeassistant.const import HTTP_HEADER_HA_AUTH, EVENT_STATE_CHANGED
import homeassistant.util.dt as dt_util

from tests.common import (
    get_test_instance_port, get_test_home_assistant, get_test_config_dir)

API_PASSWORD = 'test1234'
MASTER_PORT = get_test_instance_port()
SLAVE_PORT = get_test_instance_port()
BROKEN_PORT = get_test_instance_port()
HTTP_BASE_URL = 'http://127.0.0.1:{}'.format(MASTER_PORT)

HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}

broken_api = remote.API('127.0.0.1', "bladiebla")
hass, slave, master_api = None, None, None


def _url(path=''):
    """Helper method to generate URLs."""
    return HTTP_BASE_URL + path

开发者ID:DavidLP,项目名称:home-assistant,代码行数:29,代码来源:test_remote.py


示例9: import

import threading
import unittest
from unittest.mock import patch

import homeassistant.core as ha
import homeassistant.bootstrap as bootstrap
import homeassistant.remote as remote
import homeassistant.components.http as http
from homeassistant.const import HTTP_HEADER_HA_AUTH, EVENT_STATE_CHANGED
import homeassistant.util.dt as dt_util

from tests.common import (
    get_test_instance_port, get_test_home_assistant, get_test_config_dir)

API_PASSWORD = 'test1234'
MASTER_PORT = get_test_instance_port()
SLAVE_PORT = get_test_instance_port()
BROKEN_PORT = get_test_instance_port()
HTTP_BASE_URL = 'http://127.0.0.1:{}'.format(MASTER_PORT)

HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}

broken_api = remote.API('127.0.0.1', "bladybla", port=get_test_instance_port())
hass, slave, master_api = None, None, None


def _url(path=''):
    """Helper method to generate URLs."""
    return HTTP_BASE_URL + path

开发者ID:Teagan42,项目名称:home-assistant,代码行数:29,代码来源:test_remote.py


示例10: test_api_event_forward

    def test_api_event_forward(self):
        """ Test setting up event forwarding. """

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({'host': '127.0.0.1'}),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({'api_password': 'bla-di-bla'}),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'api_password': 'bla-di-bla',
                'host': '127.0.0.1',
                'port': 'abcd'
                }),
            headers=HA_HEADERS)
        self.assertEqual(422, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'api_password': 'bla-di-bla',
                'host': '127.0.0.1',
                'port': get_test_instance_port()
                }),
            headers=HA_HEADERS)
        self.assertEqual(422, req.status_code)

        # Setup a real one
        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'api_password': API_PASSWORD,
                'host': '127.0.0.1',
                'port': SERVER_PORT
                }),
            headers=HA_HEADERS)
        self.assertEqual(200, req.status_code)

        # Delete it again..
        req = requests.delete(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({}),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.delete(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'host': '127.0.0.1',
                'port': 'abcd'
                }),
            headers=HA_HEADERS)
        self.assertEqual(422, req.status_code)

        req = requests.delete(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'host': '127.0.0.1',
                'port': SERVER_PORT
                }),
            headers=HA_HEADERS)
        self.assertEqual(200, req.status_code)
开发者ID:100dayproject,项目名称:home-assistant,代码行数:75,代码来源:test_api.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python common.init_recorder_component函数代码示例发布时间:2022-05-27
下一篇:
Python common.get_test_home_assistant函数代码示例发布时间: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