Skip to content

Commit

Permalink
download tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinDo committed Aug 21, 2024
1 parent 08a2e67 commit 0bab674
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/frontend_celery/webapp/download/download_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,30 @@ def get_vcf(variants_oi, conn, worker=get_variant_vcf_line, check_vcf=True):
return buffer, status, "", ""


import time
def test_large_download():
for i in range(50):
yield str(i).encode()
print(i)
time.sleep(1)



def get_vcf_stream(variants_oi, conn, worker=get_variant_vcf_line):
for id in variants_oi:
info_headers, variant_vcf = worker(id, conn)
yield variant_vcf
#all_variant_vcf_lines.append(variant_vcf)
#final_info_headers = merge_info_headers(final_info_headers, info_headers)

#printable_info_headers = list(final_info_headers.values())
#printable_info_headers.sort()
#functions.write_vcf_header(printable_info_headers, lambda l: yield_something(l.encode()), tail='\n')


def yield_something(val):
yield val



############################################################
Expand Down
27 changes: 27 additions & 0 deletions src/frontend_celery/webapp/download/download_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ def variant_list():
return send_file(vcf_file_buffer, as_attachment=True, download_name=download_file_name, mimetype="text/vcf")


from flask import Response, stream_with_context
@download_blueprint.route('/download/test')
@require_permission(["admin_resources"])
def download_test():
return Response(
stream_with_context(download_functions.test_large_download()),
headers={'Content-Disposition': 'attachment; filename=test.txt'}
)

@download_blueprint.route('/download/test_vcf')
@require_permission(["admin_resources"])
def download_test_vcf():
conn = get_connection()

list_id = request.args.get('list_id')
require_valid(list_id, "user_variant_lists", conn)

# check that the logged in user is the owner of this list
require_list_permission(list_id, ['read'], conn)
variant_ids_oi = conn.get_variant_ids_from_list(list_id)

return Response(
stream_with_context(download_functions.get_vcf_stream(variant_ids_oi, conn)),
headers={'Content-Disposition': 'attachment; filename=test.txt'}
)


# listens on get parameter: raw
@download_blueprint.route('/download/vcf/classified')
@require_permission(['read_resources'])
Expand Down

0 comments on commit 0bab674

Please sign in to comment.