Skip to content
Snippets Groups Projects
Commit 8b61f901 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

count problematic cases

parent 9c53da19
No related branches found
No related tags found
1 merge request!231Resolve "auto-import of subject data"
......@@ -15,23 +15,28 @@ class Importer(object):
# type: (str, SubjectImportReader) -> None
self.filename = filename
self.reader = reader
self.added_count = 0;
self.added_count = 0
self.problematic_count = 0
def execute(self):
self.added_count = 0;
self.added_count = 0
self.problematic_count = 0
study_subjects = self.reader.load_data(self.filename)
for study_subject in study_subjects:
try:
if study_subject.study is None:
self.problematic_count += 1
logger.warn("Empty study found. Ignoring")
continue
elif study_subject.study.id != GLOBAL_STUDY_ID:
self.problematic_count += 1
logger.warn("Empty study found. Ignoring: " + study_subject.study.id)
continue
else:
self.import_study_subject(study_subject)
except:
self.problematic_count += 1
traceback.print_exc(file=sys.stdout)
logger.error("Problem with importing study subject: " + study_subject.screening_number)
......
......@@ -37,3 +37,35 @@ class TestImporter(TestCase):
self.assertEqual(study_subject_counter + 1, StudySubject.objects.count())
self.assertEqual(1, importer.added_count)
self.assertEqual(0, importer.problematic_count)
def test_import_invalid(self):
study_subjects = []
study_subject = StudySubject()
study_subject.screening_number = "Cov-123456"
study_subject.study = self.study
study_subjects.append(study_subject)
importer = Importer(filename="empty.csv", reader=MockReader(study_subjects))
study_subject_counter = StudySubject.objects.count()
importer.execute()
self.assertEqual(study_subject_counter, StudySubject.objects.count())
self.assertEqual(0, importer.added_count)
self.assertEqual(1, importer.problematic_count)
def test_import_no_study(self):
study_subjects = []
study_subject = StudySubject()
study_subject.screening_number = "Cov-123456"
study_subjects.append(study_subject)
importer = Importer(filename="empty.csv", reader=MockReader(study_subjects))
study_subject_counter = StudySubject.objects.count()
importer.execute()
self.assertEqual(study_subject_counter, StudySubject.objects.count())
self.assertEqual(0, importer.added_count)
self.assertEqual(1, importer.problematic_count)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment