コード例 #1
0
def test_client_list_bad():
    list_response = "FOO"
    with patch('compoundpi.client.CompoundPiServerList.transact') as l, \
            patch('compoundpi.client.CompoundPiDownloadServer'):
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): list_response,
            compoundpi.client.IPv4Address('192.168.0.2'): list_response,
            }
        client = compoundpi.client.CompoundPiClient()
        with pytest.raises(CompoundPiTransactionFailed) as excinfo:
            client.list()
            assert len(excinfo.value.errors) == 2
            assert isinstance(excinfo.value.errors[0], CompoundPiInvalidResponse)
            assert isinstance(excinfo.value.errors[1], CompoundPiInvalidResponse)
コード例 #2
0
def test_client_list_ok():
    list_response = """\
IMAGE,0,1000.0,1234567
VIDEO,1,2000.0,2345678
"""
    list_struct = [
        compoundpi.client.CompoundPiFile('IMAGE', 0,
                                         dt.datetime.fromtimestamp(1000.0),
                                         1234567),
        compoundpi.client.CompoundPiFile('VIDEO', 1,
                                         dt.datetime.fromtimestamp(2000.0),
                                         2345678),
    ]
    with patch('compoundpi.client.CompoundPiServerList.transact') as l, \
            patch('compoundpi.client.CompoundPiDownloadServer'):
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): list_response,
            compoundpi.client.IPv4Address('192.168.0.2'): list_response,
        }
        client = compoundpi.client.CompoundPiClient()
        assert client.list() == {
            compoundpi.client.IPv4Address('192.168.0.1'): list_struct,
            compoundpi.client.IPv4Address('192.168.0.2'): list_struct,
        }
        l.assert_called_once_with('LIST', None)
コード例 #3
0
def test_client_list_ok():
    list_response = """\
IMAGE,0,1000.0,1234567
VIDEO,1,2000.0,2345678
"""
    list_struct = [
        compoundpi.client.CompoundPiFile('IMAGE', 0, dt.datetime.fromtimestamp(1000.0), 1234567),
        compoundpi.client.CompoundPiFile('VIDEO', 1, dt.datetime.fromtimestamp(2000.0), 2345678),
        ]
    with patch('compoundpi.client.CompoundPiServerList.transact') as l, \
            patch('compoundpi.client.CompoundPiDownloadServer'):
        l.return_value = {
            compoundpi.client.IPv4Address('192.168.0.1'): list_response,
            compoundpi.client.IPv4Address('192.168.0.2'): list_response,
            }
        client = compoundpi.client.CompoundPiClient()
        assert client.list() == {
            compoundpi.client.IPv4Address('192.168.0.1'): list_struct,
            compoundpi.client.IPv4Address('192.168.0.2'): list_struct,
            }
        l.assert_called_once_with('LIST', None)