Exemplo n.º 1
0
def test_login_basic():
    clear_test_credentials()
    assert config.config_file_read_api_key('test') is None
    prepare_successful_login()
    ArcsecondAPI.login(TEST_LOGIN_USERNAME,
                       TEST_LOGIN_PASSWORD,
                       debug=True,
                       test=True)
    assert config.config_file_read_api_key('test') is None
    assert config.config_file_read_upload_key('test') is None
Exemplo n.º 2
0
def test_login_both_apikey_uploadkey():
    clear_test_credentials()
    assert config.config_file_read_api_key('test') is None
    prepare_successful_login()
    ArcsecondAPI.login(TEST_LOGIN_USERNAME,
                       TEST_LOGIN_PASSWORD,
                       api_key=True,
                       upload_key=True,
                       debug=True,
                       test=True)
    assert config.config_file_read_api_key('test') == TEST_API_KEY
    assert config.config_file_read_upload_key('test') == TEST_UPLOAD_KEY
Exemplo n.º 3
0
def test_datafiles_upload_file_create_threaded_with_callback():
    # Using standard CLI runner to make sure we login successfuly as in other tests.
    runner = CliRunner()
    make_successful_login(runner)
    # has_callback_been_called = False # Do NOT declare var despite what IDE says

    dataset_uuid = uuid.uuid4()
    httpretty.register_uri(httpretty.POST,
                           ARCSECOND_API_URL_DEV + '/datasets/' +
                           str(dataset_uuid) + '/datafiles/',
                           status=201,
                           body='{"result": "OK"}')

    def upload_callback(eventName, progress):
        print(eventName, progress, flush=True)
        global has_callback_been_called
        has_callback_been_called = True

    fixtures_folder = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                   'fixtures')
    # Go for Python module tests
    datafiles_api = ArcsecondAPI.datafiles(dataset=str(dataset_uuid),
                                           debug=True,
                                           test=True)
    payload = {'file': os.path.join(fixtures_folder, 'file1.fits')}
    uploader, _ = datafiles_api.create(payload, callback=upload_callback)
    uploader.start()
    while uploader.is_alive():
        pass
    print(f'is alive? {uploader.is_alive()}', flush=True)
    results, error = uploader.finish()

    assert results is not None
    assert error is None
    assert has_callback_been_called is True
Exemplo n.º 4
0
def parse_coord_string(s, state):
    try:
        if state.verbose:
            click.echo(ECHO_PREFIX +
                       'Parsing REF coordinates input "{}"...'.format(s))
        return SkyCoord(s.replace(',', ' '), frame='icrs', unit='deg')
    except ValueError:
        if state.verbose:
            click.echo(
                ECHO_PREFIX +
                'REF coordinates can be parsed. Looking for an object with name "{}"...'
                .format(s))
        from arcsecond import ArcsecondAPI
        obj = ArcsecondAPI(ArcsecondAPI.ENDPOINT_OBJECTS).read(s)
        coords = obj.get('ICRS_coordinates')
        return SkyCoord(coords.get('right_ascension'),
                        coords.get('declination'),
                        frame='icrs',
                        unit='deg')
Exemplo n.º 5
0
 def test_organisation_GET_nightlogs_filtered_list_valid_member_role(self):
     """As a simple user, I must not be able to access the list of nightlogs of an organisation."""
     api = ArcsecondAPI.nightlogs(debug=True,
                                  test=True,
                                  organisation='saao')
     mock_url_path(httpretty.GET,
                   '/saao/nightlogs/',
                   query='',
                   body='[{uuid: "112233", name:"dummy"}]',
                   status=200)
     mock_url_path(httpretty.GET,
                   '/saao/nightlogs/',
                   query='?date=2020-03-28',
                   body='[]',
                   status=200)
     logs, error = api.list(date='2020-03-28')
     assert logs == []
     assert error is None
Exemplo n.º 6
0
def test_datafiles_upload_file_threaded_no_callback():
    runner = CliRunner()
    make_successful_login(runner)

    dataset_uuid = uuid.uuid4()
    httpretty.register_uri(httpretty.POST,
                           ARCSECOND_API_URL_DEV + '/datasets/' +
                           str(dataset_uuid) + '/datafiles/',
                           status=201,
                           body='{"result": "OK"}')

    # Go for Python module tests
    datafiles_api = ArcsecondAPI.datafiles(dataset=str(dataset_uuid),
                                           debug=True,
                                           test=True)
    uploader, _ = datafiles_api.create({'file': os.path.abspath(__file__)})
    uploader.start()
    time.sleep(0.1)
    results, error = uploader.finish()

    assert results is not None
    assert error is None
Exemplo n.º 7
0
def test_datafiles_upload_file_update_threaded_with_callback():
    runner = CliRunner()
    make_successful_login(runner)
    # has_callback_been_called = False # Do NOT declare var despite what IDE says

    dataset_uuid = uuid.uuid4()
    filename = 'jupiter99.fits'
    httpretty.register_uri(
        httpretty.PATCH,
        f'{ARCSECOND_API_URL_DEV}/datasets/{str(dataset_uuid)}/datafiles/{filename}/',
        status=200,
        body='{"file": "amazon.com..."}')

    def upload_callback(eventName, progress):
        print(eventName, progress, flush=True)
        global has_callback_been_called
        has_callback_been_called = True

    fixtures_folder = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                   'fixtures')
    # Go for Python module tests
    datafiles_api = ArcsecondAPI.datafiles(dataset=str(dataset_uuid),
                                           debug=True,
                                           test=True)
    payload = {'file': os.path.join(fixtures_folder, 'file1.fits')}
    uploader, _ = datafiles_api.update(filename,
                                       payload,
                                       callback=upload_callback)
    uploader.start()
    while uploader.is_alive():
        pass
    print(f'is alive? {uploader.is_alive()}', flush=True)
    results, error = uploader.finish()

    assert results is not None
    assert error is None
    assert has_callback_been_called is True
Exemplo n.º 8
0
def test_default_empty_state():
    clear_test_credentials()
    assert ArcsecondAPI.is_logged_in(debug=True, test=True) is False
    assert ArcsecondAPI.username(debug=True, test=True) == ''
    assert ArcsecondAPI.memberships(debug=True, test=True) == {}
Exemplo n.º 9
0
def test_default_logged_in_with_membership_state():
    clear_test_credentials()
    save_test_credentials('cedric', {'saao': 'superadmin'})
    assert ArcsecondAPI.is_logged_in(debug=True, test=True) is True
    assert ArcsecondAPI.username(debug=True, test=True) == 'cedric'
    assert ArcsecondAPI.memberships(debug=True, test=True) == {'saao': 'superadmin'}
Exemplo n.º 10
0
def test_default_logged_in_state():
    clear_test_credentials()
    save_test_credentials('cedric')
    assert ArcsecondAPI.is_logged_in(debug=True, test=True) is True
    assert ArcsecondAPI.username(debug=True, test=True) == 'cedric'
    assert ArcsecondAPI.memberships(debug=True, test=True) == {}