Exemple #1
0
    def test_nonadmin_cannot_set_subjects(self):
        initial_subjects = self.preprint.subjects
        with assert_raises(PermissionsError):
            self.preprint.set_subjects([[SubjectFactory()._id]], auth=Auth(self.write_contrib), save=True)

        self.preprint.reload()
        assert_equal(initial_subjects, self.preprint.subjects)
Exemple #2
0
    def setUp(self):
        super(TestTaxonomy, self).setUp()

        # Subject 1 has 3 children
        self.subject1 = SubjectFactory()
        self.subject1_child1 = SubjectFactory(parents=[self.subject1])
        self.subject1_child2 = SubjectFactory(parents=[self.subject1])

        # Subject 2 has a child whose parent is both subject 1 and subject 2
        self.subject2 = SubjectFactory()
        self.subject2_child1_subject1_child3 = SubjectFactory(parents=[self.subject1, self.subject2])

        self.subjects = Subject.find()
        self.url = '/{}taxonomies/'.format(API_BASE)
        self.res = self.app.get(self.url)
        self.data = self.res.json['data']
Exemple #3
0
    def test_admin_can_set_subjects(self):
        initial_subjects = self.preprint.subjects
        self.preprint.set_subjects([[SubjectFactory()._id]],
                                   auth=Auth(self.user),
                                   save=True)

        self.preprint.reload()
        assert_not_equal(initial_subjects, self.preprint.subjects)
Exemple #4
0
    def setUp(self):
        super(TestPreprintUpdate, self).setUp()
        self.user = AuthUserFactory()

        self.preprint = PreprintFactory(creator=self.user)
        self.url = '/{}preprints/{}/'.format(API_BASE, self.preprint._id)

        self.subject = SubjectFactory()
Exemple #5
0
    def setUpTestData(cls):
        load_common_sequences()
        cls.subject = SubjectFactory()
        Image.objects.import_path(
            DICOM_MPRAGE_PATH, progressbar=False, report=False
        )
        series_mprage = Series.objects.get(description__icontains="MPRAGE")
        Scan.objects.get_or_create(dicom=series_mprage, subject=cls.subject)
        Image.objects.import_path(
            DICOM_DWI_PATH, progressbar=False, report=False
        )
        series_dwi = Series.objects.get(description__icontains="ep2d")
        Scan.objects.get_or_create(dicom=series_dwi, subject=cls.subject)
        Image.objects.import_path(
            DICOM_FLAIR_PATH, progressbar=False, report=False
        )
        series_flair = Series.objects.get(description__icontains="FLAIR")
        Scan.objects.get_or_create(dicom=series_flair, subject=cls.subject)
        Image.objects.import_path(
            DICOM_FMRI_BOLD_PATH, progressbar=False, report=False
        )
        series_fmri_bold = Series.objects.get(description__icontains="FMRI")
        Scan.objects.get_or_create(dicom=series_fmri_bold, subject=cls.subject)
        Image.objects.import_path(
            DICOM_IREPI_PATH, progressbar=False, report=False
        )
        series_irepi = Series.objects.get(description__icontains="IR-EPI")
        Scan.objects.get_or_create(dicom=series_irepi, subject=cls.subject)

        dwi = SequenceType.objects.get(title="DWI")
        mprage = SequenceType.objects.get(title="MPRAGE")
        irepi = SequenceType.objects.get(title="IR-EPI")
        flair = SequenceType.objects.get(title="FLAIR")
        fmri_bold = SequenceType.objects.get(title="fMRI")

        cls.dwi_scan = [
            scan for scan in Scan.objects.all() if scan.sequence_type == dwi
        ][0]
        cls.mprage_scan = [
            scan for scan in Scan.objects.all() if scan.sequence_type == mprage
        ][0]
        cls.flair_scan = [
            scan for scan in Scan.objects.all() if scan.sequence_type == flair
        ][0]
        cls.irepi_scan = [
            scan for scan in Scan.objects.all() if scan.sequence_type == irepi
        ][0]
        cls.fmri_bold_scan = [
            scan
            for scan in Scan.objects.all()
            if scan.sequence_type == fmri_bold
        ][0]

        cls.mprage_nifti = cls.mprage_scan.nifti
        cls.dwi_nifti = cls.dwi_scan.nifti
        cls.flair_nifti = cls.flair_scan.nifti
        cls.irepi_nifti = cls.irepi_scan.nifti
        cls.fmri_bold_nifti = cls.fmri_bold_scan.nifti
 def setUpTestData(cls):
     subject = SubjectFactory()
     Image.objects.import_path(
         SIEMENS_DWI_SERIES_PATH, progressbar=False, report=False
     )
     cls.scan = Scan.objects.create(
         dicom=Image.objects.first().series, subject=subject
     )
     cls.analyses = Analysis.objects.from_list(analysis_definitions)
