a Fmg!@s8ddlZddlmmZddlZddlmZddlm Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlmZejddZddZd d Zd d Zd dZddZddZddZddZddZddZddZ ddZ!dd Z"d!d"Z#d#d$Z$d%d&Z%d'd(Z&d)d*Z'd+d,Z(d-d.Z)dS)/N)app)Config) HTTPBasicAuthcCsdtjd<tS)NTZTESTING)rconfigZ test_clientrr=/home/cmiss/Jenkins/workspace/SPARC-API-DEV/tests/test_api.pyclients rc Cs0d}|d|d}|j}d}||k}|std|fd||fdtvsVt|r`t|ndt|t|d}d d |i}tt |d}}}d }|j }||v} | s td | fd ||ft|dtvst|rt|ndt|d}d d |i}tt |d}} }dS)Nz0217/files/derivative/brainstem_pig_metadata.json /s3-resource/'?s3BucketName=prd-sparc-discover50-use1==z3%(py2)s {%(py2)s = %(py0)s.status_code } == %(py5)srpy0py2py5assert %(py7)spy7smedullainz,%(py1)s in %(py5)s {%(py5)s = %(py3)s.data }py1py3r get status_code @pytest_ar_call_reprcompare @py_builtinslocals_should_repr_global_name _safereprAssertionError_format_explanationdata rZ small_s3_filer @py_assert1 @py_assert4 @py_assert3 @py_format6 @py_format8 @py_assert0 @py_assert2rrr#test_direct_download_url_small_filesr0c Cs0d}|d|d}|j}d}||k}|std|fd||fdtvsVt|r`t|ndt|t|d}d d |i}tt |d}}}d }|j }||v} | s td | fd ||ft|dtvst|rt|ndt|d}d d |i}tt |d}} }dS)Nz3307%2Ffiles%2Fderivative%2Fhuman_body_metadata.jsonr r r r rrrrrscolonrrrr) rZ new_s3_filerr)r*r+r,r-r.r/rrr(test_direct_download_url_new_bucket_filesr1c Cs0d}|d|d}|j}d}||k}|std|fd||fdtvsVt|r`t|ndt|t|d}d d |i}tt |d}}}d }|j }||v} | s td | fd ||ft|dtvst|rt|ndt|d}d d |i}tt |d}} }dS)Nz795/files/derivative%2FcolonHuman_Layout1_thumbnail.jpegr r r r rrrrrsrrrrr(rrr"test_direct_download_url_thumbnail&sr2cCsd}|d|d}|j}d}||k}|std|fd||fdtvsVt|r`t|ndt|t|d}d d |i}tt |d}}}dS) Nz95/files/?encodeBase64=truer r r )!=)z3%(py2)s {%(py2)s = %(py0)s.status_code } != %(py5)srrrr rrrr r!r"r#r$r%r&)rZincorrect_pathrr)r*r+r,r-rrr#test_direct_download_incorrect_path-sr5cCs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}dS) Nr r rrrrrr4rrr)r*r+r,r-rrrtest_direct_download_empty_path3s r8c Csfd}|d|}|j}d}||k}|std|fd||fdtvsTt|r^t|ndt|t|d}dd |i}tt |d}}}d }|j }|} | j } | } || v} | sJtd | fd || ft|dtvst|rt|ndt|t| t| t| d } dd| i}tt |d}} }} } } dS)NzW61%2Ffiles%2Fprimary%2Fsub-44%2Fsam-1%2Fmicroscopy%2Fsub-44sam-1C44-1Slide2p2MT_10x.nd2r ir rrrrrzFile too big to downloadr)z|%(py1)s in %(py11)s {%(py11)s = %(py9)s {%(py9)s = %(py7)s {%(py7)s = %(py5)s {%(py5)s = %(py3)s.get_data }() }.decode }() })rrrrpy9Zpy11zassert %(py13)sZpy13) rrrr r!r"r#r$r%r&get_datadecode)rZ large_s3_filerr)r*r+r,r-r. @py_assert6Z @py_assert8Z @py_assert10r/Z @py_format12Z @py_format14rrr#test_direct_download_url_large_file9sr=c Csd}d}|d|}|j}d}||k}|std|fd||fdtvsXt|rbt|ndt|t|d}d d |i}tt |d}}}| d } | |k} | std| fd | |ft| d tvst|rt|nd d} dd| i}tt |d} } |dd}|j}d}||k}|std|fd||fdtvszt|rt|ndt|t|d}d d |i}tt |d}}}dS)Niznih-data-portal@blackfynn.comz/get_owner_email/r r rrrrremail)z%(py1)s == %(py3)sportal_user_emailrrassert %(py5)sr?Br6 rrrr r!r"r#r$r%r&get_json) rZportal_user_idr?rr)r*r+r,r-r.r/ @py_format4rrrtest_get_owner_emailAsrFcCs>d}|dd}|j}d}||k}|std|fd||fdtvsTt|r^t|ndt|t|d}d d |i}tt |d}}}|d|}|j}d }||k}|s.td|fd||fdtvst|rt|ndt|t|d}d d |i}tt |d}}}dS) NZ OT2OD025340z /project/rBr6r rrrrrr r4)rZportal_project_idrr)r*r+r,r-rrrtest_get_datasets_by_projectNs rGcCs0ddddi}|jdid}|j}d}||k}|std|fd ||fd tvs\t|rft|nd t|t|d }d d |i}tt |d}}}|jd|d}|j}d}||k}|s6td|fd ||fd tvst|rt|nd t|t|d }d d |i}tt |d}}}d}|j }|} || v} | std| fd|| ft|d tvst|rt|nd t|t| d}dd|i} tt | d}} }} |jd| d}|j}d}||k}|sztd|fd ||fd tvsHere is a small text but not lorem ipsumr2)rcrdr r3task_idz%https://www.wrike.com/api/v4/tasks/{}Z AuthorizationzBearer )urlheadersresp)r[rrr r!r"r#r$r%r&rDformatrZ WRIKE_TOKENrequestsdelete)rrr)r*r+r,r-rerfrSrgrhZhedrjrrrtest_create_wrike_tasks rncCsd}d}d}||}d}tt}||||}tjtjd|dtjd }t | } |j ||dd| t|d d } | j} d } | | k} | s td | fd | | fdtvst| rt| ndt| t| d}dd|i}tt|d} } } dS)NZPOSTz/hubspot_webhookzhttp://localhostzH[{"subscriptionType":"contact.propertyChange","objectId":"83944215465"}]zutf-8)keymsgZ digestmodzapplication/jsonZv3)z Content-TypezX-HubSpot-Signature-VersionzX-Hubspot-Signature-v3zX-HubSpot-Request-Timestamp)rLrir rresponserrr)inttimehmacnewrZHUBSPOT_CLIENT_SECRETencodehashlibZsha256digestbase64 b64encoder;r[strrrr r!r"r#r$r%r&)rZ http_methodZendpointZbase_urlZfull_urlZ mock_bodyZvalid_timestampZ data_to_sign signatureZmock_signaturerrr)r*r+r,r-rrrtest_hubspot_webhooks.     r~csP|jdid}|j}d}||k}|std|fd||fdtvsNt|rXt|ndt|t|d}dd |i}tt |d}}}t j d fd d t d D}d fdd t dD}d||} |jd| dddd} | j}d}||k}|s|td|fd||fdtvs>t| rHt| ndt|t|d}dd |i}tt |d}}}| } | d} d| } tdtj}tj| |d}|j}d}||k}|s@td|fd||fdtvst|r t|ndt|t|d}dd |i}tt |d}}}dS)Nz/mailchimp_subscriberKrMr rrrrrc3s|]}tVqdSNrandomchoice.0ilettersrr z.test_subscribe_to_mailchimp..c3s|]}tVqdSrrrrrrrrz {}@{}.comTestZUser) email_addressZ first_name last_namer reidzVhttps://us2.api.mailchimp.com/3.0/lists/c81a347bd8/members/{}/actions/delete-permanentZAnyUser)rhauthrqrj)r[rrr r!r"r#r$r%r&stringascii_lowercasejoinrangerkrDrrZMAILCHIMP_API_KEYrl)rrr)r*r+r,r-r>domainrrerSZ member_hashrhrrjrrrtest_subscribe_to_mailchimps"   rc Cs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}| }d }||v} | std | fd ||ft|d tvst|rt|nd d } dd| i}tt |d}} dS)Nz/get_osparc_datar r rrrrrZ file_viewersrrR osparc_datar@rArrC) rrr)r*r+r,r-rr.r/rErrrtest_osparc_viewerss rcCs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}dS) Nz/sim/dataset/0r6r rrrrrr4r7rrrtest_sim_datasets rc Cs|jdddid}|j}d}||k}|std|fd||fdtvsRt|r\t|ndt|t|d }d d |i}tt |d}}}| }|d }d }||k} | std| fd||ft|t|d} dd| i} tt | d}} }dS)Nz/onto_term_lookuptermz-http://purl.obolibrary.org/obo/NCBITaxon_9606)Z query_stringr r rrrrrlabelZHumanrTrUrWrXrC) rrr)r*r+r,r-Z json_datar.r/r]r^rrrtest_onto_term_lookupsrcCs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}dS) Nz/simulation_ui_file/137r6r rrrrrr4r7rrr$test_non_existing_simulation_ui_files rc Cs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}| d d d d }d }||k}|std|fd||ft|t|d} dd| i} tt | d}}}dS)Nz/simulation_ui_file/135r r rrrrr simulationsolversrnamezsimcore/services/comp/opencorrTrUrWrXrC rrr)r*r+r,r-r.r/r]r^rrr%test_simulation_ui_file_old_s3_buckets rc Cs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}| d d d d }d }||k}|std|fd||ft|t|d} dd| i} tt | d}}}dS)Nz/simulation_ui_file/308r r rrrrrrrrrz*simcore/services/comp/kember-cardiac-modelrTrUrWrXrCrrrr%test_simulation_ui_file_new_s3_buckets rcCs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}| }d }||v} | std | fd ||ft|d tvst|rt|nd d } dd| i}tt |d}} |d }t |}|t k} | std| fd|t fdtvsbtt rltt ndt|t|dtvstt rtt ndd} dd| i} tt | d}}} dS)Nz"/get_featured_datasets_identifiersr r rrrrrZ identifiersrrRrLr@rAr)z0%(py4)s {%(py4)s = %(py0)s(%(py2)s) } == %(py6)srIlist)rrrVrXzassert %(py8)sZpy8) rrrr r!r"r#r$r%r&rDrIr)rrr)r*r+r,r-rLr.r/rEZ @py_assert5r^Z @py_format9rrrtest_get_featured_datasetss  zr)*builtinsr!_pytest.assertion.rewrite assertionrewriterpytestrZ app.configrrlrrrurxrzrtrLZ requests.authrfixturerr0r1r2r5r8r=rFrGr_rbrnr~rrrrrrrrrrrrsB"      "