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
| Test methods that use sessions and datasets tables. | |
| Test OneAlyx methods that use the Alyx REST API. | |
| Test downloading datasets using OpenAlyx. | |
| Test functions in one.util. | |
| Test remote queries using OpenAlyx. | |
| 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
 - test_mode_validation()[source]
- Test validation of mode kwarg. - Since auto and refresh modes were removed, a ValueError should be raised. 
 
- class TestOneAlyx(methodName='runTest')[source]
- Bases: - TestCase- Test OneAlyx methods that use the Alyx REST API. - 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]
- Ensure the ONE mode is local and that the cache isn’t saved when ONE is deleted. 
 - test_pid2eid()[source]
- Test OneAlyx.pid2eid. - For a more complete test see test_converters.TestOnlineConverters.test_pid2eid. This test uses the REST fixtures and therefore can be run offline. 
 - test_describe_dataset(mock_stdout)[source]
- Test OneAlyx.describe_dataset. - NB This could be offline: REST responses in fixtures. 
 
- class TestOneRemote(methodName='runTest')[source]
- Bases: - TestCase- Test remote queries using OpenAlyx. 
- class TestOneDownload(methodName='runTest')[source]
- Bases: - TestCase- Test downloading datasets using OpenAlyx. - tempdir = None
 - one = None
 
- class TestOneSetup(methodName='runTest')[source]
- Bases: - TestCase- Test parameter setup upon ONE instantiation and calling setup methods. - test_local_tables_only()[source]
- Test first time instantiation of ONE with only tables_dir arg. - Previously this would have raised and AttributeError as cache_map.DEFAULT doesn’t exist on a new install. 
 - 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