Exemple #7
0
 def test_project_made_public(self):
     assert_false(self.project.is_public)
     self.preprint.set_primary_file(self.file, auth=self.auth, save=True)
     assert_false(self.project.is_public)
     with assert_raises(ValueError):
         self.preprint.set_published(True, auth=self.auth, save=True)
     self.preprint.provider = PreprintProviderFactory()
     self.preprint.set_subjects([[SubjectFactory()._id]], auth=self.auth, save=True)
     self.project.reload()
     assert_false(self.project.is_public)
     self.preprint.set_published(True, auth=self.auth, save=True)
     self.project.reload()
     assert_true(self.project.is_public)
Exemple #8
0
    def setUp(self):
        super(TestPreprintFiltering, self).setUp()
        self.user = AuthUserFactory()
        self.provider = PreprintProviderFactory(name='wwe')
        self.provider_two = PreprintProviderFactory(name='wcw')

        self.subject = SubjectFactory()
        self.subject_two = SubjectFactory()

        self.preprint = PreprintFactory(creator=self.user,
                                        provider=self.provider,
                                        subjects=[[self.subject._id]])
        self.preprint_two = PreprintFactory(creator=self.user,
                                            filename='woo.txt',
                                            provider=self.provider_two,
                                            subjects=[[self.subject_two._id]])
        self.preprint_three = PreprintFactory(creator=self.user,
                                              filename='stonecold.txt',
                                              provider=self.provider,
                                              subjects=[[self.subject._id],
                                                        [self.subject_two._id]
                                                        ])
Exemple #9
0
 def setUpTestData(cls):
     subject = SubjectFactory()
     Image.objects.import_path(SIEMENS_DWI_SERIES_PATH,
                               progressbar=False,
                               report=False)
     cls.scan = Scan.objects.create(dicom=Image.objects.first().series,
                                    subject=subject)
     cls.definition = ScanInputDefinition.objects.create(key="test")
     version = AnalysisVersion.objects.create(title="TestVersion",
                                              description="desc")
     run = Run.objects.create(analysis_version=version)
     cls.input = ScanInput.objects.create(value=cls.scan,
                                          definition=cls.definition,
                                          run=run)
Exemple #10
0
 def test_create_preprint_adds_log_if_published(self):
     public_project_payload = build_preprint_create_payload(
         self.public_project._id, self.provider._id,
         self.file_one_public_project._id, {
             'is_published': True,
             'subjects': [[SubjectFactory()._id]],
         })
     res = self.app.post_json_api(self.url,
                                  public_project_payload,
                                  auth=self.user.auth)
     assert_equal(res.status_code, 201)
     preprint_id = res.json['data']['id']
     preprint = PreprintService.load(preprint_id)
     log = preprint.node.logs[-2]
     assert_equal(log.action, 'preprint_initiated')
     assert_equal(log.params.get('preprint'), preprint_id)
Exemple #11
0
 def setUpTestData(cls):
     load_common_sequences()
     subject = SubjectFactory()
     Image.objects.import_path(SIEMENS_DWI_SERIES_PATH,
                               progressbar=False,
                               report=False)
     series = Series.objects.first()
     scan = Scan.objects.create(dicom=series, subject=subject)
     cls.nifti = scan.nifti
     cls.definition = NiftiInputDefinition.objects.create(key="test")
     version = AnalysisVersion.objects.create(title="TestVersion",
                                              description="desc")
     run = Run.objects.create(analysis_version=version)
     cls.input = NiftiInput.objects.create(value=cls.nifti,
                                           definition=cls.definition,
                                           run=run)
