diff --git a/README.md b/README.md index 3d4c23c..f7e7ffe 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ To delete a data file, one use its "id/pk" (pk = Primary Key == ID): As a Python module: >>> from arcsecond import ArcsecondAPI - >>> api = Arcsecond.build_datafiles_api(dataset='') + >>> api = ArcsecondAPI.datafiles(dataset='') >>> api.create(file='') More documentation is coming. diff --git a/arcsecond/__init__.py b/arcsecond/__init__.py index d607568..0850ce0 100644 --- a/arcsecond/__init__.py +++ b/arcsecond/__init__.py @@ -1,10 +1,10 @@ -from .api import Arcsecond, ArcsecondError, ArcsecondConnectionError, ArcsecondInvalidEndpointError +from .api import ArcsecondAPI, ArcsecondError, ArcsecondConnectionError, ArcsecondInvalidEndpointError name = 'arcsecond' -__all__ = ["Arcsecond", +__all__ = ["ArcsecondAPI", "ArcsecondError", "ArcsecondConnectionError", "ArcsecondInvalidEndpointError"] -__version__ = '0.9.8' +__version__ = '1.0.0' diff --git a/arcsecond/api/__init__.py b/arcsecond/api/__init__.py index 3f9cff3..0bc0990 100644 --- a/arcsecond/api/__init__.py +++ b/arcsecond/api/__init__.py @@ -1,7 +1,7 @@ from .error import ArcsecondConnectionError, ArcsecondError, ArcsecondInvalidEndpointError -from .main import Arcsecond +from .main import ArcsecondAPI -__all__ = ["Arcsecond", +__all__ = ["ArcsecondAPI", "ArcsecondError", "ArcsecondConnectionError", "ArcsecondInvalidEndpointError"] diff --git a/arcsecond/api/main.py b/arcsecond/api/main.py index 7dabf6b..bf08cbe 100644 --- a/arcsecond/api/main.py +++ b/arcsecond/api/main.py @@ -84,39 +84,12 @@ def factory(endpoint_class, state=None, **kwargs): return ArcsecondAPI(endpoint_class, state, **kwargs) for endpoint_class in ENDPOINTS: - func_name = 'build_' + endpoint_class.name + '_api' - setattr(cls, func_name, staticmethod(types.MethodType(factory, endpoint_class))) + setattr(cls, endpoint_class.name, staticmethod(types.MethodType(factory, endpoint_class))) return cls @set_api_factory -class Arcsecond(object): - @classmethod - def is_logged_in(cls, state=None, **kwargs): - return ArcsecondAPI.is_logged_in(state, **kwargs) - - @classmethod - def username(cls, state=None, **kwargs): - return ArcsecondAPI.username(state, **kwargs) - - @classmethod - def api_key(cls, state=None, **kwargs): - return ArcsecondAPI.api_key(state, **kwargs) - - @classmethod - def memberships(cls, state=None, **kwargs): - return ArcsecondAPI.memberships(state, **kwargs) - - @classmethod - def login(cls, username, password, subdomain, state=None, **kwargs): - return ArcsecondAPI.login(username, password, subdomain, state, **kwargs) - - @classmethod - def register(cls, username, email, password1, password2, state=None, **kwargs): - return ArcsecondAPI.register(username, email, password1, password2, state, **kwargs) - - class ArcsecondAPI(object): def __init__(self, endpoint_class=None, state=None, **kwargs): self.state = get_api_state(state, **kwargs) @@ -223,17 +196,17 @@ def _echo_error(cls, state, error): click.echo(click.style(ECHO_PREFIX + message, fg='red')) @classmethod - def _check_organisation_membership(cls, state, username, subdomain): - ArcsecondAPI._echo_message(state, f'Checking Membership of Organisation "{subdomain}"...') + def _check_memberships(cls, state, username): + ArcsecondAPI._echo_message(state, f'Checking Memberships...') profile, error = PersonalProfileAPIEndPoint(state.make_new_silent()).read(username) if error: ArcsecondAPI._echo_error(state, error) else: memberships = {m['organisation']['subdomain']: m['role'] for m in profile['memberships']} - if subdomain in memberships.keys(): - msg = f'Membership confirmed. Role is "{memberships[subdomain]}", stored in {config_file_path()}.' + for membership in memberships.keys(): + msg = f'Membership confirmed. Role is "{memberships[membership]}", stored in {config_file_path()}.' ArcsecondAPI._echo_message(state, msg) - config_file_save_organisation_membership(subdomain, memberships[subdomain], state.config_section()) + config_file_save_organisation_membership(membership, memberships[membership], state.config_section()) else: ArcsecondAPI._echo_message(state, 'Membership denied.') @@ -281,8 +254,7 @@ def login(cls, username, password, subdomain, state=None, **kwargs): elif result: # We replace result and error of login with that of api key result, error = ArcsecondAPI._get_and_save_api_key(state, username, result['key']) - if subdomain: - ArcsecondAPI._check_organisation_membership(state, username, subdomain) + ArcsecondAPI._check_memberships(state, username) return result, error @classmethod diff --git a/arcsecond/cli.py b/arcsecond/cli.py index c2041af..4a238c2 100644 --- a/arcsecond/cli.py +++ b/arcsecond/cli.py @@ -1,7 +1,7 @@ import click from . import __version__ -from .api import Arcsecond, ArcsecondError +from .api import ArcsecondAPI, ArcsecondError from .api.helpers import make_coords_dict from .config import config_file_read_username from .options import MethodChoiceParamType, State, basic_options, open_options, organisation_options @@ -37,7 +37,7 @@ def version(): @pass_state def register(state, username, email, password1, password2): """Register for a free personal Arcsecond.io account, and retrieve the associated API key.""" - Arcsecond.register(username, email, password1, password2, state) + ArcsecondAPI.register(username, email, password1, password2, state) @main.command(help='Login to a personal Arcsecond.io account') @@ -48,7 +48,7 @@ def register(state, username, email, password1, password2): @pass_state def login(state, username, password, organisation=None): """Login to your personal Arcsecond.io account, and retrieve the associated API key.""" - Arcsecond.login(username, password, organisation, state) + ArcsecondAPI.login(username, password, organisation, state) @main.command(help='Fetch your complete user profile.') @@ -60,7 +60,7 @@ def me(state): if not username: msg = 'Invalid/missing username: {}. Make sure to login first: $ arcsecond login'.format(username) raise ArcsecondError(msg) - Arcsecond.build_me_api(state).read(username) + ArcsecondAPI.me(state).read(username) @main.command(help='Request an object.') @@ -74,7 +74,7 @@ def objects(state, name): The NED information, as well as being able to choose the source will be implemented in the future. """ - Arcsecond.build_objects_api(state).read(name) + ArcsecondAPI.objects(state).read(name) @main.command(help='Request an exoplanet (in the /exoplanets// API endpoint)') @@ -82,7 +82,7 @@ def objects(state, name): @open_options @pass_state def exoplanets(state, name): - Arcsecond.build_exoplanets_api(state).read(name) + ArcsecondAPI.exoplanets(state).read(name) @main.command(help='Request the list of object finding charts (in the /findingcharts// API endpoint)') @@ -90,38 +90,38 @@ def exoplanets(state, name): @open_options @pass_state def findingcharts(state, name): - Arcsecond.build_findingcharts_api(state).list(name=name) + ArcsecondAPI.findingcharts(state).list(name=name) @main.command(help='Request the list of observing sites (in the /observingsites/ API endpoint)') @open_options @pass_state def sites(state): - Arcsecond.build_observingsites_api(state).list() + ArcsecondAPI.observingsites(state).list() @main.command(help='Request the list of telescopes (in the /telescopes/ API endpoint)') @open_options @pass_state def telescopes(state): - Arcsecond.build_telescopes_api(state).list() + ArcsecondAPI.telescopes(state).list() @main.command(help='Request the list of instruments (in the /instruments/ API endpoint)') @open_options @pass_state def instruments(state, name): - Arcsecond.build_instruments_api(state).list() + ArcsecondAPI.instruments(state).list() @main.command(help='Request your own list of observing runs (in the /observingruns/ API endpoint)') @click.argument('method', required=False, nargs=1, type=MethodChoiceParamType(), default='read') -@click.argument('uuid', required=False, nargs=1) +@click.argument('uuid', required=False, nargs=1, type=click.UUID) @click.option('--name', required=False, nargs=1, help="The observing run name.") @organisation_options @pass_state def runs(state, method, uuid, **kwargs): - api = Arcsecond.build_observingruns_api(state) + api = ArcsecondAPI.observingruns(state) if method == 'create': api.create(kwargs) # the kwargs dict is the payload! elif method == 'read': @@ -136,12 +136,12 @@ def runs(state, method, uuid, **kwargs): @main.command(help='Request your own list of night logs (in the /nightlogs/ API endpoint)') @click.argument('method', required=False, nargs=1, type=MethodChoiceParamType(), default='read') -@click.argument('uuid', required=False, nargs=1) +@click.argument('uuid', required=False, nargs=1, type=click.UUID) @click.option('--name', required=False, nargs=1, help="The log name.") @organisation_options @pass_state def logs(state, method, uuid, **kwargs): - api = Arcsecond.build_nightlogs_api(state) + api = ArcsecondAPI.nightlogs(state) if method == 'create': api.create(kwargs) # the kwargs dict is the payload! elif method == 'read': @@ -156,11 +156,11 @@ def logs(state, method, uuid, **kwargs): @main.command(help='Request your own list of observations (in the /observations/ API endpoint)') @click.argument('method', required=False, nargs=1, type=MethodChoiceParamType(), default='read') -@click.argument('uuid', required=False, nargs=1) +@click.argument('uuid', required=False, nargs=1, type=click.UUID) @organisation_options @pass_state def observations(state, method, uuid, **kwargs): - api = Arcsecond.build_observations_api(state) + api = ArcsecondAPI.observations(state) if method == 'create': api.create(kwargs) # the kwargs dict is the payload! elif method == 'read': @@ -175,11 +175,11 @@ def observations(state, method, uuid, **kwargs): @main.command(help='Request your own list of calibrations (in the /calibrations/ API endpoint)') @click.argument('method', required=False, nargs=1, type=MethodChoiceParamType(), default='read') -@click.argument('uuid', required=False, nargs=1) +@click.argument('uuid', required=False, nargs=1, type=click.UUID) @organisation_options @pass_state def calibrations(state, method, uuid, **kwargs): - api = Arcsecond.build_calibrations_api(state) + api = ArcsecondAPI.calibrations(state) if method == 'create': api.create(kwargs) # the kwargs dict is the payload! elif method == 'read': @@ -210,7 +210,7 @@ def calibrations(state, method, uuid, **kwargs): @open_options @pass_state def activities(state, method, pk, **kwargs): - api = Arcsecond.build_activities_api(state) + api = ArcsecondAPI.activities(state) if method == 'create': kwargs.update(coordinates=make_coords_dict(kwargs)) api.create(kwargs) # the kwargs dict is the payload! @@ -226,12 +226,12 @@ def activities(state, method, pk, **kwargs): @main.command(help='Access and modify your own datasets (in the /datasets/ API endpoint)') @click.argument('method', required=False, nargs=1, type=MethodChoiceParamType(), default='read') -@click.argument('uuid', required=False, nargs=1) +@click.argument('uuid', required=False, nargs=1, type=click.UUID) @click.option('--name', required=False, nargs=1, help="The dataset name.") @organisation_options @pass_state def datasets(state, method, uuid, **kwargs): - api = Arcsecond.build_datasets_api(state) + api = ArcsecondAPI.datasets(state) if method == 'create': api.create(kwargs) # the kwargs dict is the payload! elif method == 'read': @@ -263,7 +263,7 @@ def datafiles(state, dataset, method, pk, **kwargs): if state.organisation: # If organisation is provided as argument, don't put in payload too! kwargs.pop('organisation') - api = Arcsecond.build_datafiles_api(state=state, dataset=dataset) + api = ArcsecondAPI.datafiles(state=state, dataset=dataset) if method == 'create': api.create(kwargs) # the kwargs dict is the payload! elif method == 'read': @@ -289,7 +289,7 @@ def satellites(state, catalogue_number): Data is extracted from celestrak.com. """ # If catalogue_number is None, ArcsecondAPI fallback to .list() - Arcsecond.build_satellites_api(state).read(catalogue_number) + ArcsecondAPI.satellites(state).read(catalogue_number) @main.command(help='Read telegrams (ATel)') @@ -302,7 +302,7 @@ def telegrams(state, identifier): The other sources of telegrams will be added in the future. """ # If catalogue_number is None, ArcsecondAPI fallback to .list() - Arcsecond.build_telegrams_api(state).read(identifier) + ArcsecondAPI.telegrams(state).read(identifier) @main.command(help='Read catalogues (standard stars)') @@ -314,7 +314,7 @@ def catalogues(state, identifier, rows): """Request the list of identifier or the details of one (in the /catalogues/ API endpoint). """ - api = Arcsecond.build_catalogues_api(state) + api = ArcsecondAPI.catalogues(state) if identifier: identifier = identifier + '/rows' if rows else identifier api.read(identifier) @@ -334,4 +334,4 @@ def standardstars(state, around, count=5): Coordinates are assumed to be Equatorial, with epoch J2000. """ - Arcsecond.build_standardstars_api(state).list() + ArcsecondAPI.standardstars(state).list() diff --git a/arcsecond/options.py b/arcsecond/options.py index d25cfa5..170f1c8 100644 --- a/arcsecond/options.py +++ b/arcsecond/options.py @@ -125,7 +125,7 @@ class MethodChoiceParamType(click.ParamType): name = 'method' def __init__(self, *args): - super(MethodChoiceParamType, self).__init__() + super().__init__() self.allowed_methods = args or ['list', 'create', 'read', 'update', 'delete'] def convert(self, value, param, ctx): diff --git a/tests/cli/test_activities.py b/tests/cli/test_activities.py index a0862c8..dd268c8 100644 --- a/tests/cli/test_activities.py +++ b/tests/cli/test_activities.py @@ -7,13 +7,13 @@ from arcsecond import cli from arcsecond.api.constants import ARCSECOND_API_URL_DEV from arcsecond.api.error import ArcsecondInputValueError -from tests.utils import register_successful_personal_login +from tests.utils import register_successful_login @httpretty.activate def test_activities_with_valid_coordinates(): runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) site_uuid = str(uuid.uuid4()) coords_ra = 2.33 coords_dec = 4.55 @@ -38,7 +38,7 @@ def request_callback(request, uri, response_headers): @httpretty.activate def test_activities_with_invalid_coordinates(): runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) site_uuid = str(uuid.uuid4()) coords_ra = 2.33 coords_dec = 4.55 @@ -51,7 +51,7 @@ def test_activities_with_invalid_coordinates(): @httpretty.activate def test_activities_with_invalid_coordinates2(): runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) site_uuid = str(uuid.uuid4()) coords_ra = 2.33 coords_dec = 4.55 @@ -64,7 +64,7 @@ def test_activities_with_invalid_coordinates2(): @httpretty.activate def test_activities_with_invalid_coordinates3(): runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) site_uuid = str(uuid.uuid4()) coords_ra = 2.33 coords = "yoyo,{}".format(coords_ra) diff --git a/tests/cli/test_datasets_organisations.py b/tests/cli/test_datasets_organisations.py index c03293f..5fd0cdc 100644 --- a/tests/cli/test_datasets_organisations.py +++ b/tests/cli/test_datasets_organisations.py @@ -6,8 +6,8 @@ from arcsecond.api.error import ArcsecondError from arcsecond.config import config_file_clear_section -from tests.utils import (register_successful_personal_login, - register_successful_organisation_login, +from tests.utils import (register_successful_login, + register_successful_login, mock_http_get, mock_http_post) @@ -23,21 +23,21 @@ def tearDown(self): def test_datasets_list_unlogged(self): """As a simple user, I must not be able to access the list of datasets of an organisation.""" runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) result = runner.invoke(cli.datasets, ['--organisation', 'saao', '-d']) assert result.exit_code != 0 and isinstance(result.exception, ArcsecondError) def test_organisation_GET_datasets_list_logged_but_wrong_organisation(self): """No matter role I have, accessing an unknown organisation must fail.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'superadmin') + register_successful_login(runner, 'saao', 'superadmin') result = runner.invoke(cli.datasets, ['--organisation', 'dummy', '-d']) assert result.exit_code != 0 and isinstance(result.exception, ArcsecondError) def test_organisation_GET_datasets_list_valid_role(self): """As a SAAO superadmin, I must be able to access the list of datasets.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'superadmin') + register_successful_login(runner, 'saao', 'superadmin') mock_http_get('/saao/datasets/', '[]') result = runner.invoke(cli.datasets, ['--organisation', 'saao', '-d']) assert result.exit_code == 0 and not result.exception @@ -45,7 +45,7 @@ def test_organisation_GET_datasets_list_valid_role(self): def test_organisation_POST_datasets_list_valid_superadmin_role(self): """As a SAAO superadmin, I must be able to create a dataset.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'superadmin') + register_successful_login(runner, 'saao', 'superadmin') mock_http_post('/saao/datasets/', '[]') result = runner.invoke(cli.datasets, ['create', '--organisation', 'saao', '-d']) assert result.exit_code == 0 and not result.exception @@ -53,7 +53,7 @@ def test_organisation_POST_datasets_list_valid_superadmin_role(self): def test_organisation_POST_datasets_list_valid_admin_role(self): """As a SAAO admin, I must be able to create a dataset.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'admin') + register_successful_login(runner, 'saao', 'admin') mock_http_post('/saao/datasets/', '[]') result = runner.invoke(cli.datasets, ['create', '--organisation', 'saao', '-d']) assert result.exit_code == 0 and not result.exception @@ -61,7 +61,7 @@ def test_organisation_POST_datasets_list_valid_admin_role(self): def test_organisation_POST_datasets_list_valid_member_role(self): """As a SAAO member, I must be able to create a dataset.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'member') + register_successful_login(runner, 'saao', 'member') mock_http_post('/saao/datasets/', '[]') result = runner.invoke(cli.datasets, ['create', '--organisation', 'saao', '-d']) assert result.exit_code == 0 and not result.exception @@ -69,7 +69,7 @@ def test_organisation_POST_datasets_list_valid_member_role(self): def test_organisation_POST_datasets_list_invalid_guest_role(self): """As a SAAO guest, I must not be able to create a dataset.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'guest') + register_successful_login(runner, 'saao', 'guest') mock_http_post('/saao/datasets/', '[]') result = runner.invoke(cli.datasets, ['create', '--organisation', 'saao', '-d']) assert result.exit_code != 0 and isinstance(result.exception, ArcsecondError) diff --git a/tests/cli/test_datasets_personal.py b/tests/cli/test_datasets_personal.py index 1e59be2..b413660 100644 --- a/tests/cli/test_datasets_personal.py +++ b/tests/cli/test_datasets_personal.py @@ -7,13 +7,13 @@ from arcsecond import cli from arcsecond.api.constants import ARCSECOND_API_URL_DEV -from tests.utils import register_successful_personal_login +from tests.utils import register_successful_login @httpretty.activate def test_empty_datasets_list(): runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) httpretty.register_uri( httpretty.GET, @@ -30,7 +30,7 @@ def test_empty_datasets_list(): @httpretty.activate def test_datafiles_list_of_datasets(): runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) dataset_uuid = uuid.uuid4() httpretty.register_uri( @@ -48,7 +48,7 @@ def test_datafiles_list_of_datasets(): @httpretty.activate def test_datafiles_create_with_file(): runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) dataset_uuid = uuid.uuid4() httpretty.register_uri( diff --git a/tests/cli/test_nightlogs_organisations.py b/tests/cli/test_nightlogs_organisations.py index fd35388..2746e7c 100644 --- a/tests/cli/test_nightlogs_organisations.py +++ b/tests/cli/test_nightlogs_organisations.py @@ -2,13 +2,13 @@ from click.testing import CliRunner from unittest import TestCase -from arcsecond import cli, Arcsecond +from arcsecond import cli, ArcsecondAPI from arcsecond.api.error import ArcsecondError from arcsecond.config import config_file_clear_section, config_file_save_api_key, \ config_file_save_organisation_membership -from tests.utils import (register_successful_personal_login, - register_successful_organisation_login, +from tests.utils import (register_successful_login, + register_successful_login, mock_http_get, mock_http_post, mock_url_path) @@ -25,21 +25,21 @@ def tearDown(self): def test_nightlogs_list_unlogged(self): """As a simple user, I must not be able to access the list of nightlogs of an organisation.""" runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) result = runner.invoke(cli.logs, ['--organisation', 'saao', '-d']) assert result.exit_code != 0 and isinstance(result.exception, ArcsecondError) def test_organisation_GET_nightlogs_list_logged_but_wrong_organisation(self): """No matter role I have, accessing an unknown organisation must fail.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'superadmin') + register_successful_login(runner, 'saao', 'superadmin') result = runner.invoke(cli.logs, ['--organisation', 'dummy', '-d']) assert result.exit_code != 0 and isinstance(result.exception, ArcsecondError) def test_organisation_GET_nightlogs_list_valid_role(self): """As a SAAO superadmin, I must be able to access the list of nightlogs.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'superadmin') + register_successful_login(runner, 'saao', 'superadmin') mock_http_get('/saao/nightlogs/', '[]') result = runner.invoke(cli.logs, ['--organisation', 'saao', '-d']) assert result.exit_code == 0 and not result.exception @@ -47,7 +47,7 @@ def test_organisation_GET_nightlogs_list_valid_role(self): def test_organisation_POST_nightlogs_list_valid_superadmin_role(self): """As a SAAO superadmin, I must be able to create a nightlog.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'superadmin') + register_successful_login(runner, 'saao', 'superadmin') mock_http_post('/saao/nightlogs/', '[]') result = runner.invoke(cli.logs, ['create', '--organisation', 'saao', '-d']) assert result.exit_code == 0 and not result.exception @@ -55,7 +55,7 @@ def test_organisation_POST_nightlogs_list_valid_superadmin_role(self): def test_organisation_POST_nightlogs_list_valid_admin_role(self): """As a SAAO admin, I must be able to create a nightlog.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'admin') + register_successful_login(runner, 'saao', 'admin') mock_http_post('/saao/nightlogs/', '[]') result = runner.invoke(cli.logs, ['create', '--organisation', 'saao', '-d']) assert result.exit_code == 0 and not result.exception @@ -63,7 +63,7 @@ def test_organisation_POST_nightlogs_list_valid_admin_role(self): def test_organisation_POST_nightlogs_list_valid_member_role(self): """As a SAAO member, I must be able to create a nightlog.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'member') + register_successful_login(runner, 'saao', 'member') mock_http_post('/saao/nightlogs/', '[]') result = runner.invoke(cli.logs, ['create', '--organisation', 'saao', '-d']) assert result.exit_code == 0 and not result.exception @@ -71,7 +71,7 @@ def test_organisation_POST_nightlogs_list_valid_member_role(self): def test_organisation_POST_nightlogs_list_invalid_guest_role(self): """As a SAAO guest, I must not be able to create a nightlog.""" runner = CliRunner() - register_successful_organisation_login(runner, 'saao', 'guest') + register_successful_login(runner, 'saao', 'guest') mock_http_post('/saao/nightlogs/', '[]') result = runner.invoke(cli.logs, ['create', '--organisation', 'saao', '-d']) assert result.exit_code != 0 and isinstance(result.exception, ArcsecondError) @@ -89,7 +89,7 @@ def tearDown(self): 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 = Arcsecond.build_nightlogs_api(debug=True, test=True, organisation='saao') + 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') diff --git a/tests/module/test_arcsecond_root.py b/tests/module/test_arcsecond_root.py index c4f0cdb..36dfe0f 100644 --- a/tests/module/test_arcsecond_root.py +++ b/tests/module/test_arcsecond_root.py @@ -1,23 +1,23 @@ -from arcsecond import Arcsecond +from arcsecond import ArcsecondAPI from tests.utils import save_test_credentials, clear_test_credentials def test_default_empty_state(): clear_test_credentials() - assert Arcsecond.is_logged_in(debug=True) is False - assert Arcsecond.username(debug=True) == '' - assert Arcsecond.memberships(debug=True) == {} + assert ArcsecondAPI.is_logged_in(debug=True) is False + assert ArcsecondAPI.username(debug=True) == '' + assert ArcsecondAPI.memberships(debug=True) == {} def test_default_logged_in_state(): save_test_credentials('cedric') - assert Arcsecond.is_logged_in(debug=True) is True - assert Arcsecond.username(debug=True) == 'cedric' - assert Arcsecond.memberships(debug=True) == {} + assert ArcsecondAPI.is_logged_in(debug=True) is True + assert ArcsecondAPI.username(debug=True) == 'cedric' + assert ArcsecondAPI.memberships(debug=True) == {} def test_default_logged_in_with_membership_state(): save_test_credentials('cedric', {'saao': 'superadmin'}) - assert Arcsecond.is_logged_in(debug=True) is True - assert Arcsecond.username(debug=True) == 'cedric' - assert Arcsecond.memberships(debug=True) == {'saao': 'superadmin'} + assert ArcsecondAPI.is_logged_in(debug=True) is True + assert ArcsecondAPI.username(debug=True) == 'cedric' + assert ArcsecondAPI.memberships(debug=True) == {'saao': 'superadmin'} diff --git a/tests/module/test_datafiles_upload.py b/tests/module/test_datafiles_upload.py index 5e426e8..b690655 100644 --- a/tests/module/test_datafiles_upload.py +++ b/tests/module/test_datafiles_upload.py @@ -5,9 +5,9 @@ import httpretty from click.testing import CliRunner -from arcsecond import Arcsecond +from arcsecond import ArcsecondAPI from arcsecond.api.constants import ARCSECOND_API_URL_DEV -from tests.utils import register_successful_personal_login +from tests.utils import register_successful_login has_callback_been_called = False @@ -16,7 +16,7 @@ def test_datafiles_upload_file_threaded_no_callback(): # Using standard CLI runner to make sure we login successfuly as in other tests. runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) dataset_uuid = uuid.uuid4() httpretty.register_uri( @@ -27,7 +27,7 @@ def test_datafiles_upload_file_threaded_no_callback(): ) # Go for Python module tests - datafiles_api = Arcsecond.build_datafiles_api(debug=True, dataset=str(dataset_uuid)) + datafiles_api = ArcsecondAPI.datafiles(debug=True, dataset=str(dataset_uuid)) uploader, _ = datafiles_api.create({'file': os.path.abspath(__file__)}) uploader.start() time.sleep(0.1) @@ -41,7 +41,7 @@ def test_datafiles_upload_file_threaded_no_callback(): def test_datafiles_upload_file_threaded_with_callback(): # Using standard CLI runner to make sure we login successfuly as in other tests. runner = CliRunner() - register_successful_personal_login(runner) + register_successful_login(runner) dataset_uuid = uuid.uuid4() httpretty.register_uri( @@ -58,7 +58,7 @@ def upload_callback(eventName, progress): fixtures_folder = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'fixtures') # Go for Python module tests - datafiles_api = Arcsecond.build_datafiles_api(debug=True, dataset=str(dataset_uuid)) + datafiles_api = ArcsecondAPI.datafiles(debug=True, dataset=str(dataset_uuid)) payload = {'file': os.path.join(fixtures_folder, 'file1.fits')} uploader, _ = datafiles_api.create(payload, callback=upload_callback) uploader.start() diff --git a/tests/utils.py b/tests/utils.py index 6ffb4c6..5fa6cf8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -40,7 +40,7 @@ def make_profile_json(subdomain, role): return json.dumps(make_profile(subdomain, role)) -def register_successful_personal_login(runner): +def register_successful_login(runner, subdomain='robotland', role='member'): httpretty.register_uri( httpretty.POST, ARCSECOND_API_URL_DEV + API_AUTH_PATH_LOGIN, @@ -49,20 +49,9 @@ def register_successful_personal_login(runner): ) httpretty.register_uri( httpretty.GET, - ARCSECOND_API_URL_DEV + '/profiles/' + TEST_LOGIN_USERNAME + '/keys/', - status=200, - body='{ "api_key": "' + TEST_API_KEY + '" }' - ) - result = runner.invoke(cli.login, ['-d'], input=TEST_LOGIN_USERNAME + '\n' + TEST_LOGIN_PASSWORD) - assert result.exit_code == 0 - - -def register_successful_organisation_login(runner, subdomain, role): - httpretty.register_uri( - httpretty.POST, - ARCSECOND_API_URL_DEV + API_AUTH_PATH_LOGIN, + ARCSECOND_API_URL_DEV + '/profiles/' + TEST_LOGIN_USERNAME + '/', status=200, - body='{ "key": "935e2b9e24c44581b4ef5f4c8e53213e935e2b9e24c44581b4ef5f4c8e53213e" }' + body=make_profile_json(subdomain, role) ) httpretty.register_uri( httpretty.GET, @@ -70,14 +59,7 @@ def register_successful_organisation_login(runner, subdomain, role): status=200, body='{ "api_key": "' + TEST_API_KEY + '" }' ) - httpretty.register_uri( - httpretty.GET, - ARCSECOND_API_URL_DEV + '/profiles/' + TEST_LOGIN_USERNAME + '/', - status=200, - body=make_profile_json(subdomain, role) - ) - result = runner.invoke(cli.login, ['--organisation', subdomain, '-d'], - input=TEST_LOGIN_USERNAME + '\n' + TEST_LOGIN_PASSWORD) + result = runner.invoke(cli.login, ['-d'], input=TEST_LOGIN_USERNAME + '\n' + TEST_LOGIN_PASSWORD) assert result.exit_code == 0