one.tests.test_one

Unit tests for the one.api module.

Wherever possible the ONE tests should not rely on an internet connection.

Fixture locations:

  • The cache tables for the public test instance are in tests/fixtures/

  • The test db parameters can be found in tests/fixtures/params/

  • Some REST GET requests can be found in tests/fixtures/rest_responses/

  • These can be copied over to a temporary directory using the functions in tests/util.py, then construct ONE with the directory as cache_dir, mode=’local’ and silent=True

Imported constants:

  • For tests that do require a remote connection use the tests.OFFLINE_ONLY flag in the skipIf decorator.

  • For testing REST POST requests use TEST_DB_1 (test.alyx.internationalbrainlab.org).

  • For testing download functions, use TEST_DB_2 (openalyx.internationalbrainlab.org).

Note ONE and AlyxClient use caching:

  • When verifying remote changes via the rest method, use the no_cache flag to ensure the remote databaseis queried. You can clear the cache using AlyxClient.clear_rest_cache(), or mock iblutil.io.params.getfile to return a temporary cache directory.

  • An One object created through the one.api.ONE function, make sure you restore the properties to their original state on teardown, or call one.api.ONE.cache_clear().

Classes

TestONECache

Test methods that use sessions and datasets tables.

TestOneAlyx

This could be an offline test.

TestOneDownload

Test downloading datasets using OpenAlyx.

TestOneMisc

Test functions in one.util.

TestOneRemote

Test remote queries using OpenAlyx

TestOneSetup

Test parameter setup upon ONE instantiation and calling setup methods.

class TestONECache(methodName='runTest')[source]

Bases: TestCase

Test methods that use sessions and datasets tables. This class loads the parquet tables from the fixtures and builds a file tree in a temp folder

tempdir = None
setUp() None[source]

Hook method for setting up the test fixture before exercising it.

tearDown() None[source]

Hook method for deconstructing the test fixture after testing it.

test_list_subjects()[source]

Test One.list_subejcts

test_offline_repr()[source]

Test for One.offline property

Test for One.search

test_filter()[source]

Test one.util.filter_datasets

test_filter_wildcards()[source]

Test one.util.filter_datasets with wildcards flag set to True

test_list_datasets()[source]

Test One.list_datasets

test_list_collections()[source]

Test One.list_collections

test_list_revisions()[source]

Test One.list_revisions

test_get_details()[source]

Test One.get_details

test_check_filesystem()[source]

Test for One._check_filesystem.

Most is already covered by other tests, this checks that it can deal with dataset frame without eid index and without a session_path column.

test_load_dataset()[source]

Test One.load_dataset

test_load_datasets()[source]

Test One.load_datasets

test_load_dataset_from_id()[source]

Test One.load_dataset_from_id

test_load_object()[source]

Test One.load_object

test_load_collection()[source]

Test One.load_collection

test_load_cache()[source]

Test One._load_cache

test_refresh_cache()[source]

Test One.refresh_cache

test_save_cache()[source]

Test one.util.save_cache

test_update_cache_from_records()[source]

Test One._update_cache_from_records

test_save_loaded_ids()[source]

Test One.save_loaded_ids and logic within One._check_filesystem

class TestOneAlyx(methodName='runTest')[source]

Bases: TestCase

This could be an offline test. Would need to add /docs REST cache fixture.

tempdir = None
one = None
classmethod setUpClass() None[source]

Hook method for setting up class fixture before running tests in the class.

tearDown() None[source]

Hook method for deconstructing the test fixture after testing it.

test_type2datasets()[source]

Test OneAlyx.type2datasets

test_dataset2type()[source]

Test for OneAlyx.dataset2type

test_ses2records()[source]

Test one.util.ses2records

test_datasets2records()[source]

Test one.util.datasets2records

test_pid2eid()[source]

Test OneAlyx.pid2eid

test_describe_revision(mock_stdout)[source]

Test OneAlyx.describe_revision

test_describe_dataset(mock_stdout)[source]

Test OneAlyx.describe_dataset. NB This could be offline: REST responses in fixtures.

test_url_from_path()[source]

Test OneAlyx.path2url

test_url_from_record()[source]

Test ConversionMixin.record2url

test_load_cache()[source]

Test loading the remote cache

test_check_filesystem()[source]

Test for One._check_filesystem. Most is already covered by other tests, this just checks that it can deal with dataset dicts as input.

test_download_aws(boto3_mock)[source]

Tests for the OneAlyx._download_aws method

test_list_aggregates()[source]

Test OneAlyx.list_aggregates

test_load_aggregate()[source]

Test OneAlyx.load_aggregate

classmethod tearDownClass() None[source]

Hook method for deconstructing the class fixture after running all tests in the class.

class TestOneRemote(methodName='runTest')[source]

Bases: TestCase

Test remote queries using OpenAlyx

setUp() None[source]

Hook method for setting up the test fixture before exercising it.

test_online_repr()[source]

Tests OneAlyx.__repr__

test_list_datasets()[source]

Test OneAlyx.list_datasets

Test OneAlyx.search method in remote mode.

test_search_insertions()[source]

Test OneAlyx.search_insertion method in remote mode.

test_search_terms()[source]

Test OneAlyx.search_terms.

test_load_dataset()[source]

Test OneAlyx.load_dataset.

test_load_object()[source]

Test OneAlyx.load_object.

test_get_details()[source]

Test OneAlyx.get_details.

class TestOneDownload(methodName='runTest')[source]

Bases: TestCase

Test downloading datasets using OpenAlyx.

tempdir = None
one = None
setUp() None[source]

Hook method for setting up the test fixture before exercising it.

test_download_datasets()[source]

Test OneAlyx._download_dataset, _download_file and _dset2url.

test_download_aws()[source]

Test for OneAlyx._download_aws method.

test_tag_mismatched_file_record()[source]

Test for OneAlyx._tag_mismatched_file_record.

This method is also tested in test_download_datasets.

tearDown() None[source]

Hook method for deconstructing the test fixture after testing it.

class TestOneSetup(methodName='runTest')[source]

Bases: TestCase

Test parameter setup upon ONE instantiation and calling setup methods.

setUp() None[source]

Hook method for setting up the test fixture before exercising it.

test_local_cache_setup_prompt()[source]

Test One.setup.

test_setup_silent()[source]

Test setting up parameters with silent flag.

  • Mock getfile to return temp dir as param file location

  • Mock input function as fail safe in case function erroneously prompts user for input

test_setup_username()[source]

Test setting up parameters with a provided username.

  • Mock getfile to return temp dir as param file location

  • Mock input function as fail safe in case function erroneously prompts user for input

  • Mock requests.post returns a fake user authentication response

test_static_setup()[source]

Test OneAlyx.setup.

test_setup()[source]

Test one.params.setup.

test_patch_params()[source]

Test patching legacy params to the new location.

test_one_factory()[source]

Tests the ONE class factory.

class TestOneMisc(methodName='runTest')[source]

Bases: TestCase

Test functions in one.util.

test_validate_date_range()[source]

Test one.util.validate_date_range.

test_index_last_before()[source]

Test one.util.index_last_before.

test_collection_spec()[source]

Test one.util._collection_spec.

test_revision_last_before()[source]

Test one.util.filter_revision_last_before.

test_parse_id()[source]

Test one.util.parse_id.

test_autocomplete()[source]

Test one.util.autocomplete.

test_LazyID()[source]

Test one.util.LazyID.

test_ensure_list()[source]

Test one.util.ensure_list.

This function has now moved therefore we simply check for deprecation warning.