Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog
## [Latest](https://github.com/int-brain-lab/ONE/commits/main) [3.2.0]
## [Latest](https://github.com/int-brain-lab/ONE/commits/main) [3.2.1]

### Modified

- improved test coverage

## [3.2.0]
This version adds session part properties to the ALFPath class and turns off save on delete by default.

### Added
Expand Down
2 changes: 1 addition & 1 deletion one/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""The Open Neurophysiology Environment (ONE) API."""
__version__ = '3.2.0'
__version__ = '3.2.1'
23 changes: 23 additions & 0 deletions one/tests/test_alyxclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,29 @@ def test_download_datasets(self):
data = json.load(json_file)
self.assertTrue(len(data) > 0)

@mock.patch('one.webclient.zipfile.ZipFile')
@mock.patch('one.webclient.http_download_file')
def test_download_cache_tables_auth(self, download_file_mock, zipfile_mock):
"""Test for AlyxClient.download_cache_tables with authentication.

NB: This test simply checks that alex is authenticated automatically before
downloading the tables.
"""
try:
token = self.ac._token
self.ac._token = None # Force re-authentication
with mock.patch.object(self.ac, 'authenticate') as mock_auth:
# When the URL is different from the database, no need to authenticate
self.ac.download_cache_tables('https://example.com/cache.zip')
mock_auth.assert_not_called()
download_file_mock.assert_called_once()
zipfile_mock.assert_called_once()
# When the URL is the same as the database, should authenticate
self.ac.download_cache_tables(self.ac.base_url + '/cache.zip')
mock_auth.assert_called_once()
finally:
self.ac._token = token


class TestMisc(unittest.TestCase):
def test_update_url_params(self):
Expand Down
18 changes: 15 additions & 3 deletions one/tests/test_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from iblutil.util import Bunch

from one import __version__
import one.api # required for patching SAVE_ON_DELETE
from one.api import ONE, One, OneAlyx
from one.util import (
validate_date_range, index_last_before, filter_datasets, _collection_spec,
Expand Down Expand Up @@ -102,11 +103,22 @@ def test_delete(self):
shutil.rmtree(self.one.eid2path(eid))
datasets = self.one._cache.datasets.loc[eid]
self.one._check_filesystem(datasets, update_exists=True, check_hash=False)
# Check that the cache tables are updated and saved upon delete
self.one.__del__()
self.assertFalse(self.one._cache.datasets.loc[eid, 'exists'].any())
# Save cache should not be called when SAVE_ON_DELETE is False
with mock.patch.object(one.api, 'SAVE_ON_DELETE', False), \
mock.patch.object(self.one, 'save_cache') as save_cache:
self.one.__del__()
save_cache.assert_not_called()
# Check that the cache tables are updated and saved upon delete with SAVE_ON_DELETE = True
self.one = One(mode='local', cache_dir=self.tempdir.name)
datasets = self.one._cache.datasets.loc[eid]
self.one._check_filesystem(datasets, update_exists=True, check_hash=False)
self.assertFalse(self.one._cache.datasets.loc[eid, 'exists'].any())
with mock.patch.object(one.api, 'SAVE_ON_DELETE', True):
self.one.__del__()
while Path(self.tempdir.name, '.lock').exists():
time.sleep(.1)
self.one = ONE(mode='local', cache_dir=self.tempdir.name)
self.one = One(mode='local', cache_dir=self.tempdir.name)
self.assertFalse(self.one._cache.datasets.loc[eid, 'exists'].any())

def test_list_subjects(self):
Expand Down