-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Because the DCP Query Service uses Swagger 3.0/OpenAPI 3.0, this also introduces OpenAPI 3.0 compatibility in the Swagger Client.
- Loading branch information
Showing
6 changed files
with
101 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
DCP Query Service | ||
***************** | ||
""" | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from ..util import SwaggerClient | ||
|
||
|
||
class DCPQueryClient(SwaggerClient): | ||
""" | ||
Client for the DCP Query Service API. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import sys | ||
|
||
from . import DCPQueryClient | ||
|
||
def add_commands(subparsers, help_menu=False): | ||
query_parser = subparsers.add_parser('query', help="Interact with the HCA DCP Query Service") | ||
|
||
def help(args): | ||
query_parser.print_help() | ||
|
||
if sys.version_info >= (2, 7, 9): # See https://bugs.python.org/issue9351 | ||
query_parser.set_defaults(entry_point=help) | ||
query_subparsers = query_parser.add_subparsers() | ||
query_cli_client = DCPQueryClient() | ||
query_cli_client.build_argparse_subparsers(query_subparsers, help_menu=help_menu) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os, sys, unittest, logging | ||
|
||
from hca.query import DCPQueryClient | ||
from hca.util.exceptions import SwaggerAPIException | ||
|
||
logging.basicConfig() | ||
|
||
|
||
class TestDCPQueryClient(unittest.TestCase): | ||
def setUp(self): | ||
self.client = DCPQueryClient() | ||
|
||
def test_dcpquery_client(self): | ||
query = "select count(*) from files" | ||
res = self.client.post_query(query=query) | ||
self.assertEqual(res["query"], query) | ||
self.assertGreater(res["results"][0]["count"], 0) | ||
|
||
invalid_queries = ["select count(*) from nonexistent_table", "*", "", None] | ||
for query in invalid_queries: | ||
with self.assertRaises(SwaggerAPIException): | ||
self.client.post_query(query=query) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |