def setup(self, researcher=True, apikey=True, study=True):
        """
        This function is used to initialize that database for each test.

        This was written in this fashion because of a known issue with the HybridTest class that does not consistently
        use database changes that persist between tests
        """
        if apikey and not researcher:
            raise Exception("invalid setup criteria")
        if researcher:
            self.researcher = Researcher.create_with_password(
                username=TEST_USERNAME, password=TEST_PASSWORD)
        if apikey:
            self.api_key = ApiKey.generate(self.researcher,
                                           has_tableau_api_permissions=True)
            self.api_key_public = self.api_key.access_key_id
            self.api_key_private = self.api_key.access_key_secret_plaintext
        if study:
            self.study = Study.create_with_object_id(
                device_settings=DeviceSettings(),
                encryption_key=TEST_STUDY_ENCRYPTION_KEY,
                name=TEST_STUDY_NAME,
            )
            if researcher:
                self.study_relation = StudyRelation(
                    study=self.study,
                    researcher=self.researcher,
                    relationship="researcher",
                ).save()
示例#2
0
def create_new_researcher():
    if request.method == 'GET':
        return render_template('create_new_researcher.html')

    # Drop any whitespace or special characters from the username
    username = ''.join(e for e in request.form.get('admin_id', '')
                       if e.isalnum())
    password = request.form.get('password', '')

    if Researcher.objects.filter(username=username).exists():
        flash(f"There is already a researcher with username {username}",
              'danger')
        return redirect('/create_new_researcher')
    else:
        researcher = Researcher.create_with_password(username, password)
        return redirect('/edit_researcher/{:d}'.format(researcher.pk))
示例#3
0
    def test_all_routes(self):
        """
        Tests urls
        """
        app2 = subdomain("frontend")
        app2.register_blueprint(admin_pages.admin_pages)

        long_encryption_key = 'aabbccddefggiijjkklmnoppqqrrsstt'

        researcher = Researcher.create_with_password('test_user',
                                                     'test_password')
        researcher.admin = True
        researcher.reset_access_credentials()
        researcher.save()

        study = Study.create_with_object_id(name='test_study',
                                            encryption_key=long_encryption_key)
        researcher.studies.add(study)

        self.selenium.get("localhost:54321")
        self.selenium.find_element_by_name('username').send_keys('test_user')
        self.selenium.find_element_by_name('password').send_keys(
            'test_password')
        self.selenium.find_element_by_name('submit').click()

        for rule in app2.url_map.iter_rules():
            str_rule = str(rule)
            self.assertIn(str_rule, ADMIN_PAGES)

            if ADMIN_PAGES[str_rule]['method'] == 'get':
                self.selenium.get("localhost:54321" + str_rule)
            elif ADMIN_PAGES[str_rule]['method'] == 'post':
                continue
            elif ADMIN_PAGES[str_rule]['method'] == 'get_param':
                str_rule_formatted = re.sub(r"<\w+:\w+>", str(study.id),
                                            str_rule)
                self.selenium.get("localhost:54321" + str_rule_formatted)
            else:
                continue

            response = self.determine_errors()
            self.assertEqual(response, '200')
示例#4
0
 def handle(self, *args, **options):
     new_researcher = Researcher.create_with_password("admin", "admin")
     new_researcher.elevate_to_site_admin()