Exemple #12
0
    def test_create_preprint_from_private_project(self):
        private_project_payload = build_preprint_create_payload(
            self.private_project._id,
            self.provider._id,
            self.file_one_private_project._id,
            attrs={
                'subjects': [[SubjectFactory()._id]],
                'is_published': True
            })
        res = self.app.post_json_api(self.url,
                                     private_project_payload,
                                     auth=self.user.auth)

        self.private_project.reload()
        assert_equal(res.status_code, 201)
        assert_true(self.private_project.is_public)
Exemple #13
0
    def setUp(self):
        super(TestPreprintCreate, self).setUp()

        self.user = AuthUserFactory()
        self.other_user = AuthUserFactory()
        self.private_project = ProjectFactory(creator=self.user)
        self.public_project = ProjectFactory(creator=self.user, public=True)
        self.public_project.add_contributor(self.other_user, permissions=[permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS], save=True)
        self.subject = SubjectFactory()

        self.user_two = AuthUserFactory()

        self.file_one_public_project = test_utils.create_test_file(self.public_project, self.user, 'millionsofdollars.pdf')
        self.file_one_private_project = test_utils.create_test_file(self.private_project, self.user, 'woowoowoo.pdf')

        self.url = '/{}preprints/'.format(API_BASE)
Exemple #14
0
    def setUp(self):
        super(TestOnPreprintUpdatedTask, self).setUp()
        self.user = AuthUserFactory()
        self.auth = Auth(user=self.user)
        self.preprint = PreprintFactory()

        self.preprint.node.add_tag('preprint', self.auth, save=False)
        self.preprint.node.add_tag('spoderman', self.auth, save=False)
        self.preprint.node.add_unregistered_contributor(
            'BoJack Horseman', '*****@*****.**',
            Auth(self.preprint.node.creator))
        self.preprint.node.add_contributor(self.user, visible=False)
        self.preprint.node.save()

        self.preprint.node.creator.given_name = 'ZZYZ'
        self.preprint.node.creator.save()

        self.preprint.set_subjects([[SubjectFactory()._id]],
                                   auth=Auth(self.preprint.node.creator),
                                   save=False)
Exemple #15
0
    def setUpTestData(cls):
        load_common_sequences()
        cls.subject = SubjectFactory()

        # MPRAGE scan
        Image.objects.import_path(DICOM_MPRAGE_PATH,
                                  progressbar=False,
                                  report=False)
        series = Image.objects.first().series
        cls.simple_scan = Scan.objects.create(dicom=series,
                                              subject=cls.subject)
        cls.simple_nifti = cls.simple_scan.nifti

        # DWI scan
        Image.objects.import_path(SIEMENS_DWI_SERIES_PATH,
                                  progressbar=False,
                                  report=False)
        series_dwi = Image.objects.last().series
        cls.dwi_scan = Scan.objects.create(dicom=series_dwi,
                                           subject=cls.subject)
        cls.dwi_nifti = cls.dwi_scan.nifti
Exemple #16
0
 def create_subject_rules(self):
     '''
     Subject Hierarchy
     +-----------------------------+
     |                    +-->E    |
     |      +-------->B+--+        |
     |      |             +-->F    |
     |  A+----------->C            |
     |      |                      |
     |      +-------->D+----->G    |
     |                             |
     |  H+------>I+----->J         |
     |            |                |
     |            +----->K         |
     |                             |
     |  L+------>M+----->N         |
     |            |                |
     |            +------->E       |
     |                             |
     |  O                          |
     +-----------------------------+
     '''
     self.subA = SubjectFactory(text='A')
     self.subB = SubjectFactory(text='B', parents=[self.subA])
     self.subC = SubjectFactory(text='C', parents=[self.subA])
     self.subD = SubjectFactory(text='D', parents=[self.subA])
     self.subF = SubjectFactory(text='F', parents=[self.subB])
     self.subG = SubjectFactory(text='G', parents=[self.subD])
     self.subH = SubjectFactory(text='H')
     self.subI = SubjectFactory(text='I', parents=[self.subH])
     self.subJ = SubjectFactory(text='J', parents=[self.subI])
     self.subK = SubjectFactory(text='K', parents=[self.subI])
     self.subL = SubjectFactory(text='L')
     self.subM = SubjectFactory(text='M', parents=[self.subL])
     self.subE = SubjectFactory(text='E', parents=[self.subB, self.subM])
     self.subN = SubjectFactory(text='N', parents=[self.subM])
     self.subO = SubjectFactory(text='O')
     rules = [([self.subA._id, self.subB._id], False),
              ([self.subA._id, self.subD._id], True),
              ([self.subH._id, self.subI._id, self.subJ._id], True),
              ([self.subL._id], True)]
     #  This should allow: A, B, D, G, H, I, J, L, M, N and E
     #  This should not allow: C, F, K, O
     return rules
