Skip to content

Commit

Permalink
fix(unittes): change unittest since due to submitter fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
giangbui committed Mar 23, 2018
1 parent 56f9af1 commit 7595ebf
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 131 deletions.
2 changes: 1 addition & 1 deletion peregrine/dev_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

# API server
PEREGRINE_HOST = os.getenv("PEREGRINE_HOST", "localhost")
PEREGRINE_PORT = int(os.getenv("PEREGRINE_PORT", "5000"))
PEREGRINE_PORT = int(os.getenv("PEREGRINE_PORT", "5555"))

# FLASK_SECRET_KEY should be set to a secure random string with an appropriate
# length; 50 is reasonable. For the random generation to be secure, use
Expand Down
87 changes: 80 additions & 7 deletions peregrine/resources/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import graphql



def get_open_project_ids():
"""
List project ids corresponding to projects with ``availability_type ==
Expand Down Expand Up @@ -65,6 +66,53 @@ def set_read_access_projects():
flask.g.read_access_projects = flask.g.user.get_project_ids('read')
open_project_ids = get_open_project_ids()
flask.g.read_access_projects.extend(open_project_ids)

# @peregrine.blueprints.blueprint.route('/graphql', methods=['POST'])
# @peregrine.auth.set_global_user
# def root_graphql_query():
# """
# Run a graphql query.
# """
# # Short circuit if user is not recognized. Make sure that the list of
# # projects that the user has read access to is set.

# print("root_graphql_query. Run a graphql query in resource/submission/__init__")
# try:
# set_read_access_projects()
# except peregrine.errors.AuthError:
# data = flask.jsonify({'data': {}, 'errors': ['Unauthorized query.']})
# return data, 403
# payload = peregrine.utils.parse_request_json()
# query = payload.get('query')
# export_format = payload.get('format')
# bag_path = payload.get('path')
# variables, errors = peregrine.utils.get_variables(payload)
# if errors:
# return flask.jsonify({'data': None, 'errors': errors}), 400
# return_data = graphql.execute_query(query, variables)

# import pdb; pdb.set_trace()

# if export_format == 'bdbag':
# # if peregrine.utils.contain_node_with_category(return_data,'data_file') == False:
# # return flask.jsonify({ 'errors': 'No data_file node'}), 400

# import pdb; pdb.set_trace()

# res = peregrine.utils.json2tbl(json.loads(json.dumps(return_data)),'', "_" )
# bag_info = {'organization': 'CDIS',
# 'data_type': 'TOPMed',
# 'date_created': datetime.date.today().isoformat()}
# args = dict(
# bag_path=bag_path,
# bag_info=bag_info,
# payload=res)
# peregrine.utils.create_bdbag(**args) # bag is a compressed file
# return flask.jsonify({'data': res}), 200
# else:
# return peregrine.utils.jsonify_check_errors(return_data)
# #return flask.jsonify({'data': 'Format not supported !!!'}), 400

@peregrine.blueprints.blueprint.route('/graphql', methods=['POST'])
@peregrine.auth.set_global_user
def root_graphql_query():
Expand All @@ -74,7 +122,6 @@ def root_graphql_query():
# Short circuit if user is not recognized. Make sure that the list of
# projects that the user has read access to is set.

import pdb; pdb.set_trace()
print("root_graphql_query. Run a graphql query in resource/submission/__init__")
try:
set_read_access_projects()
Expand All @@ -83,12 +130,41 @@ def root_graphql_query():
return data, 403
payload = peregrine.utils.parse_request_json()
query = payload.get('query')
export_format = payload.get('format')
bag_path = payload.get('path')
variables, errors = peregrine.utils.get_variables(payload)
if errors:
return flask.jsonify({'data': None, 'errors': errors}), 400
return peregrine.utils.jsonify_check_errors(
graphql.execute_query(query, variables)
)

return_data= graphql.execute_query(query, variables)
import pdb; pdb.set_trace()
return_data = peregrine.utils.jsonify_check_errors(return_data)

data, error = return_data


if export_format == 'bdbag':
# if peregrine.utils.contain_node_with_category(return_data,'data_file') == False:
# return flask.jsonify({ 'errors': 'No data_file node'}), 400


import pdb; pdb.set_trace()

res = peregrine.utils.json2tbl(data.json),'', "_" )

import pdb; pdb.set_trace()
bag_info = {'organization': 'CDIS',
'data_type': 'TOPMed',
'date_created': datetime.date.today().isoformat()}
args = dict(
bag_path=bag_path,
bag_info=bag_info,
payload=res)
peregrine.utils.create_bdbag(**args) # bag is a compressed file
return flask.jsonify({'data': res}), 200
else:
return return_data
#return flask.jsonify({'data': 'Format not supported !!!'}), 400


def get_introspection_query():
Expand Down Expand Up @@ -129,13 +205,10 @@ def get_manifest():
description: Filters to be applied when generating the manifest
:return: A manifest that the user can use to download the files in there
"""
import pdb; pdb.set_trace()
payload = peregrine.utils.parse_request_json()
export_data = payload.get('export_data')
bag_path = payload.get('bag_path')

import pdb; pdb.set_trace()

if(bag_path is None):
return flask.jsonify({'bag_path': None, 'errors': 'bag_path is required!!!'}), 400

Expand Down
3 changes: 2 additions & 1 deletion peregrine/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .payload import get_variables,jsonify_check_errors,parse_request_json,get_keys,contain_node_with_category
from .pybdbag import create_bdbag
from .scheduling import AsyncPool
from .json2csv import flatten_obj,json2tbl
from .json2csv import flatten_obj,json2tbl, to_csv
from .response import format_response
1 change: 1 addition & 0 deletions peregrine/utils/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SUCCESS_STATE,
)

from peregrine.resources.submission.graphql.node import get_fields

def get_external_proxies():
"""Get any custom proxies set in the config.
Expand Down
15 changes: 4 additions & 11 deletions peregrine/utils/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import os
from cdispyutils.log import get_handler
from flask import Response, Markup
from peregrine import VERSION
from peregrine.utils.json2csv import to_csv

defusedxml.defuse_stdlib()
#defusedxml.defuse_stdlib()
logger = logging.getLogger("peregrine.utils.response")
logger.addHandler(get_handler())

Expand All @@ -30,13 +29,6 @@ def get_data_release():
return 'Data Release 3.0 - September 21, 2016'


def get_status():
status = {'status': 'OK', 'version': 1, 'tag': VERSION, 'data_release': get_data_release()}
if COMMIT:
status["commit"] = COMMIT
return status


def tryToInt(value):
new_value = value
try:
Expand Down Expand Up @@ -125,6 +117,7 @@ def format_response(request_options, data, mimetype):
Returns:
A Flask Response object, with the data formatted as specified and the Content-Type set
"""
import pdb; pdb.set_trace()
if (request_options.get('attachment', '').lower() == 'true' or
"text/csv" in mimetype or
"text/tab-separated-values" in mimetype):
Expand Down Expand Up @@ -152,8 +145,8 @@ def format_response(request_options, data, mimetype):
data = to_json(request_options, data)

response = Response(data, mimetype=mimetype)
for key, value in get_status().iteritems():
response.headers.extend({'X-GDC-{}'.format(key): value})
# for key, value in get_status().iteritems():
# response.headers.extend({'X-GDC-{}'.format(key): value})

return response

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bdbag==1.2.3
defusedxml==0.5.0
scipy==0.18.1
SurvivalPy==1.0.2
Expand Down
Loading

0 comments on commit 7595ebf

Please sign in to comment.