Skip to content

Commit

Permalink
Test register-files QC validation; improve setup.py get user
Browse files Browse the repository at this point in the history
  • Loading branch information
k1o0 committed Mar 14, 2024
1 parent aba9e1b commit 8c067a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions alyx/data/tests_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_dataset_filerecord(self):
self.assertTrue(new_mod_date > mod_date)

def test_dataset(self):
# Test dataset creation via the datasets endpoint
data = {
'name': 'some-dataset',
'dataset_type': 'dst',
Expand Down Expand Up @@ -172,6 +173,7 @@ def test_dataset(self):
self.assertEqual(r.data['revision'], None)
self.assertEqual(r.data['collection'], data['collection'])
self.assertEqual(r.data['default_dataset'], True)
self.assertEqual(r.data['qc'], 'PASS')
data_url = r.data['url']

# But if we change the collection, we are okay
Expand Down Expand Up @@ -345,6 +347,24 @@ def test_register_files_hostname(self):
self.assertEqual(ds0.version, '1.1.1')
self.assertEqual(ds1.version, '2.2.2')

def test_qc_validation(self):
# this tests the validation of dataset QC outcomes
data = {
'path': '%s/2018-01-01/2/dir' % self.subject,
'filenames': 'a.b.e1,a.c.e2',
'hostname': 'hostname',
'qc': '10,critical' # Both numerical and string QC values should be parsed
}
r = self.post(reverse('register-file'), data)
records = self.ar(r, 201)
self.assertEqual([10, 50], [rec['qc'] for rec in records])
self._assert_registration(r, data)
# a single QC value should be applied to all datasets
data['qc'] = 'FAIL'
r = self.post(reverse('register-file'), data)
records = self.ar(r, 201)
self.assertEqual([40, 40], [rec['qc'] for rec in records])

def test_register_files_hash(self):
# this is old use case where we register one dataset according to the hostname, no need
# for a lab in this case
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

from pathlib import Path
from getpass import getpass
from getpass import getpass, getuser
import os
import os.path as op
import platform
Expand Down Expand Up @@ -141,8 +141,8 @@ def _replace_in_file(source_file, target_file, replacements=None, target_mode='w
try:
_system(f'sudo mkdir -p {file_log_json.parent}')
_system(f'sudo mkdir -p {file_log.parent}')
_system(f'sudo chown {os.getlogin()}:www-data -fR {file_log.parent}')
_system(f'sudo chown {os.getlogin()}:www-data -fR {file_log_json.parent}')
_system(f'sudo chown {getuser()}:www-data -fR {file_log.parent}')
_system(f'sudo chown {getuser()}:www-data -fR {file_log_json.parent}')
_system(f'touch {file_log_json}')
_system(f'touch {file_log}')
_system('python3 alyx/manage.py makemigrations')
Expand Down

0 comments on commit 8c067a8

Please sign in to comment.