예제 #1
0
def mock_query_object(timerange):
    """
    Creating a Query Response object and prefilling it with some information
    """
    # Creating a Query Response Object
    start = timerange.start
    end = timerange.end
    wave = 17 * u.GHz
    delta = end - start
    resp = []
    for i in range(delta.datetime.days + 1):
        start_time = start.datetime + timedelta(days=i)
        end_time = start_time + timedelta(days=1) - timedelta(milliseconds=1)
        obj = {
            'Start Time': parse_time(start_time),
            'End Time': parse_time(end_time),
            'Instrument': 'NORH',
            'Source': 'NAOJ',
            'Provider': 'NRO',
            'Wavelength': wave,
            'url': create_url(start_time, wave)
        }
        resp.append(obj)
    results = QueryResponse(resp, client=norh.NoRHClient())
    return results
예제 #2
0
def test_can_handle_query(time):
    LCClient = norh.NoRHClient()
    ans1 = LCClient._can_handle_query(time, a.Instrument.norh)
    assert ans1 is True
    ans1 = LCClient._can_handle_query(time, a.Instrument.norh,
                                      a.Wavelength(10 * u.GHz))
    assert ans1 is True
    ans2 = LCClient._can_handle_query(time)
    assert ans2 is False
예제 #3
0
def test_query(time, wave):
    qr1 = norh.NoRHClient().search(time, a.Instrument('norh'), wave)
    assert isinstance(qr1, QueryResponse)
    # Not all hypothesis queries are going to produce results, and
    if qr1:
        # There are no observations everyday
        #  so the results found have to be equal or later than the queried time
        #  (looking at the date because it may search for miliseconds, but only date is available)
        assert qr1.time_range().start.date() >= time.start.date()
        #  and the end time equal or smaller.
        # hypothesis can give same start-end, but the query will give you from start to end (so +1)
        assert qr1.time_range().end <= time.end + datetime.timedelta(days=1)
예제 #4
0
def test_query(time, wave):
    LCClient = norh.NoRHClient()
    qr1 = LCClient.search(time, a.Instrument.norh, wave)
    assert isinstance(qr1, QueryResponse)
    # Not all hypothesis queries are going to produce results, and
    if qr1:
        # There are no observations everyday
        #  so the results found have to be equal or later than the queried time
        #  (looking at the date because it may search for miliseconds, but only date is available)
        assert qr1[0]['Start Time'].strftime(
            '%Y-%m-%d') >= time.start.strftime('%Y-%m-%d')
        #  and the end time equal or smaller.
        # hypothesis can give same start-end, but the query will give you from start to end (so +1)
        assert qr1[-1]['End Time'] <= time.end + TimeDelta(1 * u.day)
예제 #5
0
def test_query_wrong_wave():
    c = norh.NoRHClient()
    with pytest.raises(ValueError):
        c.query(a.Time("2016/10/1", "2016/10/2"), a.Instrument('norh'),
                a.Wavelength(50 * u.GHz))
예제 #6
0
def test_wavelength_range():
    with pytest.raises(ValueError):
        norh.NoRHClient().query(a.Time("2016/10/1", "2016/10/2"),
                                a.Instrument('norh'),
                                a.Wavelength(17 * u.GHz, 34 * u.GHz))
예제 #7
0
def test_query_no_wave():
    c = norh.NoRHClient()
    with pytest.raises(ValueError):
        c.query(a.Time("2016/10/1", "2016/10/2"), a.Instrument('norh'))
예제 #8
0
def test_query_34(time):
    qr1 = norh.NoRHClient().query(time, a.Instrument('norh'),
                                  a.Wavelength(34 * u.GHz))
    assert isinstance(qr1, QueryResponse)
    assert qr1.time_range().start == time.start
    assert qr1.time_range().end == time.end
예제 #9
0
def test_get_url_for_date():
    url = norh.NoRHClient()._get_url_for_date(datetime.date(2011, 3, 14),
                                              wavelength=17 * u.GHz)
    assert url == 'ftp://*****:*****@[email protected]/pub/nsro/norh/data/tcx/2011/03/tca110314'
예제 #10
0
def test_get_url_for_time_range(timerange, url_start, url_end):
    urls = norh.NoRHClient()._get_url_for_timerange(timerange,
                                                    wavelength=17 * u.GHz)
    assert isinstance(urls, list)
    assert urls[0] == url_start
    assert urls[-1] == url_end
예제 #11
0
def test_get(time, instrument, wave):
    LCClient = norh.NoRHClient()
    qr1 = LCClient.query(time, instrument, wave)
    res = LCClient.get(qr1)
    download_list = res.wait(progress=False)
    assert len(download_list) == len(qr1)
예제 #12
0
def LCClient():
    return norh.NoRHClient()
예제 #13
0
def test_get(time, instrument, wave):
    LCClient = norh.NoRHClient()
    qr1 = LCClient.search(time, instrument, wave)
    download_list = LCClient.fetch(qr1)
    assert len(download_list) == len(qr1)