X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/13181107ecaeaa92e5d96b05270e56b2d807af39..22f68d307a3229fbf842fba0f61ea0ae0330832b:/sdk/python/tests/test_api.py diff --git a/sdk/python/tests/test_api.py b/sdk/python/tests/test_api.py index 576e47ae3d..9d438e2e03 100644 --- a/sdk/python/tests/test_api.py +++ b/sdk/python/tests/test_api.py @@ -1,14 +1,17 @@ #!/usr/bin/env python import arvados +import collections import httplib2 import json import mimetypes import os import run_test_server +import string import unittest from apiclient import errors as apiclient_errors from apiclient import http as apiclient_http +from arvados.api import OrderedJsonModel from arvados_testutil import fake_httplib2_response @@ -59,11 +62,35 @@ class ArvadosApiClientTest(unittest.TestCase): for index in [0, 1]] self.assertIsNot(*clients) - def test_basic_list(self): - answer = self.api.humans().list( + def test_empty_list(self): + answer = arvados.api('v1').humans().list( filters=[['uuid', 'is', None]]).execute() self.assertEqual(answer['items_available'], len(answer['items'])) + def test_nonempty_list(self): + answer = arvados.api('v1').collections().list().execute() + self.assertNotEqual(0, answer['items_available']) + self.assertNotEqual(0, len(answer['items'])) + + def test_timestamp_inequality_filter(self): + api = arvados.api('v1') + new_item = api.specimens().create(body={}).execute() + for operator, should_include in [ + ['<', False], ['>', False], + ['<=', True], ['>=', True], ['=', True]]: + response = api.specimens().list(filters=[ + ['created_at', operator, new_item['created_at']], + # Also filter by uuid to ensure (if it matches) it's on page 0 + ['uuid', '=', new_item['uuid']]]).execute() + uuids = [item['uuid'] for item in response['items']] + did_include = new_item['uuid'] in uuids + self.assertEqual( + did_include, should_include, + "'%s %s' filter should%s have matched '%s'" % ( + operator, new_item['created_at'], + ('' if should_include else ' not'), + new_item['created_at'])) + def test_exceptions_include_errors(self): with self.assertRaises(apiclient_errors.HttpError) as err_ctx: self.api.humans().get(uuid='xyz-xyz-abcdef').execute() @@ -76,6 +103,28 @@ class ArvadosApiClientTest(unittest.TestCase): self.api.humans().delete(uuid='xyz-xyz-abcdef').execute() self.assertIn("500", str(err_ctx.exception)) + def test_request_too_large(self): + api = arvados.api('v1') + maxsize = api._rootDesc.get('maxRequestSize', 0) + with self.assertRaises(apiclient_errors.MediaUploadSizeError): + text = "X" * maxsize + arvados.api('v1').collections().create(body={"manifest_text": text}).execute() + + def test_ordered_json_model(self): + mock_responses = { + 'arvados.humans.get': (None, json.dumps(collections.OrderedDict( + (c, int(c, 16)) for c in string.hexdigits))), + } + req_builder = apiclient_http.RequestMockBuilder(mock_responses) + api = arvados.api('v1', + host=os.environ['ARVADOS_API_HOST'], + token='discovery-doc-only-no-token-needed', + insecure=True, + requestBuilder=req_builder, + model=OrderedJsonModel()) + result = api.humans().get(uuid='test').execute() + self.assertEqual(string.hexdigits, ''.join(result.keys())) + if __name__ == '__main__': unittest.main()