Exemple #17
0
class TestSubjectValidation(OsfTestCase):
    def setUp(self):
        super(TestSubjectValidation, self).setUp()

        self.root_subject = SubjectFactory()
        self.one_level_root = SubjectFactory()
        self.two_level_root = SubjectFactory()
        self.outside_root = SubjectFactory()

        self.parent_subj_0 = SubjectFactory(parents=[self.root_subject])
        self.parent_subj_1 = SubjectFactory(parents=[self.root_subject])
        self.two_level_parent = SubjectFactory(parents=[self.two_level_root])

        self.outside_parent = SubjectFactory(parents=[self.outside_root])

        self.child_subj_00 = SubjectFactory(parents=[self.parent_subj_0])
        self.child_subj_01 = SubjectFactory(parents=[self.parent_subj_0])
        self.child_subj_10 = SubjectFactory(parents=[self.parent_subj_1])
        self.child_subj_11 = SubjectFactory(parents=[self.parent_subj_1])
        self.outside_child = SubjectFactory(parents=[self.outside_parent])

        self.parent_subj_0.children = [self.child_subj_00, self.child_subj_01]
        self.parent_subj_1.children = [self.child_subj_10, self.child_subj_11]
        self.outside_parent.children = [self.outside_child]

        self.root_subject.children = [self.parent_subj_0, self.parent_subj_1]
        self.outside_root.children = [self.outside_parent]
        self.two_level_root.children = [self.two_level_parent]

        self.child_subj_00.save()
        self.child_subj_01.save()
        self.child_subj_10.save()
        self.child_subj_11.save()
        self.outside_child.save()

        self.parent_subj_0.save()
        self.parent_subj_1.save()
        self.outside_parent.save()
        self.two_level_parent.save()

        self.root_subject.save()
        self.outside_root.save()
        self.two_level_root.save()
        self.one_level_root.save()

        self.valid_full_hierarchy = [self.root_subject._id, self.parent_subj_0._id, self.child_subj_00._id]
        self.valid_two_level_hierarchy = [self.two_level_root._id, self.two_level_parent._id]
        self.valid_one_level_hierarchy = [self.one_level_root._id]
        self.valid_partial_hierarchy = [self.root_subject._id, self.parent_subj_1._id]
        self.valid_root = [self.root_subject._id]

        self.no_root = [self.parent_subj_0._id, self.child_subj_00._id]
        self.no_parent = [self.root_subject._id, self.child_subj_00._id]
        self.invalid_child_leaf = [self.root_subject._id, self.parent_subj_0._id, self.child_subj_10._id]
        self.invalid_parent_leaf = [self.root_subject._id, self.outside_parent._id, self.child_subj_00._id]
        self.invalid_root_leaf = [self.outside_root._id, self.parent_subj_0._id, self.child_subj_00._id]
        self.invalid_ids = ['notarealsubjectid', 'thisisalsoafakeid']

    def test_validation_full_hierarchy(self):
        assert_equal(validate_subject_hierarchy(self.valid_full_hierarchy), None)

    def test_validation_two_level_hierarchy(self):
        assert_equal(validate_subject_hierarchy(self.valid_two_level_hierarchy), None)

    def test_validation_one_level_hierarchy(self):
        assert_equal(validate_subject_hierarchy(self.valid_one_level_hierarchy), None)

    def test_validation_partial_hierarchy(self):
        assert_equal(validate_subject_hierarchy(self.valid_partial_hierarchy), None)

    def test_validation_root_only(self):
        assert_equal(validate_subject_hierarchy(self.valid_root), None)

    def test_invalidation_no_root(self):
        with assert_raises(ValidationValueError) as e:
            validate_subject_hierarchy(self.no_root)

        assert_in('Unable to find root', e.exception.message)

    def test_invalidation_no_parent(self):
        with assert_raises(ValidationValueError) as e:
            validate_subject_hierarchy(self.no_parent)

        assert_in('Invalid subject hierarchy', e.exception.message)

    def test_invalidation_invalid_child_leaf(self):
        with assert_raises(ValidationValueError) as e:
            validate_subject_hierarchy(self.invalid_child_leaf)

        assert_in('Invalid subject hierarchy', e.exception.message)

    def test_invalidation_invalid_parent_leaf(self):
        with assert_raises(ValidationValueError) as e:
            validate_subject_hierarchy(self.invalid_parent_leaf)

        assert_in('Invalid subject hierarchy', e.exception.message)

    def test_invalidation_invalid_root_leaf(self):
        with assert_raises(ValidationValueError) as e:
            validate_subject_hierarchy(self.invalid_root_leaf)

        assert_in('Invalid subject hierarchy', e.exception.message)

    def test_invalidation_invalid_ids(self):
        with assert_raises(ValidationValueError) as e:
            validate_subject_hierarchy(self.invalid_ids)

        assert_in('could not be found', e.exception.message)
