コード例 #1
0
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()
        self.opp.data.pop(DATA_CUSTOM_COMPONENTS)

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

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

        setup_component(self.opp, ip.DOMAIN, config)
        self.opp.block_till_done()

        state = self.opp.states.get("camera.demo_camera")
        self.url = (
            f"{self.opp.config.internal_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
        )
コード例 #2
0
 def setUp(self):  # pylint: disable=invalid-name
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     assert setup_component(self.opp, lock.DOMAIN,
                            {"lock": {
                                "platform": "demo"
                            }})
コード例 #3
0
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()

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

        with patch(
                "openpeerpower.components.demo.image_processing."
                "DemoImageProcessingFace.should_poll",
                new_callable=PropertyMock(return_value=False),
        ):
            setup_component(self.opp, ip.DOMAIN, config)
            self.opp.block_till_done()

        state = self.opp.states.get("camera.demo_camera")
        self.url = (
            f"{self.opp.config.internal_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}"
        )

        self.face_events = []

        @callback
        def mock_face_event(event):
            """Mock event."""
            self.face_events.append(event)

        self.opp.bus.listen("image_processing.detect_face", mock_face_event)
コード例 #4
0
ファイル: test_init.py プロジェクト: OpenPeerPower/core
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()

        self.config = {mf.DOMAIN: {"api_key": "12345678abcdef"}}

        self.endpoint_url = f"https://westus.{mf.FACE_API_URL}"
コード例 #5
0
ファイル: test_weather.py プロジェクト: OpenPeerPower/core
 def setUp(self):
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     self.opp.config.units = METRIC_SYSTEM
     self.lat = self.opp.config.latitude = 37.8267
     self.lon = self.opp.config.longitude = -122.423
     self.addCleanup(self.tear_down_cleanup)
コード例 #6
0
 def setUp(self):
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     platform = getattr(self.opp.components, "test.switch")
     platform.init()
     # Switch 1 is ON, switch 2 is OFF
     self.switch_1, self.switch_2, self.switch_3 = platform.ENTITIES
コード例 #7
0
 def setup_method(self, method):
     """Set up things to be run when tests are started."""
     self.entity = entity.Entity()
     self.entity.entity_id = "test.overwrite_hidden_true"
     self.opp = self.entity.opp = get_test_open_peer_power()
     self.entity.schedule_update_op_state()
     self.opp.block_till_done()
コード例 #8
0
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.url = "https://example.com/"
        self.config = {
            rc.DOMAIN: {
                "get_test": {
                    "url": self.url,
                    "method": "get"
                },
                "patch_test": {
                    "url": self.url,
                    "method": "patch"
                },
                "post_test": {
                    "url": self.url,
                    "method": "post"
                },
                "put_test": {
                    "url": self.url,
                    "method": "put"
                },
                "delete_test": {
                    "url": self.url,
                    "method": "delete"
                },
            }
        }

        self.opp = get_test_open_peer_power()
コード例 #9
0
 def setUp(self):
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     assert setup_component(self.opp, remote.DOMAIN,
                            {"remote": {
                                "platform": "demo"
                            }})
コード例 #10
0
 def setUp(self):
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     self.opp.config.units = METRIC_SYSTEM
     assert setup_component(
         self.opp, weather.DOMAIN, {"weather": {"platform": "demo"}}
     )
コード例 #11
0
 def setUp(self):
     """Initialize values for this testcase class."""
     self.opp = get_test_open_peer_power()
     self.mock_kira = MagicMock()
     self.opp.data[kira.DOMAIN] = {kira.CONF_REMOTE: {}}
     self.opp.data[kira.DOMAIN][kira.CONF_REMOTE]["kira"] = self.mock_kira
     self.addCleanup(self.opp.stop)
コード例 #12
0
 def setUp(self):  # pylint: disable=invalid-name
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     self.opp.config.units = IMPERIAL_SYSTEM
     assert setup_component(self.opp, water_heater.DOMAIN,
                            {"water_heater": {
                                "platform": "demo"
                            }})
コード例 #13
0
 def setUp(self):
     """Initialize values for this testcase class."""
     self.opp = get_test_open_peer_power()
     self.key = "foo"
     self.lat = self.opp.config.latitude = 37.8267
     self.lon = self.opp.config.longitude = -122.423
     self.entities = []
     self.addCleanup(self.tear_down_cleanup)
コード例 #14
0
 def setUp(self):
     """Init values for this testcase class."""
     self.opp = get_test_open_peer_power()
     self.configs = [
         {CONF_SUBSCRIPTION: "576965", CONF_NAME: "A Server"},
         {CONF_SUBSCRIPTION: "123456", CONF_NAME: "Failed Server"},
         {CONF_SUBSCRIPTION: "555555", CONF_NAME: vultr.DEFAULT_NAME},
     ]
     self.addCleanup(self.tear_down_cleanup)
