Пример #1
0
def test_get_collections(monkeypatch):
    monkeypatch.setattr(cadc_core, 'get_access_url', get_access_url_mock)
    dummyTapHandler = DummyTapHandler()
    cadc = CadcClass(dummyTapHandler)

    def mock_run_query(query, output_format, operation):
        assert query == \
               'select distinct collection, energy_emBand from caom2.EnumField'
        assert output_format == 'csv'
        assert operation == 'sync'
        table = Table(rows=[('CFHT', 'Optical'), ('CFHT', 'Infrared'),
                            ('JCMT', 'Millimeter'), ('DAO', 'Optical'),
                            ('DAO', 'Infrared')],
                      names=('collection', 'energy_emBand'))

        class Response(object):
            pass

        response = Response()
        response.results = table
        return response

    cadc.run_query = mock_run_query
    result = cadc.get_collections()
    assert len(result) == 3
    assert 'CFHT' in result
    assert 'JCMT' in result
    assert 'DAO' in result
Пример #2
0
def test_run_query(monkeypatch):
    dummyTapHandler = DummyTapHandler()
    monkeypatch.setattr(cadc_core, 'get_access_url', get_access_url_mock)
    tap = CadcClass(tap_plus_handler=dummyTapHandler)
    query = "query"
    operation = 'sync'
    # default parameters
    parameters = {}
    parameters['query'] = query
    parameters['name'] = None
    parameters['output_file'] = None
    parameters['output_format'] = 'votable'
    parameters['verbose'] = False
    parameters['dump_to_file'] = False
    parameters['upload_resource'] = None
    parameters['upload_table_name'] = None
    tap.run_query(query, operation)
    dummyTapHandler.check_call('run_query', parameters)
    # test with parameters
    dummyTapHandler.reset()
    output_file = 'output'
    output_format = 'format'
    verbose = True
    upload_resource = 'upload_res'
    upload_table_name = 'upload_table'
    parameters['query'] = query
    parameters['name'] = None
    parameters['output_file'] = output_file
    parameters['output_format'] = output_format
    parameters['verbose'] = verbose
    parameters['dump_to_file'] = True
    parameters['upload_resource'] = upload_resource
    parameters['upload_table_name'] = upload_table_name
    tap.run_query(query,
                  operation,
                  output_file=output_file,
                  output_format=output_format,
                  verbose=verbose,
                  upload_resource=upload_resource,
                  upload_table_name=upload_table_name)
    dummyTapHandler.check_call('run_query', parameters)