Exemple #18
0
    def setUp(self):
        super(TestSubjectValidation, self).setUp()

        self.root_subject = SubjectFactory()
        self.one_level_root = SubjectFactory()
        self.two_level_root = SubjectFactory()
        self.outside_root = SubjectFactory()

        self.parent_subj_0 = SubjectFactory(parents=[self.root_subject])
        self.parent_subj_1 = SubjectFactory(parents=[self.root_subject])
        self.two_level_parent = SubjectFactory(parents=[self.two_level_root])

        self.outside_parent = SubjectFactory(parents=[self.outside_root])

        self.child_subj_00 = SubjectFactory(parents=[self.parent_subj_0])
        self.child_subj_01 = SubjectFactory(parents=[self.parent_subj_0])
        self.child_subj_10 = SubjectFactory(parents=[self.parent_subj_1])
        self.child_subj_11 = SubjectFactory(parents=[self.parent_subj_1])
        self.outside_child = SubjectFactory(parents=[self.outside_parent])

        self.parent_subj_0.children = [self.child_subj_00, self.child_subj_01]
        self.parent_subj_1.children = [self.child_subj_10, self.child_subj_11]
        self.outside_parent.children = [self.outside_child]

        self.root_subject.children = [self.parent_subj_0, self.parent_subj_1]
        self.outside_root.children = [self.outside_parent]
        self.two_level_root.children = [self.two_level_parent]

        self.child_subj_00.save()
        self.child_subj_01.save()
        self.child_subj_10.save()
        self.child_subj_11.save()
        self.outside_child.save()

        self.parent_subj_0.save()
        self.parent_subj_1.save()
        self.outside_parent.save()
        self.two_level_parent.save()

        self.root_subject.save()
        self.outside_root.save()
        self.two_level_root.save()
        self.one_level_root.save()

        self.valid_full_hierarchy = [self.root_subject._id, self.parent_subj_0._id, self.child_subj_00._id]
        self.valid_two_level_hierarchy = [self.two_level_root._id, self.two_level_parent._id]
        self.valid_one_level_hierarchy = [self.one_level_root._id]
        self.valid_partial_hierarchy = [self.root_subject._id, self.parent_subj_1._id]
        self.valid_root = [self.root_subject._id]

        self.no_root = [self.parent_subj_0._id, self.child_subj_00._id]
        self.no_parent = [self.root_subject._id, self.child_subj_00._id]
        self.invalid_child_leaf = [self.root_subject._id, self.parent_subj_0._id, self.child_subj_10._id]
        self.invalid_parent_leaf = [self.root_subject._id, self.outside_parent._id, self.child_subj_00._id]
        self.invalid_root_leaf = [self.outside_root._id, self.parent_subj_0._id, self.child_subj_00._id]
        self.invalid_ids = ['notarealsubjectid', 'thisisalsoafakeid']
Exemple #19
0
 def setUpTestData(cls):
     Image.objects.import_path(
         SIEMENS_DWI_SERIES_PATH, progressbar=False, report=False
     )
     cls.series = Series.objects.first()
     cls.subject = SubjectFactory()