コード例 #15
0
    def setUp(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()
        assert asyncio.run_coroutine_threadsafe(
            async_setup_component(self.opp, "openpeerpower", {}),
            self.opp.loop).result()

        self.opp.states.set("light.Bowl", STATE_ON)
        self.opp.states.set("light.Ceiling", STATE_OFF)
コード例 #16
0
ファイル: test_tts.py プロジェクト: OpenPeerPower/core
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()
        self._base_url = "https://tts.voicetech.yandex.net/generate?"

        asyncio.run_coroutine_threadsafe(
            async_process_op_core_config(
                self.opp, {"internal_url": "http://example.local:8123"}),
            self.opp.loop,
        )
コード例 #17
0
ファイル: test_sensor.py プロジェクト: OpenPeerPower/core
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()

        self.config = {
            "binary_sensor": {
                "platform": "ffmpeg_motion",
                "input": "testinputvideo"
            }
        }
コード例 #18
0
 def setUp(self):
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     self.opp.states.set(
         "test.indoortemp", "20", {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
     )
     self.opp.states.set(
         "test.outdoortemp", "10", {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
     )
     self.opp.states.set(
         "test.indoorhumidity", "50", {ATTR_UNIT_OF_MEASUREMENT: "%"}
     )
コード例 #19
0
    def setUp(self):  # pylint: disable=invalid-name
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()
        self.events = []
        self.calls = []

        @callback
        def record_event(event):
            """Record event to send notification."""
            self.events.append(event)

        self.opp.bus.listen(demo.EVENT_NOTIFY, record_event)
コード例 #20
0
ファイル: test_init.py プロジェクト: OpenPeerPower/core
def test_service_disable_run_information_recorded(tmpdir):
    """Test that runs are still recorded when recorder is disabled."""
    test_db_file = tmpdir.mkdir("sqlite").join("test_run_info.db")
    dburl = f"{SQLITE_URL_PREFIX}//{test_db_file}"

    opp = get_test_open_peer_power()
    setup_component(opp, DOMAIN, {DOMAIN: {CONF_DB_URL: dburl}})
    opp.start()
    wait_recording_done(opp)

    with session_scope(opp=opp) as session:
        db_run_info = list(session.query(RecorderRuns))
        assert len(db_run_info) == 1
        assert db_run_info[0].start is not None
        assert db_run_info[0].end is None

    assert opp.services.call(
        DOMAIN,
        SERVICE_DISABLE,
        {},
        blocking=True,
    )

    wait_recording_done(opp)
    opp.stop()

    opp = get_test_open_peer_power()
    setup_component(opp, DOMAIN, {DOMAIN: {CONF_DB_URL: dburl}})
    opp.start()
    wait_recording_done(opp)

    with session_scope(opp=opp) as session:
        db_run_info = list(session.query(RecorderRuns))
        assert len(db_run_info) == 2
        assert db_run_info[0].start is not None
        assert db_run_info[0].end is not None
        assert db_run_info[1].start is not None
        assert db_run_info[1].end is None

    opp.stop()
コード例 #21
0
def opp_recorder():
    """Open Peer Power fixture with in-memory recorder."""
    opp = get_test_open_peer_power()

    def setup_recorder(config=None):
        """Set up with params."""
        init_recorder_component(opp, config)
        opp.start()
        opp.block_till_done()
        opp.data[DATA_INSTANCE].block_till_done()
        return opp

    yield setup_recorder
    opp.stop()
コード例 #22
0
 def setUp(self):  # pylint: disable=invalid-name
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     self.mailer = MockSMTP(
         "localhost",
         25,
         5,
         "*****@*****.**",
         1,
         "testuser",
         "testpass",
         ["*****@*****.**", "*****@*****.**"],
         "Open Peer Power",
         0,
     )
コード例 #23
0
ファイル: test_upnp.py プロジェクト: OpenPeerPower/core
    def setUpClass(cls):
        """Set up the class."""
        cls.opp = opp = get_test_open_peer_power()

        setup.setup_component(
            opp,
            emulated_hue.DOMAIN,
            {
                emulated_hue.DOMAIN: {
                    emulated_hue.CONF_LISTEN_PORT: BRIDGE_SERVER_PORT
                }
            },
        )

        cls.opp.start()
コード例 #24
0
 def setup_method(self, method):
     """Set up things to be run when tests are started."""
     self.opp = get_test_open_peer_power()
     self.values = [17, 20, 15.2, 5, 3.8, 9.2, 6.7, 14, 6]
     self.count = len(self.values)
     self.min = min(self.values)
     self.max = max(self.values)
     self.total = sum(self.values)
     self.mean = round(sum(self.values) / len(self.values), 2)
     self.median = round(statistics.median(self.values), 2)
     self.deviation = round(statistics.stdev(self.values), 2)
     self.variance = round(statistics.variance(self.values), 2)
     self.change = round(self.values[-1] - self.values[0], 2)
     self.average_change = round(self.change / (len(self.values) - 1), 2)
     self.change_rate = round(self.change / (60 * (self.count - 1)), 2)
     self.addCleanup(self.opp.stop)
コード例 #25
0
ファイル: test_tts.py プロジェクト: OpenPeerPower/core
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()

        asyncio.run_coroutine_threadsafe(
            async_process_op_core_config(
                self.opp, {"internal_url": "http://example.local:8123"}),
            self.opp.loop,
        )

        self.url = "https://api.voicerss.org/"
        self.form_data = {
            "key": "1234567xx",
            "hl": "en-us",
            "c": "MP3",
            "f": "8khz_8bit_mono",
            "src": "I person is on front of your door.",
        }
コード例 #26
0
def test_setup_scanner_timeout():
    """Test setup_scanner failure from timeout."""
    opp = get_test_open_peer_power()
    opp.start()

    config = {
        "username": TEST_CALLSIGN,
        "password": TEST_PASSWORD,
        "host": "localhost",
        "timeout": 0.01,
        "callsigns": ["XX0FOO*", "YY0BAR-1"],
    }

    see = Mock()
    try:
        assert not device_tracker.setup_scanner(opp, config, see)
    finally:
        opp.stop()
コード例 #27
0
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()

        config = {
            ip.DOMAIN: {
                "platform": "openalpr_cloud",
                "source": {
                    "entity_id": "camera.demo_camera",
                    "name": "test local"
                },
                "region": "eu",
                "api_key": "sk_abcxyz123456",
            },
            "camera": {
                "platform": "demo"
            },
        }

        with patch(
                "openpeerpower.components.openalpr_cloud.image_processing."
                "OpenAlprCloudEntity.should_poll",
                new_callable=PropertyMock(return_value=False),
        ):
            setup_component(self.opp, ip.DOMAIN, config)
            self.opp.block_till_done()

        self.alpr_events = []

        @callback
        def mock_alpr_event(event):
            """Mock event."""
            self.alpr_events.append(event)

        self.opp.bus.listen("image_processing.found_plate", mock_alpr_event)

        self.params = {
            "secret_key": "sk_abcxyz123456",
            "tasks": "plate",
            "return_image": 0,
            "country": "eu",
        }
コード例 #28
0
    def setUp(self):  # pylint: disable=invalid-name
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()
        test_light = getattr(self.opp.components, "test.light")
        test_light.init()

        assert setup_component(self.opp, light.DOMAIN,
                               {light.DOMAIN: {
                                   "platform": "test"
                               }})

        self.light_1, self.light_2 = test_light.ENTITIES[0:2]

        common_light.turn_off(self.opp,
                              [self.light_1.entity_id, self.light_2.entity_id])

        self.opp.block_till_done()

        assert not self.light_1.is_on
        assert not self.light_2.is_on
コード例 #29
0
ファイル: conftest.py プロジェクト: OpenPeerPower/core
def opp_recorder(enable_statistics):
    """Open Peer Power fixture with in-memory recorder."""
    opp = get_test_open_peer_power()
    stats = recorder.Recorder.async_hourly_statistics if enable_statistics else None
    with patch(
        "openpeerpower.components.recorder.Recorder.async_hourly_statistics",
        side_effect=stats,
        autospec=True,
    ):

        def setup_recorder(config=None):
            """Set up with params."""
            init_recorder_component(opp, config)
            opp.start()
            opp.block_till_done()
            opp.data[recorder.DATA_INSTANCE].block_till_done()
            return opp

        yield setup_recorder
        opp.stop()
コード例 #30
0
ファイル: test_tts.py プロジェクト: OpenPeerPower/core
    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.opp = get_test_open_peer_power()

        asyncio.run_coroutine_threadsafe(
            async_process_op_core_config(
                self.opp, {"internal_url": "http://example.local:8123"}),
            self.opp.loop,
        )

        self.host = "localhost"
        self.port = 59125
        self.params = {
            "INPUT_TEXT": "OpenPeerPower",
            "INPUT_TYPE": "TEXT",
            "OUTPUT_TYPE": "AUDIO",
            "LOCALE": "en_US",
            "AUDIO": "WAVE_FILE",
            "VOICE": "cmu-slt-hsmm",
        }