Пример #1
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
    }
Пример #2
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)
Пример #3
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())
Пример #4
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
Пример #5
0
    kw1 = choice(Keyword.objects.all())
    kw2 = choice(Keyword.objects.all())
    kw3 = choice(Keyword.objects.all())
    study.keywords.add(kw1, kw2, kw3)

# Create some entries for ClassificationOfDiseases
create_classification_of_deseases(10)

# Create genders
gender1 = Gender.objects.create(name='male')
gender2 = Gender.objects.create(name='female')

# Create groups' experimental protocols and participants
for group in Group.objects.all():
    create_experimental_protocol(group)
    create_participant(randint(3, 7), group,
                       gender1 if randint(1, 2) == 1 else gender2)
    ic1 = choice(ClassificationOfDiseases.objects.all())
    ic2 = choice(ClassificationOfDiseases.objects.all())
    group.inclusion_criteria.add(ic1, ic2)

# Create TMSSetting from an experiment Approved, to test search.
# Obs.: TO VERIFY SEARCH TMS things, change Experiment status to APPROVED
# after run this faker populator
experiment = Experiment.objects.first()
create_tms_setting(1, experiment)
tms_setting = TMSSetting.objects.last()
tms_setting.name = 'tmssettingname'
tms_setting.save()

# Create TMSDeviceSetting from a TMSSetting to test search
# Required creating TMSSetting from experiment Approved, first
Пример #6
0
 def setUp(self):
     experiment = create_experiment(1)
     group = create_group(1, experiment)
     create_genders()
     create_participant(1, group)