def test_get_citation_stats(self): '''Test getting citation stats''' from metrics import get_citation_stats from metrics import get_record_info bibs, bibs_ref, IDs, missing = get_record_info(bibcodes=testset, query=None) # We use mock data, so not important that we feed bibcodes instead of # IDs cs, csr, data, selfcits, citdata = get_citation_stats( testset, testset, bibs_ref) # Check the citation stats with expected results citation_checks = [ 'number of citing papers', 'total number of citations', 'number of self-citations', 'total number of refereed citations', 'average number of citations', 'median number of citations', 'normalized number of citations', 'average number of refereed citations' ] for check in citation_checks: self.assertEqual(cs[check], expected_results['citation stats'][check]) # and the same for the citation stats for refereed papers for check in citation_checks: self.assertEqual( csr[check], expected_results['citation stats refereed'][check])
def test_get_citation_stats(self): '''Test getting citation stats''' from metrics import get_citation_stats from metrics import get_record_info bibs, bibs_ref, IDs, missing = get_record_info( bibcodes=testset, query=None) # We use mock data, so not important that we feed bibcodes instead of # IDs cs, csr, data, selfcits, citdata = get_citation_stats( testset, testset, bibs_ref) # Check the citation stats with expected results citation_checks = ['number of citing papers', 'total number of citations', 'number of self-citations', 'total number of refereed citations', 'average number of citations', 'median number of citations', 'normalized number of citations', 'average number of refereed citations'] for check in citation_checks: self.assertEqual( cs[check], expected_results['citation stats'][check]) # and the same for the citation stats for refereed papers for check in citation_checks: self.assertEqual( csr[check], expected_results['citation stats refereed'][check])
def test_get_record_info_from_bibcodes(self): '''Test getting record info when specifying bibcodes''' from metrics import get_record_info bibs, bibs_ref, IDs, missing = get_record_info( bibcodes=testset, query=None) # The list of bibcodes returned should be equal to the test set self.assertEqual(sorted(map(str, bibs)), sorted(testset)) # The list IDs should be a list of integers self.assertEqual(isinstance(IDs, list), True) self.assertTrue(False not in [isinstance(x, int) for x in IDs]) # The list of skipped bibcodes should be empty self.assertEqual(missing, []) # If we add a non-existing bibcode to the test set, it should get # returned in the 'missing' list bibs, bibs_ref, IDs, missing = get_record_info( bibcodes=testset + ['foo'], query=None) self.assertEqual(missing, ['foo'])
def test_illegal_retrieval_method(self): '''No record info is found when an unsupported retrieval method is specified''' from metrics import get_record_info data = get_record_info(other="foo") expected = {'Status Code': 200, 'Error Info': 'Unsupported metrics request', 'Error': 'Unable to get results!'} self.assertEqual(data, expected)
def test_get_record_info_from_bibcodes(self): '''Test getting record info when specifying bibcodes''' from metrics import get_record_info bibs, bibs_ref, IDs, missing = get_record_info(bibcodes=testset, query=None) # The list of bibcodes returned should be equal to the test set self.assertEqual(sorted(map(str, bibs)), sorted(testset)) # The list IDs should be a list of integers self.assertEqual(isinstance(IDs, list), True) self.assertTrue(False not in [isinstance(x, int) for x in IDs]) # The list of skipped bibcodes should be empty self.assertEqual(missing, []) # If we add a non-existing bibcode to the test set, it should get # returned in the 'missing' list bibs, bibs_ref, IDs, missing = get_record_info(bibcodes=testset + ['foo'], query=None) self.assertEqual(missing, ['foo'])
def test_illegal_retrieval_method(self): '''No record info is found when an unsupported retrieval method is specified''' from metrics import get_record_info data = get_record_info(other="foo") expected = { 'Status Code': 200, 'Error Info': 'Unsupported metrics request', 'Error': 'Unable to get results!' } self.assertEqual(data, expected)
def test_solr_failure(self): '''No record info is found because Solr failed to return results''' from metrics import get_record_info httpretty.register_uri( httpretty.GET, self.app.config.get('METRICS_SOLRQUERY_URL'), content_type='application/json', status=500, body="""{ "responseHeader":{ "status":0, "QTime":0, "params":{ "fl":"bibcode", "indent":"true", "wt":"json", "q":"*"}}, "response":{"numFound":0,"start":0,"docs":[] }}""") data = get_record_info(bibcodes=None, query="foo") self.assertTrue(data['Status Code'] == 500) self.assertTrue('Error' in data)
def test_solr_failure(self): '''No record info is found because Solr failed to return results''' from metrics import get_record_info httpretty.register_uri(httpretty.GET, self.app.config.get('METRICS_SOLRQUERY_URL'), content_type='application/json', status=500, body="""{ "responseHeader":{ "status":0, "QTime":0, "params":{ "fl":"bibcode", "indent":"true", "wt":"json", "q":"*"}}, "response":{"numFound":0,"start":0,"docs":[] }}""") data = get_record_info(bibcodes=None, query="foo") self.assertTrue(data['Status Code'] == 500) self.assertTrue('Error' in data)
def test_get_record_info_from_query(self): '''Test getting record info when a query is supplied''' from metrics import get_record_info httpretty.register_uri(httpretty.GET, self.app.config.get('METRICS_SOLRQUERY_URL'), content_type='application/json', status=200, body="""{ "responseHeader":{ "status":0, "QTime":0, "params":{ "fl":"bibcode", "indent":"true", "wt":"json", "q":"*"}}, "response":{"numFound":10456930,"start":0,"docs":%s }}""" % json.dumps(mockdata)) bibs, bibs_ref, IDs, missing = get_record_info(bibcodes=None, query="foo") # The list IDs should be a list of integers self.assertEqual(isinstance(IDs, list), True) self.assertTrue(False not in [isinstance(x, int) for x in IDs]) # The list of skipped bibcodes should be empty self.assertEqual(missing, [])
def test_get_record_info_from_query(self): '''Test getting record info when a query is supplied''' from metrics import get_record_info httpretty.register_uri( httpretty.GET, self.app.config.get('METRICS_SOLRQUERY_URL'), content_type='application/json', status=200, body="""{ "responseHeader":{ "status":0, "QTime":0, "params":{ "fl":"bibcode", "indent":"true", "wt":"json", "q":"*"}}, "response":{"numFound":10456930,"start":0,"docs":%s }}""" % json.dumps(mockdata)) bibs, bibs_ref, IDs, missing = get_record_info( bibcodes=None, query="foo") # The list IDs should be a list of integers self.assertEqual(isinstance(IDs, list), True) self.assertTrue(False not in [isinstance(x, int) for x in IDs]) # The list of skipped bibcodes should be empty self.assertEqual(missing, [])