Exemple #1
0
    def setUp(self):

        # create the groups of users and their permissions
        exec(open('add_initial_data.py').read())

        # return user password to use when necessary in subclasses
        self.user, self.user_passwd = create_user(Group.objects.all())
        self.client.login(
            username=self.user.username, password=self.user_passwd
        )

        # create experiment/experimental protocol/group
        self.experiment = ObjectsFactory.create_experiment(
            ObjectsFactory.create_research_project(self.user)
        )
        self.root_component = ObjectsFactory.create_block(self.experiment)
        self.group = ObjectsFactory.create_group(
            self.experiment, self.root_component
        )

        # create patient/subject/subject_of_group
        self.patient = UtilTests().create_patient(changed_by=self.user)
        subject = ObjectsFactory.create_subject(self.patient)
        self.subject_of_group = \
            ObjectsFactory.create_subject_of_group(self.group, subject)
Exemple #2
0
    def test_send_experiment_to_portal(self, mockRestApiClientClass):
        # create the groups of users and their permissions
        exec(open('add_initial_data.py').read())

        user, user_passwd = create_user(Group.objects.all())

        research_project = ObjectsFactory.create_research_project()
        experiment = ObjectsFactory.create_experiment(research_project)
        ScheduleOfSending.objects.create(
            experiment=experiment,
            responsible=user,
            status='scheduled',
            send_participant_age=False,
            reason_for_resending='Ein guter Grund')

        send_experiment_to_portal(experiment)

        api_fields = {
            'nes_id', 'title', 'description', 'data_acquisition_done',
            'project_url', 'ethics_committee_url', 'ethics_committee_file',
            'release_notes'
        }

        (api_schema, action_keys), kwargs = \
            mockRestApiClientClass.return_value.client.action.call_args
        self.assertTrue(
            set(kwargs['params'].keys()).issubset(api_fields),
            str(set(kwargs['params'].keys())) + ' not in ' + str(api_fields))
Exemple #3
0
    def test_send_experiment_to_portal(self, mockRestApiClientClass):
        # create the groups of users and their permissions
        exec(open('add_initial_data.py').read())

        user, user_passwd = create_user(Group.objects.all())

        research_project = ObjectsFactory.create_research_project()
        experiment = ObjectsFactory.create_experiment(research_project)
        ScheduleOfSending.objects.create(
            experiment=experiment, responsible=user, status='scheduled',
            send_participant_age=False, reason_for_resending='Ein guter Grund'
        )

        send_experiment_to_portal(experiment)

        api_fields = {
            'nes_id', 'title', 'description', 'data_acquisition_done',
            'project_url', 'ethics_committee_url', 'ethics_committee_file',
            'release_notes'
        }

        (api_schema, action_keys), kwargs = \
            mockRestApiClientClass.return_value.client.action.call_args
        self.assertTrue(
            set(kwargs['params'].keys()).issubset(api_fields),
            str(set(kwargs['params'].keys())) + ' not in ' + str(api_fields)
        )
Exemple #4
0
    def setUp(self):

        # create the groups of users and their permissions
        exec(open('add_initial_data.py').read())

        # return user password to use when necessary in subclasses
        self.user, self.user_passwd = create_user(Group.objects.all())
        self.client.login(
            username=self.user.username, password=self.user_passwd
        )

        # create experiment/experimental protocol/group
        self.experiment = ObjectsFactory.create_experiment(
            ObjectsFactory.create_research_project(self.user)
        )
        self.root_component = ObjectsFactory.create_block(self.experiment)
        self.group = ObjectsFactory.create_group(
            self.experiment, self.root_component
        )

        # create patient/subject/subject_of_group
        self.patient = UtilTests().create_patient_mock(changed_by=self.user)
        subject = ObjectsFactory.create_subject(self.patient)
        self.subject_of_group = \
            ObjectsFactory.create_subject_of_group(self.group, subject)
Exemple #5
0
 def test_first_time_user_login_redirects_to_change_password_page(self):
     user, passwd = create_user(force_password_change=True)
     response = self.client.post(reverse('login'),
                                 data={
                                     'username': user.username,
                                     'password': passwd
                                 },
                                 follow=True)
     self.assertRedirects(response, reverse('password_change'))
Exemple #6
0
    def create_experiment_researcher(experiment):
        """Create an experiment researcher to be used in tests
        :param experiment: researcher's experiment
        :return: ExperimentResearcher model instance
        """
        user, passwd = create_user()

        return ExperimentResearcher.objects.create(experiment=experiment,
                                                   researcher=user)
Exemple #7
0
 def create_pre_authenticated_session(self):
     user = create_user(group_name='Senior researcher',
                        username=TEST_USERNAME)
     session = SessionStore()
     session[SESSION_KEY] = user.pk
     session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
     session.save()
     # to set a cookie we need to first visit the domain.
     # 404 pages load the quickest
     self.browser.get(self.live_server_url + '/404_no_such_url')
     self.browser.add_cookie(
         dict(name=settings.SESSION_COOKIE_NAME,
              value=session.session_key,
              path='/'))
Exemple #8
0
    def setUp(self):
        # create the groups of users and their permissions
        exec(open('add_initial_data.py').read())

        self.user, passwd = create_user(Group.objects.all())
        self.client.login(username=self.user.username, password=passwd)

        self.survey = create_survey()
        self.patient = UtilTests.create_patient(self.user)
        # token_id=1 from mocks
        self.response = UtilTests.create_response_survey(self.user,
                                                         self.patient,
                                                         self.survey,
                                                         token_id=1)
Exemple #9
0
    def setUp(self):
        super(ExperimentTestCase, self).setUp()

        # create the groups of users and their permissions
        exec(open('add_initial_data.py').read())

        self.user, self.user_passwd = create_user(UserGroup.objects.all())

        self.research_project = ObjectsFactory.create_research_project(
            self.user)
        self.experiment = ObjectsFactory.create_experiment(
            self.research_project)
        self.root_component = ObjectsFactory.create_block(self.experiment)
        self.group = ObjectsFactory.create_group(self.experiment,
                                                 self.root_component)

        self.patient = UtilTests().create_patient(changed_by=self.user)
        self.subject = ObjectsFactory.create_subject(self.patient)
        self.subject_of_group = ObjectsFactory.create_subject_of_group(
            self.group, self.subject)
Exemple #10
0
    def test_can_get_username_link_to_log_in(self):
        user = create_user('Senior researcher', TEST_USERNAME)

        # Suzana goes to the NES and see a form to enter her credentials to
        # log in. She enters her credentials
        self.browser.get(self.live_server_url)
        self.browser.find_element_by_name('username').send_keys(user.username)
        password = self.browser.find_element_by_name('password')
        password.send_keys(TEST_PASSWORD)  # defined in create_user method
        password.send_keys(Keys.ENTER)

        # She's logged in!
        self.wait_to_be_logged_in(username=TEST_USERNAME)

        # Now she logs out
        self.browser.find_element_by_link_text(TEST_USERNAME).send_keys(
            Keys.ENTER)
        self.wait_for(
            lambda: self.browser.find_element_by_link_text('Logout').click())

        # She is loged out
        self.wait_to_logged_out()
Exemple #11
0
 def test_first_time_user_login_redirects_to_change_password_page(self):
     user, passwd = create_user(force_password_change=True)
     response = self.client.post(
         reverse('login'), data={'username': user.username, 'password': passwd}, follow=True)
     self.assertRedirects(response, reverse('password_change'))