Skip to content

Commit 831ef16

Browse files
committed
check for protected datasets
1 parent 63c6f24 commit 831ef16

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

ibllib/oneibl/registration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def register_dataset(file_list, one=None, exists=False, versions=None, **kwargs)
8484
# Account for cases where we are connected to cortex lab database
8585
if one.alyx.base_url == 'https://alyx.cortexlab.net':
8686
protected_status = IBLRegistrationClient(
87-
ONE(base_url='https://alyx.internationalbrainlab.org')).check_protected_files(file_list)
87+
ONE(base_url='https://alyx.internationalbrainlab.org', mode='remote')).check_protected_files(file_list)
8888
else:
8989
protected_status = client.check_protected_files(file_list)
9090

@@ -95,8 +95,8 @@ def register_dataset(file_list, one=None, exists=False, versions=None, **kwargs)
9595

9696
# If we find a protected dataset, and we don't have a force=True flag, raise an error
9797
if protected and not kwargs.pop('force', False):
98-
raise (FileExistsError, 'Protected datasets were found in the file list. To force the registration of datasets '
99-
'add the force=True argument.')
98+
raise FileExistsError('Protected datasets were found in the file list. To force the registration of datasets '
99+
'add the force=True argument.')
100100

101101
# If the repository is specified then for the registration client we want server_only=True to
102102
# make sure we don't make any other repositories for the lab

ibllib/tests/test_oneibl.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,14 @@ def test_registration_datasets(self):
332332
self.one.alyx.rest('datasets', 'partial_update',
333333
id=d['url'][-36:], data={'tags': [self.tag['name']]})
334334

335+
# Check that we get an exception error unless force=True
336+
flist = list(self.rev_path.glob('*.npy'))
337+
with self.assertRaises(FileExistsError):
338+
registration.register_dataset(file_list=flist, one=self.one)
339+
335340
# Test registering with a revision already in the file path, should use this rather than create one with today's date
336341
flist = list(self.rev_path.glob('*.npy'))
337-
r = registration.register_dataset(file_list=flist, one=self.one)
342+
r = registration.register_dataset(file_list=flist, one=self.one, force=True)
338343
self.assertTrue(all(d['revision'] == self.revision for d in r))
339344
self.assertTrue(all(d['default'] for d in r))
340345
self.assertTrue(all(d['collection'] == 'alf' for d in r))
@@ -348,7 +353,7 @@ def test_registration_datasets(self):
348353
# Register again with revision in file path, it should register to self.revision + a
349354
flist = list(self.rev_path.glob('*.npy'))
350355

351-
r = registration.register_dataset(file_list=flist, one=self.one)
356+
r = registration.register_dataset(file_list=flist, one=self.one, force=True)
352357
self.assertTrue(all(d['revision'] == f'{self.revision}a' for d in r))
353358
self.assertTrue(self.alf_path.joinpath(f'#{self.revision}a#', 'spikes.times.npy').exists())
354359
self.assertTrue(self.alf_path.joinpath(f'#{self.revision}a#', 'spikes.amps.npy').exists())
@@ -357,7 +362,7 @@ def test_registration_datasets(self):
357362

358363
# When we re-register the original it should move them into revision with today's date
359364
flist = list(self.alf_path.glob('*.npy'))
360-
r = registration.register_dataset(file_list=flist, one=self.one)
365+
r = registration.register_dataset(file_list=flist, one=self.one, force=True)
361366
self.assertTrue(all(d['revision'] == self.today_revision for d in r))
362367
self.assertTrue(self.alf_path.joinpath(f'#{self.today_revision}#', 'spikes.times.npy').exists())
363368
self.assertTrue(self.alf_path.joinpath(f'#{self.today_revision}#', 'spikes.amps.npy').exists())
@@ -375,7 +380,7 @@ def test_registration_datasets(self):
375380
np.save(self.alf_path.joinpath('spikes.times.npy'), np.random.random(500))
376381
np.save(self.alf_path.joinpath('spikes.amps.npy'), np.random.random(500))
377382
flist = list(self.alf_path.glob('*.npy'))
378-
r = registration.register_dataset(file_list=flist, one=self.one)
383+
r = registration.register_dataset(file_list=flist, one=self.one, force=True)
379384
self.assertTrue(all(d['revision'] == self.today_revision + 'a' for d in r))
380385

381386
def _write_settings_file(self):

0 commit comments

Comments
 (0)