示例#1
0
def test_request_data_protocol():
    responses = client.query(
        attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))
    req = client.request_data(responses)
    req.wait()
    assert req._d['method'] == 'url'
    assert req._d['protocol'] == 'fits'

    responses = client.query(
        attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'),
        attrs.Protocol('fits'))
    req = client.request_data(responses)
    req.wait()
    assert req._d['method'] == 'url'
    assert req._d['protocol'] == 'fits'

    responses = client.query(
        attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'),
        attrs.Protocol('as-is'))
    req = client.request_data(responses)
    req.wait()
    assert req._d['method'] == 'url_quick'
    assert req._d['protocol'] == 'as-is'
示例#2
0
def test_complexquery():
    a1 = attrs.Series('foo1')
    a2 = attrs.Series('foo2')
    t1 = attrs.Time('2012/01/01', '2013/1/2')
    t2 = attrs.Time('2012/01/01', '2013/1/3')
    ans1 = jsoc.jsoc.and_(a1 | a2, t1 | t2)
    assert isinstance(ans1.attrs[0], AttrOr)
    assert isinstance(ans1.attrs[0].attrs[0], AttrAnd)
    assert isinstance(ans1.attrs[0].attrs[1], AttrAnd)
示例#3
0
def test_wait_get():
    responses = client.query(
        attrs.Time('2012/1/3T00:00:00', '2012/1/3T00:00:45'),
        attrs.Series('hmi.M_45s'))
    res = client.get(responses)
    assert isinstance(res, Results)
    assert res.total == 2
示例#4
0
def test_check_request():
    responses = client.query(
        attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))
    req = client.request_data(responses)
    req.wait()
    assert client.check_request(req) == 0
示例#5
0
def test_request_data_error():
    responses = client.query(
        attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'),
        attrs.Protocol('foo'))
    with pytest.raises(TypeError):
        req = client.request_data(responses)
示例#6
0
def test_wait_get():
    responses = client.query(attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'),
                             attrs.Series( 'hmi.M_45s'), attrs.Notify('*****@*****.**'))
    path = tempfile.mkdtemp()
    res = client.get(responses, path=path)
    assert isinstance(res, Results)
    assert res.total == 1
示例#7
0
def test_post_pass():
    responses = client.query(attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'),
                             attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))
    aa = client.request_data(responses, return_resp=True)
    tmpresp = aa[0].json()
    assert tmpresp['status'] == 2
    assert tmpresp['protocol'] == 'FITS,compress Rice'
    assert tmpresp['method'] == 'url'
示例#8
0
def test_get_request():
    responses = client.query(attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'),
                             attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))

    bb = client.request_data(responses)
    path = tempfile.mkdtemp()
    aa = client.get_request(bb, path=path)
    assert isinstance(aa, Results)
示例#9
0
def test_post_pass():
    responses = client.search(
        attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))
    aa = client.request_data(responses)
    tmpresp = aa._d
    assert tmpresp['protocol'] == 'fits'
    assert tmpresp['method'] == 'url'
示例#10
0
def test_search_metadata():
    metadata = client.search_metadata(
        attrs.Time('2014-01-01T00:00:00', '2014-01-01T00:02:00'),
        attrs.Series('aia.lev1_euv_12s'), attrs.Wavelength(304 * u.AA))
    assert isinstance(metadata, pd.DataFrame)
    assert metadata.shape == (11, 176)
    for i in metadata.index.values:
        assert (i.startswith('aia.lev1_euv_12s') and i.endswith('[304]'))
示例#11
0
def test_get_request():
    responses = client.query(
        attrs.Time('2012/1/1T01:00:00', '2012/1/1T01:00:45'),
        attrs.Series('hmi.M_45s'))

    bb = client.request_data(responses)
    aa = client.get_request(bb)
    assert isinstance(aa, Results)
示例#12
0
def test_post_fail(recwarn):
    res = client.query(attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'),
                       attrs.Series('none'), attrs.Notify('*****@*****.**'))
    client.request_data(res, return_resp=True)
    w = recwarn.pop(Warning)
    assert issubclass(w.category, Warning)
    assert "Query 0 returned status 4 with error Series none is not a valid series accessible from hmidb2." == str(w.message)
    assert w.filename
    assert w.lineno
