Example #1
0
def test_request_data_protocol():
    responses = client.search(
        vso_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.search(
        vso_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.search(
        vso_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'
Example #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)
Example #3
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
Example #4
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
Example #5
0
def test_check_request():
    responses = client.search(
        vso_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.status == 0
Example #6
0
def test_request_data_error():
    responses = client.search(
        vso_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)
Example #7
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
Example #8
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)
Example #9
0
def test_search_metadata():
    metadata = client.search_metadata(
        vso_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]'))
Example #10
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)
Example #11
0
def test_wait_get():
    responses = client.search(
        vso_attrs.Time('2012/1/1T1:00:36', '2012/1/1T01:00:38'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))
    path = tempfile.mkdtemp()
    res = client.fetch(responses, path=path)
    assert isinstance(res, Results)
    assert len(res) == 1
Example #12
0
def test_post_pass():
    responses = client.search(
        vso_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'
Example #13
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'
Example #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'), 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
Example #15
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
Example #16
0
def test_results_filenames():
    responses = client.search(
        vso_attrs.Time('2014/1/1T1:00:36', '2014/1/1T01:01:38'),
        attrs.Series('hmi.M_45s'), attrs.Notify('*****@*****.**'))
    path = tempfile.mkdtemp()
    files = client.fetch(responses, path=path)
    assert isinstance(files, Results)
    assert len(files) == len(responses)
    for hmiurl in files:
        assert os.path.isfile(hmiurl)
Example #17
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'])
Example #18
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
Example #19
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]
Example #20
0
def test_post_wavelength():
    responses = client.search(
        vso_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'
Example #21
0
def test_basicquery():
    a1 = attrs.Series('foo')
    t1 = core_attrs.Time('2012/01/01', '2013/1/2')
    ans1 = jsoc.jsoc.and_(a1, t1)
    assert isinstance(ans1, AttrAnd)
    assert len(ans1.attrs) == 2
Example #22
0
# -*- coding: utf-8 -*-
import pytest

import astropy.units as u

import sunpy.net.jsoc as jsoc
import sunpy.net.jsoc.attrs as attrs
import sunpy.net.vso.attrs as vso_attrs
from sunpy.net import _attrs as core_attrs

from sunpy.net.attr import AttrOr, AttrAnd


@pytest.mark.parametrize(("attr1, attr2"),
                         [(attrs.Series('foo'), attrs.Series('boo')),
                         (attrs.Protocol('a1'), attrs.Protocol('a2')),
                         (attrs.Notify('*****@*****.**'),
                          attrs.Notify('*****@*****.**'))])
def test_and(attr1, attr2):
    pytest.raises(TypeError, lambda: attr1 & attr2)


def test_basicquery():
    a1 = attrs.Series('foo')
    t1 = core_attrs.Time('2012/01/01', '2013/1/2')
    ans1 = jsoc.jsoc.and_(a1, t1)
    assert isinstance(ans1, AttrAnd)
    assert len(ans1.attrs) == 2


def test_mediumquery():
Example #23
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)
Example #24
0
import pytest

import astropy.units as u

import sunpy.net.jsoc as jsoc
import sunpy.net.jsoc.attrs as attrs
from sunpy.net.attr import Attr, AttrOr, AttrAnd


@pytest.mark.parametrize(
    ("attr1, attr2"), [(attrs.Series('foo'), attrs.Series('boo')),
                       (attrs.Protocol('a1'), attrs.Protocol('a2')),
                       (attrs.Notify('*****@*****.**'),
                        attrs.Notify('*****@*****.**')),
                       (attrs.Compression('rice'), attrs.Compression('rice'))])
def test_and(attr1, attr2):
    pytest.raises(TypeError, lambda: attr1 & attr2)


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


def test_mediumquery():
    a1 = attrs.Series('foo1')
    a2 = attrs.Series('foo2')
    t1 = attrs.Time('2012/01/01', '2013/1/2')
Example #25
0
def test_post_notify_fail():
    responses = client.search(
        vso_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)