Пример #1
0
 async def test_test_connection_client_error(self):
     """Test the test connection method with a client error."""
     with patch.object(
             pyinsteon.protocol.http_reader_writer,
             "ClientSession",
             partial(create_mock_http_client, exception_error=ClientError),
     ):
         http_reader_writer = HttpReaderWriter(None)
         result = await http_reader_writer.async_test_connection("some_url")
         assert not result
Пример #2
0
 async def test_writer_status_errors(self):
     """Test the test connection method for status errors."""
     for error in [401, 404, 505, 999]:
         with patch.object(
                 pyinsteon.protocol.http_reader_writer,
                 "ClientSession",
                 partial(create_mock_http_client, status=error),
         ):
             http_reader_writer = HttpReaderWriter(None)
             result = await http_reader_writer.async_write("some_url")
             assert result == error
Пример #3
0
    async def test_test_connection_success(self):
        """Test the test connection method success."""

        with patch.object(
                pyinsteon.protocol.http_reader_writer,
                "ClientSession",
                create_mock_http_client,
        ):
            http_reader_writer = HttpReaderWriter(None)
            result = await http_reader_writer.async_test_connection("some_url")
            assert result
Пример #4
0
 async def test_reader_client_error(self):
     """Test the test connection method with a client error."""
     with patch.object(
             pyinsteon.protocol.http_reader_writer,
             "ClientSession",
             partial(create_mock_http_client, exception_error=ClientError),
     ):
         http_reader_writer = HttpReaderWriter(None)
         try:
             await http_reader_writer.async_read("some_url")
             assert False
         except HubConnectionException:
             assert True
Пример #5
0
 async def test_reader(self):
     """Test the HTTP reader method."""
     test_cases = await import_commands(FILE)
     with patch.object(
             pyinsteon.protocol.http_reader_writer,
             "ClientSession",
             create_mock_http_client,
     ):
         http_reader_writer = HttpReaderWriter(None)
         for test_case in test_cases:
             buffer = test_cases[test_case]["buffer"]
             MockHttpResponse.buffer = buffer
             expected = test_cases[test_case]["expected"]
             result = await http_reader_writer.async_read("some_url")
             try:
                 assert result == expected
             except AssertionError:
                 raise AssertionError(
                     f"Failed in test {test_case}: result={result}")