Пример #1
0
 def test_POSTing_new_experimental_protocol_with_image_creates_image_file(
         self):
     owner = User.objects.create_user(username='******', password='******')
     experiment = create_experiment(1, owner, Experiment.TO_BE_ANALYSED)
     group = create_group(1, experiment)
     image_file = generate_image_file(filename='datei.jpg')
     url = reverse('api_group_experimental_protocol-list',
                   kwargs={'pk': group.id})
     self.client.login(username=owner.username, password='******')
     response = self.client.post(
         url, {
             'image': image_file,
             'textual_description': 'Ein wunderbar Beschreibung'
         },
         format='multipart')
     self.client.logout()
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     new_exp_protocol = ExperimentalProtocol.objects.last()
     self.assertEqual(new_exp_protocol.textual_description,
                      'Ein wunderbar Beschreibung')
     self.assertTrue(
         os.path.exists(
             os.path.join(TEMP_MEDIA_ROOT, 'uploads',
                          datetime.utcnow().strftime('%Y/%m/%d'),
                          'datei.jpg')))
Пример #2
0
 def test_cannot_save_empty_attributes(self):
     owner = User.objects.create_user(username='******',
                                      password='******')
     experiment = create_experiment(1,
                                    owner=owner,
                                    status=Experiment.TO_BE_ANALYSED)
     group = create_group(1, experiment)
     experimental_protocol = ExperimentalProtocol(group=group)
     with self.assertRaises(ValidationError):
         experimental_protocol.save()
         experimental_protocol.full_clean()
Пример #3
0
def create_model_instances_to_test_step_type_data():
    experiment = create_experiment(1)
    group = create_group(1, experiment)
    create_genders()
    participant = create_participant(1, group,
                                     Gender.objects.order_by('?').first())
    return {
        'experiment': experiment,
        'group': group,
        'participant': participant
    }
Пример #4
0
    def test_delete_instance_deletes_related_files(self):
        experiment = create_experiment(1)
        group = create_group(1, experiment)
        stimulus = create_stimulus_step(group)

        file_instance = stimulus.media_file
        add_temporary_file_to_file_instance(file_instance)

        stimulus.delete()
        self.assertFalse(
            os.path.exists(
                os.path.join(self.TEMP_MEDIA_ROOT, file_instance.name)))
Пример #5
0
    def test_delete_instance_deletes_related_files(self):
        experiment = create_experiment(1)
        group = create_group(1, experiment)
        experimental_protocol = create_experimental_protocol(group)

        file_instance = experimental_protocol.image
        add_temporary_file_to_file_instance(file_instance)

        experimental_protocol.delete()
        self.assertFalse(
            os.path.exists(
                os.path.join(self.TEMP_MEDIA_ROOT, file_instance.name)))
Пример #6
0
    def test_delete_instance_deletes_related_files(self):
        experiment = create_experiment(1)
        group = create_group(1, experiment)
        step = create_step(1, group, Step.EEG)
        step_additional_file = StepAdditionalFile.objects.create(step=step)

        file_instance = step_additional_file.file
        add_temporary_file_to_file_instance(file_instance)

        step_additional_file.delete()
        self.assertFalse(
            os.path.exists(
                os.path.join(self.TEMP_MEDIA_ROOT, file_instance.name)))
Пример #7
0
    def test_can_see_groups_items_in_downloads_tab_content_only_if_they_exist(
            self):
        ##
        # Let's create an experiment with Experiment and Groups data. With
        # it, we simulate that Portal received an experiment, only with
        # Experiment and Group data. One group created has no data besides
        # Group data, the other has 1 participant associated
        ##
        owner = User.objects.get(username='******')
        create_experiment(1, owner, Experiment.APPROVED)
        experiment = Experiment.objects.last()
        create_group(1, experiment)
        group_with_nothing = Group.objects.last()
        create_group(1, experiment)
        create_participant(1, Group.objects.last(), Gender.objects.last())

        ##
        # We have to refresh page to include this new experiment in
        # Experiments List
        ##
        self.browser.refresh()

        downloads_tab_content = self.access_downloads_tab_content(experiment)

        # As the last group created has only basic participant information (
        # without data collection for it), that group is not listed.
        self.assertNotIn(
            'Group ' + experiment.groups.last().title,
            downloads_tab_content.text
        )
        self.assertIn(
            'There are not data for group ' +
            group_with_nothing.title +
            ". But there's still basic Experiment data. Click in 'Download' "
            "button to download it.",
            downloads_tab_content.text
        )
        self.assertNotIn('Per Questionnaire Data', downloads_tab_content.text)
Пример #8
0
    def test_remove_experiment_last_version_removes_objects_associated(
            self, mock_user_input):
        """
        Do not test for files deleted. This tests are made in models tests.
        """
        # create experiment and some objects associated with it
        experiment = create_experiment(1)
        create_study(1, experiment)
        groups = create_group(3, experiment)
        eeg_setting = create_eeg_setting(1, experiment)
        exp_prot = None  # just to protect assert below
        for group in groups:
            exp_prot = create_experimental_protocol(group)
            eeg_step = create_eeg_step(group, eeg_setting)
            participants = create_participant(
                3, group, gender=Gender.objects.order_by('?').first())
            for participant in participants:
                create_eeg_data(eeg_setting, eeg_step, participant)

        # remove experiment last version and its related objects
        out = StringIO()
        call_command('remove_experiment',
                     experiment.nes_id,
                     experiment.owner,
                     '--last',
                     stdout=out)

        # asserts
        self.assertFalse(Experiment.objects.exists())
        self.assertFalse(Study.objects.exists())
        self.assertFalse(EEGSetting.objects.exists())
        # TODO: fix this after fix tests helper (does not create model
        # TODO: instances for all in it, create under demand in tests). Test
        # TODO: for all objects at once.
        for group in groups:
            self.assertFalse(Group.objects.filter(pk=group.id).exists())
            self.assertFalse(
                ExperimentalProtocol.objects.filter(pk=exp_prot.id).exists())
            self.assertFalse(EEG.objects.filter(group=group).exists())
            self.assertFalse(group.participants.exists())
        self.assertFalse(EEGData.objects.exists())

        self.assertIn(
            'Last version of experiment "%s" successfully removed' %
            experiment.title, out.getvalue())
Пример #9
0
 def create_questionnaire(experiment):
     """
     Necessary the following files to exist:
         - settings.BASE_DIR/experiments/tests/questionnaire7.csv
         - settings.BASE_DIR/experiments/tests/response_questionnaire7.json
     """
     group = create_group(1, experiment)
     participant = create_participant(1, group)
     participant.age = None
     participant.save()
     questionnaire = create_questionnaire(1, 'Q5489', group)
     create_questionnaire_language(
         questionnaire,
         settings.BASE_DIR + '/experiments/tests/questionnaire7.csv', 'en')
     create_questionnaire_responses(
         questionnaire, participant, settings.BASE_DIR +
         '/experiments/tests/response_questionnaire7.json')
     return group
Пример #10
0
                         start_date=datetime.utcnow(),
                         experiment=experiment_owner1)
    # to test search (necessary to approve experiment(s) in front-end or
    # directly in database)
    if i == 1:
        study = Study.objects.last()
        study.description = 'The brachial artery is the major blood vessel ' \
                            'of  the (upper) arm. It\'s correlated with ' \
                            'plexus.'
        # We put a keyword with the string 'brachial plexus' in the study to
        # also be found by search test
        study.keywords.add('brachial plexus')
        study.save()

    create_ethics_committee_info(experiment_owner1)
    create_group(randint(1, 3), experiment_owner1)

for i in range(4, 6):
    experiment_owner2 = Experiment.objects.create(
        title=fake.word().title(),
        description=fake.text(),
        nes_id=i,
        owner=owner2,
        version=1,
        sent_date=datetime.utcnow(),
        status=Experiment.TO_BE_ANALYSED)
    # to test search (necessary to approve experiment(s) in front-end or
    # directly in database)
    if i == 4:
        experiment_owner2.title = 'Brachial Plexus'
        experiment_owner2.save()
Пример #11
0
 def setUp(self):
     experiment = create_experiment(1)
     group = create_group(1, experiment)
     create_genders()
     create_participant(1, group)