コード例 #1
0
ファイル: test_init.py プロジェクト: Khabi/home-assistant
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'
コード例 #2
0
ファイル: test_init.py プロジェクト: Teagan42/home-assistant
    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))
コード例 #3
0
ファイル: test_init.py プロジェクト: arsaboo/home-assistant
    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()}})
コード例 #4
0
    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))
コード例 #5
0
ファイル: test_init.py プロジェクト: Khabi/home-assistant
"""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 = '******'
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
コード例 #6
0
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,
コード例 #7
0
ファイル: test_api.py プロジェクト: bdfoster/blumate
    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': '******'}),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'api_password': '******',
                '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': '******',
                '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)
コード例 #8
0
ファイル: test_apiai.py プロジェクト: loraxx753/skynet
"""The tests for the APIAI component."""
# pylint: disable=protected-access
import json
import unittest

import requests

from homeassistant.core import callback
from homeassistant import bootstrap, const
from homeassistant.components import apiai, http

from tests.common import get_test_instance_port, get_test_home_assistant

API_PASSWORD = "******"
SERVER_PORT = get_test_instance_port()
BASE_API_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
INTENTS_API_URL = "{}{}".format(BASE_API_URL, apiai.INTENTS_API_ENDPOINT)

HA_HEADERS = {
    const.HTTP_HEADER_HA_AUTH: API_PASSWORD,
    const.HTTP_HEADER_CONTENT_TYPE: const.CONTENT_TYPE_JSON,
}

SESSION_ID = "a9b84cec-46b6-484e-8f31-f65dba03ae6d"
INTENT_ID = "c6a74079-a8f0-46cd-b372-5a934d23591c"
INTENT_NAME = "tests"
REQUEST_ID = "19ef7e78-fe15-4e94-99dd-0c0b1e8753c3"
REQUEST_TIMESTAMP = "2017-01-21T17:54:18.952Z"
CONTEXT_NAME = "78a5db95-b7d6-4d50-9c9b-2fc73a5e34c3_id_dialog_context"
MAX_RESPONSE_TIME = 5  # https://docs.api.ai/docs/webhook
コード例 #9
0
ファイル: test_upnp.py プロジェクト: sara0871/master.zip
"""The tests for the emulated Hue component."""
import json

import unittest
from unittest.mock import patch
import requests
from aiohttp.hdrs import CONTENT_TYPE

from homeassistant import setup, const, core
import homeassistant.components as core_components
from homeassistant.components import emulated_hue, http
from homeassistant.util.async_ import run_coroutine_threadsafe

from tests.common import get_test_instance_port, get_test_home_assistant

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}


def setup_hass_instance(emulated_hue_config):
    """Set up the Home Assistant instance to test."""
    hass = get_test_home_assistant()

    # We need to do this to get access to homeassistant/turn_(on,off)
    run_coroutine_threadsafe(
        core_components.async_setup(hass, {core.DOMAIN: {}}), hass.loop
    ).result()
コード例 #10
0
ファイル: test_api.py プロジェクト: syphernl/home-assistant
    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': '******'}),
                            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(_url(const.URL_API_EVENT_FORWARD),
                            data=json.dumps({
                                'api_password': '******',
                                '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': '******',
                                '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)
コード例 #11
0
ファイル: test_remote.py プロジェクト: DavidLP/home-assistant
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 = '******'
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

コード例 #12
0
import time
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 = "******"
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

コード例 #13
0
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 = '******'
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

コード例 #14
0
    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': '******'}),
            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(
            _url(const.URL_API_EVENT_FORWARD),
            data=json.dumps({
                'api_password': '******',
                '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': '******',
                '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)
コード例 #15
0
ファイル: test_remote.py プロジェクト: loraxx753/skynet
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 = '******'
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

コード例 #16
0
ファイル: test_api.py プロジェクト: lumavp/blumate
    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': '******'}),
                            headers=HA_HEADERS)
        self.assertEqual(400, req.status_code)

        req = requests.post(_url(const.URL_API_EVENT_FORWARD),
                            data=json.dumps({
                                'api_password': '******',
                                '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': '******',
                                '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)