async def test_init(self) -> None:
        c = client.HTTPClientV3('localhost')

        assert c.session is not None
        assert c.host == 'localhost'
        assert c.port == 5000
        assert c.base == 'http://localhost:5000'
        assert c.url == 'http://localhost:5000/v3'
    async def test_async_context(self) -> None:
        c = client.HTTPClientV3('localhost')
        assert c.session.closed is False

        async with c:
            pass

        assert c.session.closed is True
    async def test_make_request_error(self) -> None:
        # The request will return a connection error (an instance of
        # RequestException) if the fetched URL doesn't hit a match.
        c = client.HTTPClientV3('localhost')

        with pytest.raises(errors.SynseError):
            await c.make_request(
                method='GET',
                url='http://localhost:5000/v3/bar',
            )
    async def test_tags_params(self, ns, ids, expected):
        with asynctest.patch('synse.client.HTTPClientV3.make_request') as mock_request:
            mock_request.returns = []

            c = client.HTTPClientV3('localhost')
            _ = await c.tags(ns=ns, ids=ids)

        mock_request.assert_called_once()
        mock_request.assert_called_with(
            url='http://localhost:5000/v3/tags',
            method='get',
            params=expected,
        )
    async def test_scan_params(self, force, ns, sort, tags, expected):
        with asynctest.patch('synse.client.HTTPClientV3.make_request') as mock_request:
            mock_request.returns = []

            c = client.HTTPClientV3('localhost')
            _ = await c.scan(force=force, ns=ns, sort=sort, tags=tags)

        mock_request.assert_called_once()
        mock_request.assert_called_with(
            url='http://localhost:5000/v3/scan',
            method='get',
            params=expected,
        )
    async def test_read_cache_params(self, start, end, expected):
        async def side_effect(*args, **kwargs):
            for i in range(10):
                yield {}

        with asynctest.patch('synse.client.HTTPClientV3.stream_request') as mock_request:
            mock_request.side_effect = side_effect

            c = client.HTTPClientV3('localhost')
            _ = [x async for x in c.read_cache(start=start, end=end)]

        mock_request.assert_called_once()
        mock_request.assert_called_with(
            url='http://localhost:5000/v3/readcache',
            method='get',
            params=expected,
        )
    async def test_context(self) -> None:
        c = client.HTTPClientV3('localhost')

        with pytest.raises(TypeError):
            with c:
                pass
    async def test_str(self) -> None:
        c = client.HTTPClientV3('localhost')

        assert str(c) == '<Synse HTTP Client (v3): localhost:5000>'
        assert str([c]) == '[<Synse HTTP Client (v3): localhost:5000>]'
Esempio n. 9
0
def test_client_err(cli_err):
    return client.HTTPClientV3(
        host=cli_err.host,
        port=cli_err.port,
        session=cli_err.session,
    )
Esempio n. 10
0
def test_client(cli):
    return client.HTTPClientV3(
        host=cli.host,
        port=cli.port,
        session=cli.session,
    )