示例#13
0
def test_post_wavelength():
    responses = client.query(attrs.Time('2010/07/30T13:30:00','2010/07/30T14:00:00'),attrs.Series('aia.lev1_euv_12s'),
                             attrs.Wavelength(193*u.AA)|attrs.Wavelength(335*u.AA), attrs.Notify('*****@*****.**'))
    aa = client.request_data(responses, return_resp=True)
    tmpresp = aa[0].json()
    assert tmpresp['status'] == 2
    assert tmpresp['protocol'] == 'FITS,compress Rice'
    assert tmpresp['method'] == 'url'
    assert tmpresp['rcount'] == 302
示例#14
0
def test_post_fail(recwarn):
    res = client.query(attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'),
                       attrs.Series('none'))
    client.request_data(res, return_resp=True)
    w = recwarn.pop(Warning)
    assert issubclass(w.category, Warning)
    assert "Query 0 retuned status 4 with error Cannot export series 'none' - it does not exist." in str(
        w.message)
    assert w.filename
    assert w.lineno
示例#15
0
def test_results_filenames():
    responses = client.query(attrs.Time('2014/1/1T1:00:36', '2014/1/1T01:01:38'),
                             attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))
    path = tempfile.mkdtemp()
    aa = client.get(responses, path=path)
    assert isinstance(aa, Results)
    files = aa.wait()
    assert len(files) == len(responses)
    for hmiurl in aa.map_:
        assert os.path.basename(hmiurl) == os.path.basename(aa.map_[hmiurl]['path'])
示例#16
0
def test_results_filenames():
    responses = client.search(
        attrs.Time('2014/1/1T1:00:36', '2014/1/1T01:01:38'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))
    path = tempfile.mkdtemp()
    aa = client.fetch(responses, path=path)
    assert isinstance(aa, Results)
    files = aa.wait(progress=False)
    assert len(files) == len(responses)
    for hmiurl in aa.map_:
        assert os.path.isfile(hmiurl)
示例#17
0
def test_check_request():
    responses = client.query(
        attrs.Time('2012/1/1T01:00:00', '2012/1/1T01:00:45'),
        attrs.Series('hmi.M_45s'))

    bb = client.request_data(responses)
    aa = client.check_request(bb)
    assert aa == [6] or aa == [1]  #Incase JSOC is being very efficient
    time.sleep(5)
    aa = client.check_request(bb)
    assert aa == [1]
示例#18
0
def test_post_wavelength():
    responses = client.search(
        attrs.Time('2010/07/30T13:30:00', '2010/07/30T14:00:00'),
        attrs.Series('aia.lev1_euv_12s'),
        attrs.Wavelength(193 * u.AA) | attrs.Wavelength(335 * u.AA),
        attrs.Notify('*****@*****.**'))
    aa = client.request_data(responses)
    [r.wait() for r in aa]
    tmpresp = aa[0]._d
    assert tmpresp['protocol'] == 'fits'
    assert tmpresp['method'] == 'url'
    assert tmpresp['count'] == '302'
    tmpresp = aa[1]._d
    assert tmpresp['protocol'] == 'fits'
    assert tmpresp['method'] == 'url'
    assert tmpresp['count'] == '302'
示例#19
0
def test_invalid_query():
    with pytest.raises(ValueError):
        resp = client.query(
            attrs.Time('2012/1/1T01:00:00', '2012/1/1T01:00:45'))
示例#20
0
def test_post_wave_series():
    with pytest.raises(TypeError):
        client.query(
            attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'),
            attrs.Series('hmi.M_45s') | attrs.Series('aia.lev1_euv_12s'),
            attrs.Wavelength(193 * u.AA) | attrs.Wavelength(335 * u.AA))
示例#21
0
def test_query():
    Jresp = client.query(attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:01:30'),
                         attrs.Series('hmi.M_45s'),
                         attrs.Sample(90 * u.second))
    assert isinstance(Jresp, JSOCResponse)
    assert len(Jresp) == 2
示例#22
0
def test_post_notify_fail():
    responses = client.query(
        attrs.Time('2012/1/1T00:00:00', '2012/1/1T00:00:45'),
        attrs.Series('hmi.M_45s'))
    with pytest.raises(ValueError):
        client.request_data(responses, return_resp=True)
示例#23
0
def test_basicquery():
    a1 = attrs.Series('foo')
    t1 = attrs.Time('2012/01/01', '2013/1/2')
    ans1 = jsoc.jsoc.and_(a1, t1)
    assert isinstance(ans1, AttrAnd)
    assert len(ans1.attrs) == 2