one.tests.test_one

Tests for the one.api module

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

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

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 This class loads the parquet tables from the fixtures and builds a file tree in a temp folder

TestOneAlyx

This could be an offline test.

TestOneDownload

Test downloading datasets using OpenAlyx

TestOneMisc

TestOneRemote

Test remote queries

TestOneSetup

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

Bases: unittest.case.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
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.

classmethod tearDownClass() → None[source]

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

test_list_subjects()[source]
test_offline_repr()[source]
test_check_exists()[source]
test_filter()[source]
test_filter_wildcards()[source]
test_list_datasets()[source]
test_list_collections()[source]
test_list_revisions()[source]

No revisions in cache fixture so generate our own

test_get_details()[source]
test_index_type()[source]
test_load_dataset()[source]
test_load_datasets()[source]
test_load_dataset_from_id()[source]
test_load_object()[source]
test_load_cache()[source]
test_refresh_cache()[source]
class TestOneAlyx(methodName='runTest')[source]

Bases: unittest.case.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.

test_type2datasets()[source]
test_ses2records()[source]
test_datasets2records()[source]
test_pid2eid()[source]
test_describe_revision(mock_stdout)[source]
test_describe_dataset(mock_stdout)[source]

NB This could be offline: REST responses in fixtures

test_url_from_path()[source]
test_url_from_record()[source]
classmethod tearDownClass() → None[source]

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

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

Bases: unittest.case.TestCase

Test remote queries

setUp() → None[source]

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

test_online_repr()[source]
test_list_datasets()[source]
test_load_dataset()[source]
test_load_object()[source]
class TestOneDownload(methodName='runTest')[source]

Bases: unittest.case.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]
tearDown() → None[source]

Hook method for deconstructing the test fixture after testing it.

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

Bases: unittest.case.TestCase

setUp() → None[source]

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

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()[source]
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: unittest.case.TestCase

test_validate_date_range()[source]
test_index_last_before()[source]
test_collection_spec()[source]
test_revision_last_before()[source]
test_parse_id()[source]
test_autocomplete()[source]
test_LazyID()[source]