Ejemplo n.º 1
0
    def test_synopsis_view(self, simple_populated_db):
        # Null case, ivorn not in DB:
        ep_url = url_for(apiv1.name + '.packet_synopsis')
        url = ep_url + urllib.quote_plus(simple_populated_db.absent_ivorn)
        rv = self.c.get(url)
        assert rv.status_code == 422

        # Positive case, ivorn which has references:
        ivorn_w_refs = list(simple_populated_db.followup_packets)[0]
        url = ep_url + urllib.quote_plus(ivorn_w_refs)
        rv = self.c.get(url)
        assert rv.status_code == 200
        rd = json.loads(rv.data)
        full = rd[ResultKeys.result]
        etree = simple_populated_db.packet_dict[ivorn_w_refs]
        assert len(full['refs']) == len(Cite.from_etree(etree))

        # Negative case, IVORN present but packet contains no references
        all_ivorns = set(simple_populated_db.packet_dict.keys())
        ivorns_wo_refs = list(
                all_ivorns - set(simple_populated_db.followup_packets))
        ivorn = ivorns_wo_refs[0]
        url = ep_url + urllib.quote_plus(ivorn)
        rv = self.c.get(url)
        assert rv.status_code == 200
        rd = json.loads(rv.data)
        full = rd[ResultKeys.result]
        assert len(full['refs']) == 0

        # Find packet which cites a SWIFT GRB, check URLs looked up correctly:
        ref_string = 'BAT_GRB'
        url = url_for(apiv1.name + '.' + views.ListIvorn.view_name,
                      **{filters.RefContains.querystring_key: ref_string}
                      )
        rv = self.c.get(url)
        ref_lists = [Cite.from_etree(p)
                     for p in simple_populated_db.insert_packets
                     if Cite.from_etree(p)]
        matches = []
        for rl in ref_lists:
            for r in rl:
                if ref_string in r.ref_ivorn:
                    matches.append(r)
                    continue
        matched_via_restapi = json.loads(rv.data)[ResultKeys.result]
        assert len(matched_via_restapi) == len(matches)
        url = ep_url + urllib.quote_plus(matched_via_restapi[0])
        rv = self.c.get(url)
        rd = json.loads(rv.data)[ResultKeys.result]
        # When referencing a Swift alert, we should annotate for two urls,
        # GCN.gsfc.nasa.gov / www.swift.ac.uk
        assert len(rd['relevant_urls']) == 2
Ejemplo n.º 2
0
    def test_synopsis_view(self, simple_populated_db):
        # Null case, ivorn not in DB:
        ep_url = url_for(apiv1.name + '.packet_synopsis')
        url = ep_url + quote_plus(simple_populated_db.absent_ivorn)
        rv = self.c.get(url)
        assert rv.status_code == 422

        # Positive case, ivorn which has references:
        ivorn_w_refs = list(simple_populated_db.followup_packets)[0]
        url = ep_url + quote_plus(ivorn_w_refs)
        rv = self.c.get(url)
        assert rv.status_code == 200
        rd = json.loads(rv.data.decode())
        full = rd[ResultKeys.result]
        etree = simple_populated_db.packet_dict[ivorn_w_refs]
        assert len(full['refs']) == len(Cite.from_etree(etree))

        # Negative case, IVORN present but packet contains no references
        all_ivorns = set(simple_populated_db.packet_dict.keys())
        ivorns_wo_refs = list(
            all_ivorns - set(simple_populated_db.followup_packets))
        ivorn = ivorns_wo_refs[0]
        url = ep_url + quote_plus(ivorn)
        rv = self.c.get(url)
        assert rv.status_code == 200
        rd = json.loads(rv.data.decode())
        full = rd[ResultKeys.result]
        assert len(full['refs']) == 0

        # Find packet which cites a SWIFT GRB, check URLs looked up correctly:
        ref_string = 'BAT_GRB'
        url = url_for(apiv1.name + '.' + views.ListIvorn.view_name,
                      **{filters.RefContains.querystring_key: ref_string}
                      )
        rv = self.c.get(url)
        ref_lists = [Cite.from_etree(p)
                     for p in simple_populated_db.insert_packets
                     if Cite.from_etree(p)]
        matches = []
        for rl in ref_lists:
            for r in rl:
                if ref_string in r.ref_ivorn:
                    matches.append(r)
                    continue
        matched_via_restapi = json.loads(rv.data.decode())[ResultKeys.result]
        assert len(matched_via_restapi) == len(matches)
        url = ep_url + quote_plus(matched_via_restapi[0])
        rv = self.c.get(url)
        rd = json.loads(rv.data.decode())[ResultKeys.result]
        # When referencing a Swift alert, we should annotate for two urls,
        # GCN.gsfc.nasa.gov / www.swift.ac.uk
        assert len(rd['relevant_urls']) == 2
Ejemplo n.º 3
0
def test_cite_load_from_etree(fixture_db_session):
    assert len(Cite.from_etree(swift_bat_grb_655721)) == 0
    assert len(Cite.from_etree(swift_xrt_grb_655721)) == 1
    c1 = Cite.from_etree(swift_xrt_grb_655721)[0]
    assert c1.ref_ivorn == swift_bat_grb_655721.attrib['ivorn']
    assert c1.cite_type == vp.definitions.cite_types.followup
Ejemplo n.º 4
0
def test_cite_load_from_etree(fixture_db_session):
    assert len(Cite.from_etree(swift_bat_grb_655721)) == 0
    assert len(Cite.from_etree(swift_xrt_grb_655721)) == 1
    c1 = Cite.from_etree(swift_xrt_grb_655721)[0]
    assert c1.ref_ivorn == swift_bat_grb_655721.attrib['ivorn']
    assert c1.cite_type == vp.definitions.cite_types.followup