def test_17_get_abstract_bad_client_id_func(self): print("Test bad client ID...error expected.") full_URL = base_plus_endpoint_encoded( f'/v2/Documents/Abstracts/IFP.017.0240A?similarcount=4') #response = requests.get(full_URL, headers={}) #r = response.json() #response_info = r["documents"]["responseInfo"] #response_set = r["documents"]["responseSet"] #assert(response_info["count"] == 1) #print (response_set) response = requests.get(full_URL, headers=no_client_headers) r = response.json() print(r) #response_info = r["documents"]["responseInfo"] #response_set = r["documents"]["responseSet"] assert (response.status_code == 428)
def test_search_advanced6(self): # query for body summaries or appendixes paragraphs containing "asylum" and "house" within the same paragraph and bring back the document info. # note this only applies to Freud SE and GW since paragraphs are only indexed within those. # originally all documents were index that way but now paragraph proximity is simulated via ~25 (within 25 words) instead # the first part: {!parent which="art_level:1"} tells Solr to only bring back the level 1 info (the document info) full_URL = base_plus_endpoint_encoded( '/v2/Database/AdvancedSearch/?advanced_query={!parent which="art_level:1"} parent_tag:(p_body || p_summaries || p_appxs) && para:(asylum house)' ) response = requests.post(full_URL, headers=headers) assert (response.ok == True) r = response.json() #print (r) response_info = r["documentList"]["responseInfo"] response_set = r["documentList"]["responseSet"] assert (response_info["fullCount"] >= 1) print(response_set[0])
def test_001B_get_embargoed_document(self): # Try to return current content, should only return abstract full_URL = base_plus_endpoint_encoded( f"/v2/Documents/Document/AJP.080.0001A/?return_format=XML") response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. assert (response.ok == True) r = response.json() response_info = r["documents"]["responseInfo"] response_set = r["documents"]["responseSet"] assert (response_info["count"] == 1) # should be classified as current content assert ( response_set[0]["accessLimitedClassifiedAsCurrentContent"] == True) # we should not have access assert (response_set[0]["accessLimited"] == True)
def test_002A_get_document_with_hits(self): # test with real client example search_param = "?facetfields=art_year_int,art_views_last12mos,art_cited_5,art_authors,art_lang,art_type,art_sourcetype,art_sourcetitleabbr,glossary_group_terms,art_kwds_str&facetlimit=15&facetmincount=1&abstract=true&highlightlimit=5&synonyms=false&fulltext1=Evenly+Suspended+Attention" search_param_encoded = requests.utils.quote(search_param) full_URL = base_plus_endpoint_encoded(f"/v2/Documents/Document/PAQ.058.0374A/?return_format=XML&search={search_param_encoded}") response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. assert(response.ok == True) r = response.json() response_info = r["documents"]["responseInfo"] response_set = r["documents"]["responseSet"] assert(response_info["count"] == 1) termCount = r["documents"]["responseSet"][0]["termCount"] term = r["documents"]["responseSet"][0]["term"] assert(termCount >= 11) assert (term == "SearchHits(text:(Evenly Suspended Attention))")
def test_13_references_a(self): """ Full references """ full_URL = base_plus_endpoint_encoded( '/v2/Database/Search/?smarttext=Goldberg, E.L. Myers, W.A. Zeifman, I. (1974). Some Observations on Three Interracial Analyses. Int. J. Psycho-Anal., 55:495-500.' ) response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() response_info = r["documentList"]["responseInfo"] response_set = r["documentList"]["responseSet"] print(f'Smarttext: {response_info["description"]}') print(response_info["count"]) assert (response_info["count"] == 1) print(response_set[0])
def test_search_morelike_2a(self): full_URL = base_plus_endpoint_encoded( '/v2/Database/MoreLikeThis/?morelikethis=IJP.078.0335A') response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() response_info = r["documentList"]["responseInfo"] response_set = r["documentList"]["responseSet"] assert response_info[ "count"] == 1, f"Expected Count == 1, Count: {response_info['count']}" first_key = list( response_set[0]["similarityMatch"]["similarDocs"].keys())[0] length = len( list( response_set[0]["similarityMatch"]["similarDocs"].values())[0]) assert length >= 4, f"Expected Values: Count >= 4, First Key: {first_key}, Count: {length}"
def test_1b_facet_art_kwds_multi(self): # Send a request to the API server and store the response. full_URL = base_plus_endpoint_encoded( '/v2/Database/Search/?facetfields=art_kwds_str, art_kwds, terms_highlighted' ) response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() response_info = r["documentList"]["responseInfo"] print(response_info["facetCounts"]["facet_fields"]["art_kwds_str"]) print(response_info["facetCounts"]["facet_fields"]["art_kwds"]) print( response_info["facetCounts"]["facet_fields"]["terms_highlighted"]) assert (response_info["fullCount"] >= 135000) assert (response_info["facetCounts"]["facet_fields"]["art_kwds_str"] ["psychoanalysis"] >= 30)
def test_search_long_para_alt_seems_to_show_solr_misses_one(self): # This produces 0 results on the GVPi server; this result is correct though full_URL = base_plus_endpoint_encoded( '/v2/Database/Search/?sourcecode=AOP&fulltext1="physics%20science%20observations"~90&abstract=True' ) response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() #print (r) response_info = r["documentList"]["responseInfo"] response_set = r["documentList"]["responseSet"] assert ( response_info["count"] == 2 ) # should REALLY be 3. I confirmed all three papers above in test_search_long_para... # not sure why we get 2 here, but set that way for now. TODO print(response_set)
def test01_sitemapreport(self): # Login! sessID, headers, session_info = test_login( username=localsecrets.PADS_TEST_ID2, password=localsecrets.PADS_TEST_PW2) # get temp folder, cross platform tmpf = tempfile.gettempdir() # note api_key is required, but already in headers full_URL = base_plus_endpoint_encoded( f'/v2/Admin/Sitemap/?size=100&max_records=500&path={tmpf}') response = requests.get(full_URL, headers=headers) assert (response.ok == True) # these don't get affected by the level. r = response.json() site_map_index = r["siteMapIndex"] site_map_list = r["siteMapList"] assert (len(site_map_list) == 5)
def test_001A_get_document_with_hits(self): # test with real client example search_param = f"?facetfields=art_year_int,art_views_last12mos,art_cited_5,art_authors,art_lang,art_type,art_sourcetype,art_sourcetitleabbr,glossary_group_terms,art_kwds_str&facetlimit=15&facetmincount=1&highlightlimit=4&synonyms=false&fulltext1={self.search_term}" search_param_encoded = requests.utils.quote(search_param) full_URL = base_plus_endpoint_encoded(f"/v2/Documents/Document/IJP.056.0303A/?return_format=XML&search={search_param_encoded}") response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. assert(response.ok == True) r = response.json() response_info = r["documents"]["responseInfo"] response_set = r["documents"]["responseSet"] assert(response_info["count"] == 1) termCount = r["documents"]["responseSet"][0]["termCount"] term = r["documents"]["responseSet"][0]["term"] print (f"Term: {term} / TermCount: {termCount}") assert (term == f"SearchHits(text:{self.search_term})") assert(termCount > 0)
def test_search_morelike_1a(self): full_URL = base_plus_endpoint_encoded( '/v2/Database/MoreLikeThis/?morelikethis=AOP.016.0171A&similarcount=4' ) response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() # #print (r) response_info = r["documentList"]["responseInfo"] assert (response_info["count"] == 1) response_set = r["documentList"]["responseSet"] similar = response_set[0]["similarityMatch"]["similarDocs"][ "AOP.016.0171A"] for n in similar: print(n) print(f"Similar Count: {len(similar)}") assert (len(similar) == 4)
def test_search_morelike_1a(self): full_URL = base_plus_endpoint_encoded( '/v2/Database/Search/?sourcecode=AOP&fulltext1=mind¶scope=dreams&similarcount=4' ) response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() response_info = r["documentList"]["responseInfo"] response_set = r["documentList"]["responseSet"] assert response_info[ "count"] >= 15, f"Expected Count >= 15, Count: {response_info['count']}" first_key = list( response_set[0]["similarityMatch"]["similarDocs"].keys())[0] length = len( list( response_set[0]["similarityMatch"]["similarDocs"].values())[0]) assert length >= 2, f"Expected Values: Count >= 2, First Key: {first_key}, Count: {length}"
def test_15_get_document_with_similarcount(self): """ Since no login or authorization, should just return abstract """ full_URL = base_plus_endpoint_encoded( f'/v2/Documents/Document/JOAP.063.0667A/?search=?journal=&fulltext1=mother love&sort=citeCount&similarcount=2' ) # local, this works...but fails in the response.py code trying to convert self.status to int. response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. assert (response.ok == True) r = response.json() print(r) response_info = r["documents"]["responseInfo"] response_set = r["documents"]["responseSet"] assert (response_info["count"] == 1) print(response_set)
def test_001D_nonexistent_session(self): search_param = f"?facetfields=art_year_int,art_views_last12mos,art_cited_5,art_authors,art_lang,art_type,art_sourcetype,art_sourcetitleabbr,glossary_group_terms,art_kwds_str&facetlimit=15&facetmincount=1&highlightlimit=4&synonyms=false&fulltext1={self.search_term}" search_param_encoded = requests.utils.quote(search_param) full_URL = base_plus_endpoint_encoded( f"/v2/Documents/Document/IJP.056.0303A/?return_format=XML&search={search_param_encoded}" ) headers = { f"client-session": f"123456789", "client-id": UNIT_TEST_CLIENT_ID, "Content-Type": "application/json", localsecrets.API_KEY_NAME: localsecrets.API_KEY } response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. print(response.status_code) assert (response.status_code == 424) print(response.reason) assert (response.reason == "Failed Dependency")
def test_v2_get_log_level_1(self): levels = { 10: "DEBUG", 20: "INFO", 30: "WARNING", 40: "ERROR", 50: "CRITICAL" } logger = logging.getLogger() # Get root logger curr_level = levels.get(logger.level, str(logger.level)) print(curr_level) # Send a request to the API server and store the response. full_URL = base_plus_endpoint_encoded(f'/v2/Admin/LogLevel') response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. print(response.status_code) assert (response.status_code == 405) # rejected
def test_0_most_cited(self): """ """ print( f"Running: {sys._getframe( ).f_code.co_name} at {datetime.now()}") full_URL = base_plus_endpoint_encoded('/v2/Database/MostCited/') response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. assert (response.ok == True) r = response.json() # print (r) print(f"Count: {r['documentList']['responseInfo']['count']}") print(f"Limit: {r['documentList']['responseInfo']['limit']}") print( f"ReturnedData: {r['documentList']['responseSet'][0]['stat']['art_cited_5']}" ) assert (r['documentList']['responseSet'][0]['stat']['art_cited_5'] >= 15)
def test_0a_pads_tests(self): # Login to PaDS with test account and then check responses to mostCited for access. if session_id is None: logger.error(f"PaDS Login error in test") assert (False) else: full_URL = base_plus_endpoint_encoded( '/v2/Database/MostCited/?limit=10') response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. r = response.json() print( f"Count: {r['documentList']['responseInfo']['fullCount']} Count complete: {r['documentList']['responseInfo']['fullCountComplete']}" ) # PaDS ID provided has peparchive! # 20211008 Access to items in result list is no longer checked...only when one item is returned. assert (r['documentList']['responseSet'][0].get( "accessChecked", None) == False)
def test_0_most_cited_with_similardocs(self): print( f"Running: {sys._getframe( ).f_code.co_name} at {datetime.now()}") full_URL = base_plus_endpoint_encoded( '/v2/Database/MostCited/?similarcount=3') response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. assert (response.ok == True) r = response.json() # print (r) # see if it can correctly return moreLikeThese try: similar_count = int(r['documentList']['responseSet'][0] ['similarityMatch']['similarNumFound']) except: similar_count = 0 assert (similar_count >= 1)
def test_1C_meta_contents_for_source(self): """ {'infosource': 'volumes_adjacent', 'prev_vol': None, 'matched_vol': {'value': '1', 'count': 34, 'year': '2006'}, 'next_vol': {'value': '2', 'count': 39, 'year': 'IJPSP'}} """ full_URL = base_plus_endpoint_encoded('/v2/Metadata/Contents/IJPSP/1/?moreinfo=2') response = requests.get(full_URL, headers=headers) assert(response.ok == True) # test return r = response.json() print(r['documentList']['responseInfo']['fullCount']) print(r['documentList']['responseInfo']['supplementalInfo']) print(r['documentList']['responseInfo']['supplementalInfo']["next_vol"]) assert (r['documentList']['responseInfo']['supplementalInfo']["infosource"] == "volumes_adjacent") assert (r['documentList']['responseInfo']['supplementalInfo']["prev_vol"] == None) assert (r['documentList']['responseInfo']['supplementalInfo']["next_vol"] == {'value': '2', 'count': 39}) assert (r['documentList']['responseInfo']['supplementalInfo']["matched_vol"] == {'value': '1', 'count': 34})
def test_1A_meta_contents_for_source(self): """ Test with moreinfo == 1 should produce ['documentList']['responseInfo']['supplementalInfo'][infosource] = 'volumes_min_max' max = 11 min = 1 src_code = 'IJPSP' """ full_URL = base_plus_endpoint_encoded('/v2/Metadata/Contents/IJPSP/4/?moreinfo=1') response = requests.get(full_URL, headers=headers) assert(response.ok == True) # test return r = response.json() print(r['documentList']['responseInfo']['fullCount']) print(r['documentList']['responseInfo']['supplementalInfo']["infosource"]) assert (r['documentList']['responseInfo']['supplementalInfo']["infosource"] == "volumes_min_max") assert (r['documentList']['responseInfo']['supplementalInfo']["min"] == 1) assert (r['documentList']['responseInfo']['supplementalInfo']["max"] == 11) assert (r['documentList']['responseInfo']['supplementalInfo']["src_code"] == 'IJPSP')
def test_2_whats_new(self): """ (Moved from TestMosts.py) Set days_back to almost a year to insure current (usually local) database has actually been updated! """ # request login to the API server full_URL = base_plus_endpoint_encoded( '/v2/Database/WhatsNew/?days_back=290') response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. assert (response.ok == True) r = response.json() response_info = r["whatsNew"]["responseInfo"] response_set = r["whatsNew"]["responseSet"] assert (r['whatsNew']['responseInfo']['listType'] == 'newlist') #assert(r["db_server_ok"] == True) print(f"Count: {r['whatsNew']['responseInfo']['count']}") #print (r) assert (response_info["count"] >= 3)
def test_v2_searchanalysis_author_and_journalcode(self): full_URL = base_plus_endpoint_encoded( '/v2/Database/SearchAnalysis/?author=tuckett&sourcecode=AOP') response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() response_info = r["termIndex"]["responseInfo"] response_set = r["termIndex"]["responseSet"] print( f"Term: {response_set[0]['term']} Count: {response_set[0]['termCount']}" ) term0 = r["termIndex"]["responseSet"][0]["term"] assert (r["termIndex"]["responseSet"][0]["termCount"] >= 630) term1 = r["termIndex"]["responseSet"][1]["term"] print( f"Term: {response_set[1]['term']} Count: {response_set[1]['termCount']}" ) assert (r["termIndex"]["responseSet"][1]["termCount"] >= 59) print(term0) assert (term0 == '(AOP) (in source)')
def test_1_Download_orig(self): tempdir = tempfile.gettempdir() for testArticle in self.testArticlesAllFormats: print (f"Downloading original formats for: {testArticle}.") try: full_URL = base_plus_endpoint_encoded(f'/v2/Documents/Downloads/PDFORIG/{testArticle}/') response = requests.get(full_URL, headers=headers) #opener = urllib.request.build_opener() #headerlist = [(k, v) for k, v in headers.items()] #opener.addheaders = headerlist #urllib.request.install_opener(opener) #fullfilename = os.path.join(tempdir, testArticle + ".orig.pdf") #response = urllib.request.urlretrieve(full_URL, filename=fullfilename) # Confirm that the request-response cycle completed successfully. #assert(response[1]["content-type"] == 'application/pdf') except Exception as e: print (f"{testArticle} not available in that format.") else: print (f"Downloads complete for {testArticle}.")
def test06_session_log_report_like_pads(self): # note api_key is required, but already in headers from datetime import date, timedelta dt = date.today() - timedelta(14) print('Current Date :', date.today()) print('14 days before Current Date :', dt) ts = time.time() full_URL = base_plus_endpoint_encoded(f'/v2/Admin/Reports/Session-Log?startdate={dt}&limit=100000&offset=0&download=false&sortorder=asc') response = requests.get(full_URL, headers=headers) assert(response.ok == True) print (f"Watched: Admin Report Query Complete. Time={time.time() - ts}") r = response.json() response_info = r["report"]["responseInfo"] response_set = r["report"]["responseSet"] print (f'Count Retrieved: {response_info["count"]}') print (f'Fullcount Retrieved: {response_info["fullCount"]}') if use_server == 5: assert(response_info["count"] >= 50000) else: assert(response_info["count"] >= 100)
def test_0_whats_new(self): """ (Moved from TestMosts.py) """ # request login to the API server full_URL = base_plus_endpoint_encoded( '/v2/Database/WhatsNew/?days_back=30') response = requests.get(full_URL, headers=headers) # Confirm that the request-response cycle completed successfully. assert (response.ok == True) r = response.json() response_info = r["whatsNew"]["responseInfo"] response_set = r["whatsNew"]["responseSet"] assert (r['whatsNew']['responseInfo']['listType'] == 'newlist') #assert(r["db_server_ok"] == True) print(f"{r['whatsNew']['responseInfo']['count']}") print(r) if response_info["count"] == 0: logger.warning("There are no new articles. Could be ok.") else: assert (response_info["count"] >= 1)
def test_0_post(self): """ """ # make sure both are not there: full_URL = base_plus_endpoint_encoded('/v2/Client/Configuration/') response = requests.delete(full_URL, headers=headers, params={'configname': f"{test_config_name_1}, {test_config_name_2}"} ) # now post the list response = requests.post(full_URL, headers=headers, json=testlist_double) # Confirm that the request-response cycle completed successfully. assert(response.ok == True) assert(response.status_code == 201) r = response.json() assert (r == testlist_double) print ("Post OK: ", r)
def test_v2_searchanalysis_author_and_journalcode_and_text(self): full_URL = base_plus_endpoint_encoded( '/v2/Database/SearchAnalysis/?sourcecode=PCT&citecount=3') response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() #print (r) response_info = r["termIndex"]["responseInfo"] response_set = r["termIndex"]["responseSet"] print( f"Term: {response_set[0]['term']} Count: {response_set[0]['termCount']}" ) print( f"Term: {response_set[1]['term']} Count: {response_set[1]['termCount']}" ) term0 = r["termIndex"]["responseSet"][0]["term"] assert (term0 == '(PCT) (in source)') assert (r["termIndex"]["responseSet"][0]["termCount"] == 482) term1 = r["termIndex"]["responseSet"][1]["term"] print("Term1=", term1) assert (term1 == '[3 TO *] (in cited, cited in the last 5 years)') assert (r["termIndex"]["responseSet"][1]["termCount"] >= 2322)
def test_v2_searchanalysis(self): full_URL = base_plus_endpoint_encoded( '/v2/Database/SearchAnalysis/?author=rangell&fulltext1=transference&sourcecode=AOP' ) response = requests.get(full_URL, headers=headers) assert (response.ok == True) r = response.json() #print (r) response_info = r["termIndex"]["responseInfo"] response_set = r["termIndex"]["responseSet"] print( f"Term: {response_set[0]['term']} Count: {response_set[0]['termCount']}" ) assert (response_set[0]["termCount"] >= 38847) print( f"Term: {response_set[1]['term']} Count: {response_set[1]['termCount']}" ) assert (response_set[1]["termCount"] >= 132) print( f"Term: {response_set[2]['term']} Count: {response_set[2]['termCount']}" ) assert (response_set[1]["termCount"] >= 1)
def test_v2_searchanalysis_author_and_journalcode_and_paratext(self): full_URL = base_plus_endpoint_encoded( '/v2/Database/SearchAnalysis/?sourcecode=BAP&fulltext1="freud psychoanalysis"~25' ) response = requests.get(full_URL, headers=headers) r = response.json() assert (response.ok == True) #print (r) response_info = r["termIndex"]["responseInfo"] response_set = r["termIndex"]["responseSet"] print( f"Term: {response_set[0]['term']} Count: {response_set[0]['termCount']}" ) print( f"Term: {response_set[1]['term']} Count: {response_set[1]['termCount']}" ) term0 = r["termIndex"]["responseSet"][0]["term"] assert (term0 == '"freud psychoanalysis"~25 (in text)') assert (r["termIndex"]["responseSet"][0]["termCount"] >= 19000) term1 = r["termIndex"]["responseSet"][1]["term"] assert (term1 == '(BAP) (in source)') assert (r["termIndex"]["responseSet"][1]["termCount"] >= 403)
def test_4_del_and_cleanup(self): full_URL = base_plus_endpoint_encoded('/v2/Client/Configuration/') # create test records, if not there response = requests.put(full_URL, headers=headers, json=testlist_double) # Confirm that the request-response cycle completed successfully. assert(response.ok == True) response = requests.delete(full_URL, headers=headers, params={'configname': test_config_name_1}) assert(response.ok == True) r = response.json() assert (r["configList"][0]["configSettings"] == config_settings_1) response = requests.delete(full_URL, headers=headers, params={'configname': test_config_name_2}) assert(response.ok == True) r = response.json() assert (r["configList"][0]["configSettings"] == config_settings_2) #assert (r == {'configList': [{'configName': test_config_name_2, 'configSettings': config_settings_2}]}) # First create, then delete both at once response = requests.put(full_URL, headers=headers, json=testlist_double) # Confirm that the request-response cycle completed successfully. assert(response.ok == True) print ("Update list in order to test delete, Put OK: ", r) response = requests.delete(full_URL, headers=headers, params={'configname': f"{test_config_name_1}, {test_config_name_2}"} ) assert(response.ok == True) r = response.json() assert (r["configList"][0]["configSettings"] == config_settings_1) assert (r["configList"][1]["configSettings"] == config_settings_2) print ("Update list Del OK: ", r)