示例#1
0
 def test_privateMethodLinkRequest2(self):
     link_request = LinkRequest(
         '2013MNRAS.435.1904M', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     self.assertEqual(
         link_request._LinkRequest__get_url_hostname(
             'http://cda.harvard.edu/chaser?obsid=494'), 'cda.harvard.edu')
    def test_link_indentifications(self):
        """
        returning a url for either DOI or arXiv link types
        :return:
        """
        response = LinkRequest(
            bibcode='2010ApJ...713L.103B',
            link_type='DOI',
            id='10.1088/2041-8205/713/2/L103').process_request_new()
        self.assertEqual(response._status_code, 200)
        self.assertDictEqual(
            eval(response.response[0]), {
                "action": "redirect",
                "link": "https://doi.org/10.1088/2041-8205/713/2/L103",
                "link_type": "DOI",
                "service": "https://doi.org/10.1088/2041-8205/713/2/L103"
            })

        response = LinkRequest(bibcode='2018arXiv180303598K',
                               link_type='ARXIV',
                               id='1803.03598').process_request_new()
        self.assertEqual(response._status_code, 200)
        self.assertDictEqual(
            eval(response.response[0]), {
                "action": "redirect",
                "link": "http://arxiv.org/abs/1803.03598",
                "link_type": "ARXIV",
                "service": "http://arxiv.org/abs/1803.03598"
            })
示例#3
0
 def test_privateMethodLinkRequest3(self):
     link_request = LinkRequest(
         '2013MNRAS.435.1904M', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     title, url = link_request._LinkRequest__get_data_source_title_url(
         'SIMBAD', '')
     self.assertEqual(title, 'SIMBAD Database at the CDS')
     self.assertEqual(url, 'http://simbad.u-strasbg.fr')
示例#4
0
 def test_privateMethodLinkRequest4(self):
     link_request = LinkRequest(
         '2013MNRAS.435.1904M', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     title, url = link_request._LinkRequest__get_data_source_title_url(
         'Author', 'http://author.does-not.have.url')
     self.assertEqual(title, 'Author Hosted Dataset')
     self.assertEqual(url, 'http://author.does-not.have.url')
示例#5
0
 def test_privateMethodLinkRequest8(self):
     link_request = LinkRequest(
         '1948TrPul..61....5Z', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     self.assertEqual(
         link_request._LinkRequest__update_data_type_hostname(
             'http://vizier.u-strasbg.fr', 'Vizier',
             'http://$VIZIER$/viz-bin/VizieR?-source=I/45'),
         'http://vizier.u-strasbg.fr/viz-bin/VizieR?-source=I/45')
示例#6
0
 def test_privateMethodLinkRequest11(self):
     link_request = LinkRequest(
         '1979A&AS...38..423G', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     self.assertEqual(
         link_request._LinkRequest__update_data_type_hostname(
             'http://vizier.u-strasbg.fr/', 'CDS',
             'http://cdsweb.u-strasbg.fr/cgi-bin/qcat?V/35'),
         'http://cdsweb.u-strasbg.fr/cgi-bin/qcat?V/35')
示例#7
0
 def test_privateMethodLinkRequest9(self):
     link_request = LinkRequest(
         '1905POPot..50....1L', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     self.assertEqual(
         link_request._LinkRequest__update_data_type_hostname(
             'http://vizier.u-strasbg.fr/', 'CDS',
             'http://$VIZIER$/viz-bin/VizieR?-source=IV/26'),
         'http://vizier.u-strasbg.fr/viz-bin/VizieR?-source=IV/26')
示例#8
0
 def test_privateMethodLinkRequest10(self):
     link_request = LinkRequest(
         '2013MNRAS.435.1904M', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     self.assertEqual(
         link_request._LinkRequest__update_data_type_hostname(
             'http://cxc.harvard.edu/cda', 'Chandra',
             'http://cda.harvard.edu/chaser?obsid=494'),
         'http://cda.harvard.edu/chaser?obsid=494')
示例#9
0
 def test_privateMethodLinkRequest7(self):
     link_request = LinkRequest(
         '2013MNRAS.435.1904M', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     self.assertEqual(
         link_request._LinkRequest__update_data_type_hostname(
             'http://simbad.u-strasbg.fr', 'SIMBAD',
             'http://$SIMBAD$/simbo.pl?bibcode=2013MNRAS.435.1904M'),
         'http://simbad.u-strasbg.fr/simbo.pl?bibcode=2013MNRAS.435.1904M')
示例#10
0
 def test_privateMethodLinkRequest5(self):
     link_request = LinkRequest(
         '2013MNRAS.435.1904M', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     title, url = link_request._LinkRequest__get_data_source_title_url(
         'newSubType', 'http://newSubType.does-not.have.url')
     self.assertEqual(title,
                      'Resource at http://newSubType.does-not.have.url')
     self.assertEqual(url, 'http://newSubType.does-not.have.url')
示例#11
0
 def test_privateMethodLinkRequest6(self):
     link_request = LinkRequest(
         '2013MNRAS.435.1904M', 'DATA',
         self.current_app.config['RESOLVER_GATEWAY_URL'])
     self.assertEqual(
         link_request._LinkRequest__update_data_type_hostname(
             'https://ned.ipac.caltech.edu', 'NED',
             'http://$NED$/cgi-bin/nph-objsearch?search_type=Search&refcode=2013MNRAS.435.1904M'
         ),
         'http://ned.ipac.caltech.edu/cgi-bin/nph-objsearch?search_type=Search&refcode=2013MNRAS.435.1904M'
     )
示例#12
0
    def test_associated_redirect_url(self):
        """

        """
        link_request = LinkRequest('1990A&AS...83...71D', 'ASSOCIATED')
        bibcode, redirectURL = link_request._LinkRequest__get_associated_redirect_url(
            url='1987A&A...179...60C')
        self.assertEqual(bibcode, '1987A&A...179...60C')
        self.assertEqual(
            redirectURL,
            'http://localhost:5050/link_gateway/1990A&AS...83...71D/associated/:%2Fabs%2F1987A%26A...179...60C%2Fabstract'
        )
 def test_link_presentation_error_link_type(self):
     """
     return 400 for unrecognizable link type
     :return:
     """
     response = LinkRequest(bibcode='2017MNRAS.467.3556B', link_type='errorlinktype').process_request()
     self.assertEqual(response._status_code, 400)
示例#14
0
 def test_publicMethodLinkRequest1(self):
     response = LinkRequest(
         '1987gady.book.....B',
         'ABSTRACT').request_link_type_deterministic_single_url_toJSON('')
     self.assertEqual(response._status_code, 404)
     self.assertEqual(response.response[0],
                      b'{"error": "did not find any records"}')
 def test_link_url_KeyError(self):
     """
     return 400 from request_link_type_single_url where there is KeyError
     :return:
     """
     results = [{
         'bibcode':
         u'2017MNRAS.467.3556B',
         'link_type':
         u'PRESENTATION',
         'link_sub_type':
         '',
         'title': [u''],
         'url_KeyError': ['http://www.astro.lu.se/~alexey/animations.html'],
         'itemCount':
         0,
     }]
     response = LinkRequest(
         bibcode='2017MNRAS.467.3556B',
         link_type='PRESENTATION').request_link_type_single_url(results)
     self.assertEqual(response._status_code, 400)
     self.assertEqual(
         eval(response.response[0]), {
             "error":
             "requested information for bibcode=2017MNRAS.467.3556B and link_type=PRESENTATION is missing"
         })
 def test_link_associated_IndexError(self):
     """
     return 400 from request_link_type_associated when there is IndexError
     :return:
     """
     results = [{
         'bibcode':
         u'1971ATsir.615....4D',
         'link_type':
         u'ASSOCIATED',
         'link_sub_type':
         '',
         'title': [u'Part 11'],
         'url': [
             u'1971ATsir.615....4D', u'1971ATsir.624....1D',
             u'1976Afz....12..665D', u'1983Ap.....19..134D',
             u'1983Afz....19..229D', u'1974ATsir.809....2D',
             u'1984Afz....20..525D', u'1974Afz....10..315D',
             u'1984Ap.....20..290D', u'1973ATsir.759....6D',
             u'1974ATsir.837....2D', u'1974ATsir.809....1D',
             u'1971ATsir.621....7D'
         ],
         'itemCount':
         0,
     }]
     response = LinkRequest(
         bibcode='1971ATsir.615....4D',
         link_type='ASSOCIATED').request_link_type_associated(results)
     self.assertEqual(response._status_code, 400)
     self.assertEqual(
         eval(response.response[0]), {
             "error":
             "requested information for bibcode=1971ATsir.615....4D and link_type=ASSOCIATED is missing"
         })
 def test_link_data_KeyError(self):
     """
     return 400 from request_link_type_data where there is KeyError
     :return:
     """
     results = [{
         'bibcode':
         u'2013MNRAS.435.1904M',
         'link_type':
         u'DATA',
         'link_sub_type':
         u'MAST',
         'title': [u'MAST References (GALEX EUVE HST)'],
         'url_KeyError': [
             u'http://archive.stsci.edu/mastbibref.php?bibcode=2013MNRAS.435.1904M'
         ],
         'itemCount':
         3
     }]
     response = LinkRequest(
         bibcode='2013MNRAS.435.1904',
         link_type='PUB_PDF').request_link_type_data(results)
     self.assertEqual(response._status_code, 400)
     self.assertEqual(
         eval(response.response[0]), {
             "error":
             "requested information for bibcode=2013MNRAS.435.1904 and link_type=ESOURCE is missing"
         })
示例#18
0
 def test_link_data_error_bibcode(self):
     """
     return 404 for not finding any records
     :return:
     """
     results = get_records(bibcode='errorbibcode', link_type='DATA')
     response = LinkRequest(bibcode='').request_link_type_data(results)
     self.assertEqual(response._status_code, 404)
 def test_process_request_no_bibcode_error(self):
     """
     return 400 for bibcode of length 0
     :return:
     """
     response = LinkRequest(bibcode='', link_type='PRESENTATION').process_request()
     self.assertEqual(response._status_code, 400)
     self.assertEqual(eval(response.response[0]), {"error": "no bibcode received"})
 def test_link_no_url(self):
     """
     return 404 for not finding any records
     :return:
     """
     response = LinkRequest(bibcode='2017MNRAS.467.3556B', link_type='PRESENTATION').request_link_type_single_url(None)
     self.assertEqual(response._status_code, 404)
     self.assertEqual(eval(response.response[0]), {"error": "did not find any records"})
 def test_link_esource_multiple_urls(self):
     """
     return multiple escourse
     :return:
     """
     results = [{
         'bibcode':
         u'22020AANv....1..199K',
         'link_type':
         u'ESOURCE',
         'link_sub_type':
         u'PUB_PDF',
         'title': [u''],
         'url': [
             'http://astronomianova.org/pdf/AAN1_2020.pdf',
             'http://uavso.org.ua/ila/2020AANv....1..199K.pdf',
             'http://www.oa.uj.edu.pl/pbl/AAN/AAN6.pdf'
             ''
         ],
         'itemCount':
         0
     }]
     response = LinkRequest(
         bibcode='2020AANv....1..199K',
         link_type='ESOURCE').request_link_type_esource(results)
     response_json = {
         'action': 'display',
         'service': '',
         'links': {
             'count':
             1,
             'records': [{
                 'url':
                 'http://astronomianova.org/pdf/AAN1_2020.pdf',
                 'link_type':
                 'ESOURCE|PUB_PDF',
                 'title':
                 'http://astronomianova.org/pdf/AAN1_2020.pdf'
             }, {
                 'url':
                 'http://uavso.org.ua/ila/2020AANv....1..199K.pdf',
                 'link_type':
                 'ESOURCE|PUB_PDF',
                 'title':
                 'http://uavso.org.ua/ila/2020AANv....1..199K.pdf'
             }, {
                 'url': 'http://www.oa.uj.edu.pl/pbl/AAN/AAN6.pdf',
                 'link_type': 'ESOURCE|PUB_PDF',
                 'title': 'http://www.oa.uj.edu.pl/pbl/AAN/AAN6.pdf'
             }],
             'bibcode':
             '2020AANv....1..199K',
             'link_type':
             'ESOURCE'
         }
     }
     self.assertEqual(response._status_code, 200)
     self.assertEqual(eval(response.response[0]), response_json)
示例#22
0
 def test_link_associated_error_bibcode(self):
     """
     return 404 for not finding any records
     :return:
     """
     results = get_records(bibcode='errorbibcode', link_type='ASSOCIATED')
     response = LinkRequest(
         bibcode='').request_link_type_associated(results)
     self.assertEqual(response._status_code, 404)
示例#23
0
 def test_fetchingCoRead(self):
     response = LinkRequest('1987gady.book.....B',
                            'COREADS').process_request()
     self.assertEqual(response._status_code, 200)
     self.assertDictEqual(
         eval(response.response[0]), {
             "action": "redirect",
             "link": "/abs/1987gady.book.....B/coreads",
             "link_type": "COREADS",
             "service": "/abs/1987gady.book.....B/coreads"
         })
示例#24
0
 def test_fetchingAbstract(self):
     response = LinkRequest('1987gady.book.....B',
                            'ABSTRACT').process_request()
     self.assertEqual(response._status_code, 200)
     self.assertDictEqual(
         eval(response.response[0]), {
             "action": "redirect",
             "link": "/abs/1987gady.book.....B/abstract",
             "link_type": "ABSTRACT",
             "service": "/abs/1987gady.book.....B/abstract"
         })
示例#25
0
 def test_fetchingReferences(self):
     response = LinkRequest('1998ARA&A..36..189K',
                            'REFERENCES').process_request()
     self.assertEqual(response._status_code, 200)
     self.assertDictEqual(
         eval(response.response[0]), {
             "action": "redirect",
             "link": "/abs/1998ARA&A..36..189K/references",
             "link_type": "REFERENCES",
             "service": "/abs/1998ARA&A..36..189K/references"
         })
示例#26
0
 def test_case_insensetive_link_sub_type_data(self):
     """
     Test case insensitvity of data link subtypes
     """
     lowercase_data_sub_type = [
         'aca', 'alma', 'ari', 'astroverse', 'atnf', 'author', 'bavj',
         'bicep2', 'cadc', 'cds', 'chandra', 'dryad', 'esa', 'eso',
         'figshare', 'gcpd', 'gemini', 'github', 'gtc', 'heasarc',
         'herschel', 'ibvs', 'ines', 'irsa', 'iso', 'jwst', 'koa', 'lpl',
         'mast', 'ned', 'nexsci', 'noao', 'pangaea', 'pasa', 'pdg', 'pds',
         'protocols', 'simbad', 'spitzer', 'tns', 'vizier', 'xmm', 'zenodo'
     ]
     uppercase_data_sub_type = [
         'ACA', 'ALMA', 'ARI', 'ASTROVERSE', 'ATNF', 'AUTHOR', 'BAVJ',
         'BICEP2', 'CADC', 'CDS', 'CHANDRA', 'DRYAD', 'ESA', 'ESO',
         'FIGSHARE', 'GCPD', 'GEMINI', 'GITHUB', 'GTC', 'HEASARC',
         'HERSCHEL', 'IBVS', 'INES', 'IRSA', 'ISO', 'JWST', 'KOA', 'LPL',
         'MAST', 'NED', 'NEXSCI', 'NOAO', 'PANGAEA', 'PASA', 'PDG', 'PDS',
         'PROTOCOLS', 'SIMBAD', 'SPITZER', 'TNS', 'VIZIER', 'XMM', 'ZENODO'
     ]
     mixedcase_data_sub_type = [
         'AcA', 'ALMA', 'ARI', 'Astroverse', 'ATNF', 'Author', 'BAVJ',
         'BICEP2', 'CADC', 'CDS', 'Chandra', 'Dryad', 'ESA', 'ESO',
         'Figshare', 'GCPD', 'Gemini', 'Github', 'GTC', 'HEASARC',
         'Herschel', 'IBVS', 'INES', 'IRSA', 'ISO', 'JWST', 'KOA', 'LPL',
         'MAST', 'NED', 'NExScI', 'NOAO', 'PANGAEA', 'PASA', 'PDG', 'PDS',
         'protocols', 'SIMBAD', 'Spitzer', 'TNS', 'Vizier', 'XMM', 'Zenodo'
     ]
     for lower, db in zip(lowercase_data_sub_type, mixedcase_data_sub_type):
         link_request = LinkRequest(
             'anybibcode', lower,
             self.current_app.config['RESOLVER_GATEWAY_URL'])
         self.assertEqual(link_request.link_type, 'DATA')
         self.assertEqual(link_request.link_sub_type, db)
     for upper, db in zip(uppercase_data_sub_type, mixedcase_data_sub_type):
         link_request = LinkRequest(
             'anybibcode', upper,
             self.current_app.config['RESOLVER_GATEWAY_URL'])
         self.assertEqual(link_request.link_type, 'DATA')
         self.assertEqual(link_request.link_sub_type, db)
 def test_link_data_IndexError(self):
     """
     return 404 from request_link_type_data when there is IndexError
     :return:
     """
     results = [{'bibcode': u'2013MNRAS.435.1904M',
                 'link_type': u'DATA',
                 'link_sub_type': u'MAST',
                 'title': [u'MAST References (GALEX EUVE HST)'],
                 'url': [],
                 'itemCount': 3}]
     response = LinkRequest(bibcode='2013MNRAS.435.1904M', link_type='MAST').request_link_type_data(results)
     self.assertEqual(response._status_code, 404)
     self.assertEqual(eval(response.response[0]), {"error": "did not find any records"})
 def test_link_no_url_esource(self):
     """
     return 404 from request_link_type_esource when there is IndexError
     :return:
     """
     results = [{'bibcode': u'2013MNRAS.435.1904M',
                 'link_type': u'ESOURCE',
                 'link_sub_type': u'EPRINT_HTML',
                 'title': [u''],
                 'url': [],
                 'itemCount': 0}]
     response = LinkRequest(bibcode='2013MNRAS.435.1904', link_type='ESOURCE').request_link_type_esource(results)
     self.assertEqual(response._status_code, 404)
     self.assertEqual(eval(response.response[0]), {"error": "did not find any records"})
 def test_link_esource_KeyError(self):
     """
     return 400 from request_link_type_esource where there is KeyError
     :return:
     """
     results = [{'bibcode': u'2013MNRAS.435.1904M',
                 'link_type': u'ESOURCE',
                 'link_sub_type': u'EPRINT_HTML',
                 'title': [u''],
                 'url_KeyError': [u'http://arxiv.org/abs/1307.6556'],
                 'itemCount': 0}]
     response = LinkRequest(bibcode='2013MNRAS.435.1904', link_type='ESOURCE').request_link_type_esource(results)
     self.assertEqual(response._status_code, 400)
     self.assertEqual(eval(response.response[0]), {"error": "requested information for bibcode=2013MNRAS.435.1904 and link_type=ESOURCE is missing"})
 def test_link_type_single_url(self):
     """
     return a url from request_link_type_single_url when results passed in is correct and complete
     :return:
     """
     results = [{'bibcode': u'2017MNRAS.467.3556B',
                 'link_type': u'PRESENTATION',
                 'link_sub_type': '',
                 'title': [u''],
                 'url': ['http://www.astro.lu.se/~alexey/animations.html'],
                 'itemCount': 0,
                 }]
     response = LinkRequest(bibcode='2017MNRAS.467.3556B', link_type='PRESENTATION').request_link_type_single_url(results)
     self.assertEqual(response._status_code, 200)
     self.assertDictEqual(eval(response.response[0]), {"action": "redirect", "link": "http://www.astro.lu.se/~alexey/animations.html", "link_type": "PRESENTATION", "service": "http://www.astro.lu.se/~alexey/animations.html"})