Esempio n. 1
0
def test_vxuserapi_samples_iter():
    kwargs = dict(count=4,
                  offset=2,
                  md5=None,
                  sha1="sha1",
                  sha256=None,
                  format_name=None,
                  format_group_name=None)
    request = mock.Mock(return_value=[{"id": 23}, {"id": 42}])
    with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request",
                    new=request):
        api = VxCubeApi(base_url="http://test", version=2.0)
        samples = list(api.samples_iter(**kwargs))

        assert isinstance(samples, list)
        assert len(samples) == 2
        assert samples[0].id == 23
        assert samples[0]._raw_api is api._raw_api
        assert samples[1].id == 42
        assert samples[1]._raw_api is api._raw_api

    request.assert_called_with(method="get",
                               url="http://test/api-2.0/samples",
                               params={},
                               headers={},
                               json={
                                   "count": 100,
                                   "offset": 2,
                                   "sha1": "sha1"
                               })
Esempio n. 2
0
def main():
    # Create VxCubeApi
    api = VxCubeApi(api_key=API_KEY, version=2.0)

    sha256 = set()
    # Use samples_iter of VxCubeApi
    for sample in api.samples_iter():
        sha256.add(sample.sha256)

    # Use iterator
    for sample in iterator(api.samples, count_per_request=100, item_key=None):
        assert sample.sha256 in sha256

    # Use all_items
    all_sha256 = {
        s.sha256
        for s in all_items(api.samples, count_per_request=100, item_key=None)
    }
    assert sha256 == all_sha256
    print(sha256)