Beispiel #1
0
    def setup_responses(self):
        application_forms = [
            ApplicationForm(1, True, datetime(2019, 4, 12)),
            ApplicationForm(2, False, datetime(2019, 4, 12))
        ]
        db.session.add_all(application_forms)

        candidate1 =   AppUser(email='*****@*****.**', firstname='candidate',   lastname='1', user_title='Mr', password='******', organisation_id=1)
        candidate2 =   AppUser(email='*****@*****.**', firstname='candidate',   lastname='2', user_title='Ms', password='******', organisation_id=1)
        candidate3 =   AppUser(email='*****@*****.**', firstname='candidate',   lastname='3', user_title='Mr', password='******', organisation_id=1)
        event_admin =  AppUser(email='*****@*****.**',firstname='event_admin', lastname='1', user_title='Ms', password='******', organisation_id=1)
        users = [candidate1, candidate2, candidate3, event_admin]
        for user in users:
            user.verify()
        db.session.add_all(users)

        event_role = EventRole('admin', 4, 1)
        db.session.add(event_role)

        responses = [
            Response(1, 1, True, datetime(2019, 4, 10)),
            Response(1, 2, True, datetime(2019, 4, 9), True, datetime(2019, 4, 11)),
            Response(2, 3, True)
        ]
        db.session.add_all(responses)
        db.session.commit()
Beispiel #2
0
    def setup_responses(self):
        application_forms = [
            ApplicationForm(1, True, datetime(2019, 4, 12)),
            ApplicationForm(2, False, datetime(2019, 4, 12))
        ]
        db.session.add_all(application_forms)

        candidate1 = AppUser('*****@*****.**', 'candidate', '1', 'Mr', 1,
                             1, 'M', 'UWC', 'CS', 'NA', 1,
                             datetime(1984, 12, 12), 'Eng', 'abc')
        candidate2 = AppUser('*****@*****.**', 'candidate', '2', 'Ms', 1,
                             1, 'F', 'RU', 'Chem', 'NA', 1,
                             datetime(1984, 12, 12), 'Eng', 'abc')
        candidate3 = AppUser('*****@*****.**', 'candidate', '3', 'Mr', 1,
                             1, 'M', 'UFH', 'Phys', 'NA', 1,
                             datetime(1984, 12, 12), 'Eng', 'abc')
        event_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms', 1, 1,
                              'F', 'NWU', 'Math', 'NA', 1,
                              datetime(1984, 12, 12), 'Eng', 'abc')
        users = [candidate1, candidate2, candidate3, event_admin]
        for user in users:
            user.verify()
        db.session.add_all(users)

        event_role = EventRole('admin', 4, 1)
        db.session.add(event_role)

        responses = [
            Response(1, 1, True, datetime(2019, 4, 10)),
            Response(1, 2, True, datetime(2019, 4, 9), True,
                     datetime(2019, 4, 11)),
            Response(2, 3, True)
        ]
        db.session.add_all(responses)
        db.session.commit()
Beispiel #3
0
    def seed_static_data(self):
        test_country = Country('Indaba Land')
        db.session.add(test_country)
        db.session.commit()

        test_category = UserCategory('Category1')
        db.session.add(test_category)
        db.session.commit()

        self.test_user = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr',
                                 1, 1, 'Male', 'University',
                                 'Computer Science', 'None', 1,
                                 datetime(1984, 12, 12), 'Zulu', '123456')
        self.test_user.verified_email = True
        db.session.add(self.test_user)
        db.session.commit()

        test_event = Event('Test Event', 'Event Description',
                           datetime.now() + timedelta(days=30),
                           datetime.now() + timedelta(days=60))
        db.session.add(test_event)
        db.session.commit()

        self.test_form = ApplicationForm(test_event.id, True,
                                         datetime.now() + timedelta(days=60))
        db.session.add(self.test_form)
        db.session.commit()

        db.session.flush()
Beispiel #4
0
    def seed_static_data(self):
        self.add_organisation('IndabaX')
        self.start_time = datetime.now() + timedelta(days=30)
        self.end_time = datetime.now() + timedelta(days=60)

        test_event = Event('Test Event', 'Event Description', self.start_time,
                           self.end_time, 'FREAD', 1,
                           '*****@*****.**', 'indaba.deeplearning',
                           datetime.now(), datetime.now(), datetime.now(),
                           datetime.now(), datetime.now(), datetime.now(),
                           datetime.now(), datetime.now(), datetime.now(),
                           datetime.now())
        db.session.add(test_event)
        db.session.commit()
        test_form = ApplicationForm(test_event.id, True, self.end_time)
        db.session.add(test_form)
        db.session.commit()
        test_section = Section(test_form.id, 'Test Section',
                               'Test Description', 1)
        db.session.add(test_section)
        db.session.commit()
        test_question = Question(application_form_id=test_form.id,
                                 section_id=test_section.id,
                                 headline='Test Question Headline',
                                 placeholder='Test question placeholder',
                                 order=1,
                                 questionType='multi-choice',
                                 validation_regex=None,
                                 is_required=True,
                                 description='Test Question Description',
                                 options=None)
        db.session.add(test_question)
        db.session.flush()
Beispiel #5
0
    def seed_static_data(self):
        self.test_user = self.add_user('*****@*****.**')
        self.add_organisation('Deep Learning Indaba', 'blah.png',
                              'blah_big.png', 'deeplearningindaba')
        test_country = Country('Indaba Land')
        db.session.add(test_country)
        db.session.commit()

        test_category = UserCategory('Category1')
        db.session.add(test_category)
        db.session.commit()

        self.test_user.verified_email = True
        db.session.add(self.test_user)
        db.session.commit()

        test_event = Event('Test Event', 'Event Description',
                           datetime.now() + timedelta(days=30),
                           datetime.now() + timedelta(days=60), 'SPEEDNET', 1,
                           '*****@*****.**', 'indaba.deeplearning',
                           datetime.now(), datetime.now(), datetime.now(),
                           datetime.now(), datetime.now(), datetime.now(),
                           datetime.now(), datetime.now(), datetime.now(),
                           datetime.now())
        db.session.add(test_event)
        db.session.commit()

        self.test_form = ApplicationForm(test_event.id, True,
                                         datetime.now() + timedelta(days=60))
        db.session.add(self.test_form)
        db.session.commit()

        db.session.flush()
Beispiel #6
0
    def setup_static_data(self):
        self.add_organisation('Deep Learning Indaba', 'blah.png', 'blah_big.png')
        self.add_organisation('Deep Learning IndabaX', 'blah.png', 'blah_big.png')
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

        events = [
            Event('Indaba', 'Indaba Event', datetime.now(), datetime.now(), 'ADAMOPTIM', 1, '*****@*****.**','indaba.deeplearning',
                           datetime.now(), datetime.now(), datetime.now(), datetime.now(),
                           datetime.now(), datetime.now(), datetime.now(), datetime.now(),
                           datetime.now(), datetime.now()),
            Event('Indaba2', 'Indaba Event 2', datetime.now(), datetime.now(), 'HACFTET', 2, '*****@*****.**','indaba.deeplearning',
                           datetime.now(), datetime.now(), datetime.now(), datetime.now(),
                           datetime.now(), datetime.now(), datetime.now(), datetime.now(),
                           datetime.now(), datetime.now())
        ]
        db.session.add_all(events)

        application_forms = [
            ApplicationForm(1, True, datetime.now()),
            ApplicationForm(2, False, datetime.now())
        ]
        db.session.add_all(application_forms)

        candidate1 = AppUser(email='*****@*****.**', firstname='candidate', lastname='1', user_title='Mr',password= '******', organisation_id=1)
        candidate2 = AppUser(email='*****@*****.**', firstname='candidate', lastname='2', user_title='Ms', password='******', organisation_id=1)
        system_admin = AppUser(email='*****@*****.**', firstname='system_admin', lastname='1', user_title='Mr',password='******', organisation_id=1, is_admin=True)
        event_admin = AppUser(email='*****@*****.**', firstname='event_admin', lastname='1', user_title='Ms', password='******',organisation_id=1)
        reviewer = AppUser(email='*****@*****.**', firstname='reviewer', lastname='1', user_title='Ms', password='******', organisation_id=1)
        users = [candidate1, candidate2, system_admin, event_admin, reviewer]
        for user in users:
            user.verify()
        db.session.add_all(users)

        event_roles = [
            EventRole('admin', 4, 1),
            EventRole('reviwer', 5, 1)
        ]
        db.session.add_all(event_roles)
        db.session.commit()
        responses = [
            Response(1, 1, True, datetime(2019, 4, 10)),
            Response(2, 2, True, datetime(2019, 4, 9))
        ]
        db.session.add_all(responses)
        db.session.commit()
Beispiel #7
0
    def setup_static_data(self):
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))

        events = [
            Event('Indaba', 'Indaba Event', datetime.now(), datetime.now()),
            Event('Indaba2', 'Indaba Event 2', datetime.now(), datetime.now())
        ]
        db.session.add_all(events)

        application_forms = [
            ApplicationForm(1, True, datetime.now()),
            ApplicationForm(2, False, datetime.now())
        ]
        db.session.add_all(application_forms)

        candidate1 = AppUser('*****@*****.**', 'candidate', '1', 'Mr', 1,
                             1, 'M', 'UWC', 'CS', 'NA', 1,
                             datetime(1984, 12, 12), 'Eng', 'abc')
        candidate2 = AppUser('*****@*****.**', 'candidate', '2', 'Ms', 1,
                             1, 'F', 'RU', 'Chem', 'NA', 1,
                             datetime(1984, 12, 12), 'Eng', 'abc')
        system_admin = AppUser('*****@*****.**', 'system_admin', '1',
                               'Mr', 1, 1, 'M', 'UFH', 'Phys', 'NA', 1,
                               datetime(1984, 12, 12), 'Eng', 'abc', True)
        event_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms',
                              1, 1, 'F', 'NWU', 'Math', 'NA', 1,
                              datetime(1984, 12, 12), 'Eng', 'abc')
        reviewer = AppUser('*****@*****.**', 'reviewer', '1', 'Ms', 1,
                           1, 'F', 'NWU', 'Math', 'NA', 1,
                           datetime(1984, 12, 12), 'Eng', 'abc')
        users = [candidate1, candidate2, system_admin, event_admin, reviewer]
        for user in users:
            user.verify()
        db.session.add_all(users)

        event_roles = [EventRole('admin', 4, 1), EventRole('reviwer', 5, 1)]
        db.session.add_all(event_roles)

        responses = [
            Response(1, 1, True, datetime(2019, 4, 10)),
            Response(2, 2, True, datetime(2019, 4, 9))
        ]
        db.session.add_all(responses)
        db.session.commit()
Beispiel #8
0
    def create_application_form(self,
                                event_id=1,
                                is_open=True,
                                nominations=False):

        application_form = ApplicationForm(event_id, is_open, nominations)
        db.session.add(application_form)
        db.session.commit()
        return application_form
Beispiel #9
0
    def seed_static_data(self):
        inactive_user = self.add_user('*****@*****.**',
                                      'inactive',
                                      post_create_fn=lambda u: u.deactivate())
        deleted_user = self.add_user('*****@*****.**',
                                     'deleted',
                                     post_create_fn=lambda u: u.delete())

        event_admin = self.add_user('*****@*****.**', 'event', 'admin')
        self.add_user('*****@*****.**', 'applicant')
        self.add_user('*****@*****.**', 'notstarted')
        self.add_user('*****@*****.**', 'applicant')

        db.session.commit()
        self.add_organisation('Deep Learning Indaba', 'blah.png',
                              'blah_big.png', 'deeplearningindaba')
        country = Country('South Africa')
        db.session.add(country)

        user_category = UserCategory('Post Doc')
        db.session.add(user_category)

        event = Event('Indaba 2019', 'Deep Learning Indaba',
                      datetime(2019, 8, 25), datetime(2019, 8, 31), 'COOLER',
                      1, '*****@*****.**', 'indaba.deeplearning',
                      datetime.now(), datetime.now(), datetime.now(),
                      datetime.now(), datetime.now(), datetime.now(),
                      datetime.now(), datetime.now(), datetime.now(),
                      datetime.now())
        db.session.add(event)
        db.session.commit()

        email_templates = [
            EmailTemplate('application-not-submitted', None, ''),
            EmailTemplate('application-not-started', None, '')
        ]
        db.session.add_all(email_templates)
        db.session.commit()

        event_role = EventRole('admin', event_admin.id, event.id)
        db.session.add(event_role)

        application_form = ApplicationForm(1, True, datetime(2019, 4, 12))
        db.session.add(application_form)
        db.session.commit()

        responses = [
            Response(application_form.id, self.test_users[0].id, True),
            Response(application_form.id, self.test_users[1].id, False),
            Response(application_form.id, self.test_users[3].id, True,
                     datetime.now(), True, datetime.now()),
            Response(application_form.id, self.test_users[4].id, False),
        ]
        db.session.add_all(responses)

        db.session.commit()
Beispiel #10
0
    def seed_static_data(self):
        country = Country('South Africa')
        db.session.add(country)

        user_category = UserCategory('Post Doc')
        db.session.add(user_category)

        inactive_user = AppUser('*****@*****.**', 'inactive', '1', 'Mr',
                                1, 1, 'Male', 'Wits',
                                'Computer Science', 'None', 1,
                                datetime(1991, 3, 27), 'English', 'abc')
        inactive_user.deactivate()
        deleted_user = AppUser('*****@*****.**', 'deleted', '1', 'Mr', 1,
                               1, 'Male', 'Wits', 'Computer Science', 'None',
                               1, datetime(1991, 3, 27), 'English', 'abc')
        deleted_user.delete()
        users = [
            AppUser('*****@*****.**', 'event', 'admin', 'Mr', 1, 1,
                    'Male', 'Wits', 'Computer Science', 'None', 1,
                    datetime(1991, 3, 27), 'English', 'abc'),
            AppUser('*****@*****.**', 'applicant', '1', 'Mr', 1, 1,
                    'Male', 'Wits', 'Computer Science', 'None', 1,
                    datetime(1991, 3, 27), 'English', 'abc'), inactive_user,
            deleted_user,
            AppUser('*****@*****.**', 'notstarted', '1', 'Mr', 1, 1,
                    'Male', 'Wits', 'Computer Science', 'None', 1,
                    datetime(1991, 3, 27), 'English', 'abc'),
            AppUser('*****@*****.**', 'applicant', '2', 'Mr', 1, 1,
                    'Male', 'Wits', 'Computer Science', 'None', 1,
                    datetime(1991, 3, 27), 'English', 'abc')
        ]
        for user in users:
            user.verify()
        db.session.add_all(users)

        event = Event('Indaba 2019', 'Deep Learning Indaba',
                      datetime(2019, 8, 25), datetime(2019, 8, 31))
        db.session.add(event)

        event_role = EventRole('admin', 1, 1)
        db.session.add(event_role)

        application_form = ApplicationForm(1, True, datetime(2019, 4, 12))
        db.session.add(application_form)

        responses = [
            Response(1, 1, True),
            Response(1, 2, False),
            Response(1, 4, True, datetime.now(), True, datetime.now()),
            Response(1, 6, False),
        ]
        db.session.add_all(responses)

        db.session.commit()
Beispiel #11
0
    def seed_static_data(self):
        self.add_organisation('Deep Learning Indaba', 'blah.png',
                              'blah_big.png', 'deeplearningindaba')

        test_country = Country('Indaba Land')
        db.session.add(test_country)
        db.session.commit()

        test_category = UserCategory('Category1')
        db.session.add(test_category)
        db.session.commit()

        response = self.app.post('/api/v1/user', data=self.user_data_dict)
        self.test_user1 = json.loads(response.data)

        other_user_data = self.user_data_dict.copy()
        other_user_data['email'] = '*****@*****.**'
        response = self.app.post('/api/v1/user', data=other_user_data)
        self.test_user2 = json.loads(response.data)

        self.test_event = Event('Test Event', 'Event Description',
                                datetime.now() + timedelta(days=30),
                                datetime.now() + timedelta(days=60), 'KONNET',
                                1, '*****@*****.**',
                                'indaba.deeplearning', datetime.now(),
                                datetime.now(), datetime.now(), datetime.now(),
                                datetime.now(), datetime.now(), datetime.now(),
                                datetime.now(), datetime.now(), datetime.now())
        db.session.add(self.test_event)
        db.session.commit()

        self.test_form = ApplicationForm(self.test_event.id, True,
                                         datetime.now() + timedelta(days=60))
        db.session.add(self.test_form)
        db.session.commit()

        self.test_response = Response(self.test_form.id, self.test_user1['id'])
        db.session.add(self.test_response)
        db.session.commit()

        self.test_response2 = Response(self.test_form.id,
                                       self.test_user2['id'])
        self.test_response2.submit_response()
        db.session.add(self.test_response2)
        db.session.commit()

        self.user_role1 = EventRole('admin', self.test_user1['id'],
                                    self.test_event.id)
        db.session.add(self.user_role1)
        db.session.commit()

        db.session.flush()
Beispiel #12
0
    def _seed_data(self):
        self.add_organisation('Deep Learning Indaba', 'blah.png',
                              'blah_big.png')
        other_user_data = self.add_user('*****@*****.**')

        test_event = self.add_event()
        self.test_form = ApplicationForm(test_event.id, True,
                                         date(2019, 3, 24))
        self.add_to_db(self.test_form)

        self.test_response = Response(self.test_form.id, other_user_data.id)
        self.add_to_db(self.test_response)
        self.headers = self.get_auth_header_for("*****@*****.**")

        db.session.flush()
Beispiel #13
0
    def _seed_data(self):
        # Add a user
        test_country = Country('Indaba Land')
        _add_object_to_db(test_country)

        test_category = UserCategory('Category1')
        _add_object_to_db(test_category)

        other_user_data = self.user_data_dict.copy()
        other_user_data['email'] = '*****@*****.**'
        response = self.app.post('/api/v1/user', data=other_user_data)
        self.other_user_data = json.loads(response.data)

        response = self.app.post('/api/v1/user', data=self.user_data_dict)
        self.user_data = json.loads(response.data)

        # Add application form data
        self.test_event = Event('Test Event', 'Event Description', date(
            2019, 2, 24), date(2019, 3, 24))
        _add_object_to_db(self.test_event)
        self.test_form = ApplicationForm(
            self.test_event.id, True, date(2019, 3, 24))
        _add_object_to_db(self.test_form)
        test_section = Section(
            self.test_form.id, 'Test Section', 'Test Description', 1)
        _add_object_to_db(test_section)
        self.test_question = Question(self.test_form.id, test_section.id,
                                      'Test Question Description', 'Test question placeholder', 1, 'Test Type', None)
        _add_object_to_db(self.test_question)
        self.test_question2 = Question(
            self.test_form.id, test_section.id, 'Test Question 2', 'Enter something', 2, 'short-text', None)
        _add_object_to_db(self.test_question2)

        self.test_response = Response(
            self.test_form.id, self.other_user_data['id'])
        _add_object_to_db(self.test_response)

        self.test_answer1 = Answer(
            self.test_response.id, self.test_question.id, 'My Answer')
        _add_object_to_db(self.test_answer1)

        db.session.flush()
Beispiel #14
0
    def _seed_data(self):
        organisation = self.add_organisation(
            'Deep Learning Indaba', 'Baobab', 'blah.png', 'blah_big.png',
            'deeplearningindba', 'https://www.deeplearningindaba.com',
            '*****@*****.**')

        email_templates = [
            EmailTemplate('withdrawal', None, ''),
            EmailTemplate('confirmation-response', None,
                          '{question_answer_summary}')
        ]
        db.session.add_all(email_templates)
        db.session.commit()

        # Add a user
        test_country = Country('Indaba Land')
        _add_object_to_db(test_country)

        test_category = UserCategory('Category1')
        _add_object_to_db(test_category)

        other_user_data = self.user_data_dict.copy()
        other_user_data['email'] = '*****@*****.**'
        response = self.app.post('/api/v1/user', data=other_user_data)
        self.other_user_data = json.loads(response.data)

        response = self.app.post('/api/v1/user', data=self.user_data_dict)
        self.user_data = json.loads(response.data)

        # Add application form data
        self.test_event = Event('Test Event', 'Event Description',
                                date(2019, 2, 24), date(2019, 3, 24),
                                'NAGSOLVER', 1, '*****@*****.**',
                                'indaba.deeplearning', datetime.now(),
                                datetime.now(), datetime.now(), datetime.now(),
                                datetime.now(), datetime.now(), datetime.now(),
                                datetime.now(), datetime.now(), datetime.now())
        _add_object_to_db(self.test_event)
        self.test_form = ApplicationForm(self.test_event.id, True,
                                         date(2019, 3, 24))
        _add_object_to_db(self.test_form)
        test_section = Section(self.test_form.id, 'Test Section',
                               'Test Description', 1)
        _add_object_to_db(test_section)
        self.test_question = Question(self.test_form.id, test_section.id,
                                      'Test Question Description',
                                      'Test question placeholder', 1,
                                      'Test Type', None)
        _add_object_to_db(self.test_question)
        self.test_question2 = Question(self.test_form.id, test_section.id,
                                       'Test Question 2', 'Enter something', 2,
                                       'short-text', None)
        _add_object_to_db(self.test_question2)

        self.test_response = Response(self.test_form.id,
                                      self.other_user_data['id'])
        _add_object_to_db(self.test_response)

        self.test_answer1 = Answer(self.test_response.id,
                                   self.test_question.id, 'My Answer')
        _add_object_to_db(self.test_answer1)

        db.session.flush()
Beispiel #15
0
    def post(self, event_id):
        req_parser = reqparse.RequestParser()
        req_parser.add_argument('is_open', type=bool, required=True)
        req_parser.add_argument('nominations', type=bool, required=True)
        req_parser.add_argument('sections',
                                type=dict,
                                required=True,
                                action='append')
        args = req_parser.parse_args()

        app_form = application_form_repository.get_by_event_id(event_id)
        if app_form:
            return APPLICATION_FORM_EXISTS

        is_open = args['is_open']
        nominations = args['nominations']

        app_form = ApplicationForm(event_id, is_open, nominations)
        application_form_repository.add(app_form)
        sections_data = args['sections']

        # Keep track of which objects match with which incoming data for populating dependencies later.
        section_data_map = {}
        question_data_map = {}
        question_id_map = {}

        for section_data in sections_data:
            section = Section(app_form.id,
                              section_data['order'],
                              key=section_data['key'])
            application_form_repository.add(section)
            section_data_map[section] = section_data

            languages = section_data['name'].keys()
            for language in languages:
                section_translation = SectionTranslation(
                    section.id, language, section_data['name'][language],
                    section_data['description'][language],
                    section_data['show_for_values'][language])
                application_form_repository.add(section_translation)

            for question_data in section_data['questions']:
                # application_form_id, section_id, order, questionType, is_required=True
                question = Question(app_form.id, section.id,
                                    question_data['order'],
                                    question_data['type'],
                                    question_data['is_required'])
                application_form_repository.add(question)
                question_data_map[question] = question_data

                if "surrogate_id" in question_data:
                    question_id_map[
                        question_data["surrogate_id"]] = question.id

                for language in languages:
                    question_translation = QuestionTranslation(
                        question_id=question.id,
                        language=language,
                        headline=question_data['headline'][language],
                        description=question_data['description'][language],
                        placeholder=question_data['placeholder'][language],
                        validation_regex=question_data['validation_regex']
                        [language],
                        validation_text=question_data['validation_text']
                        [language],
                        options=question_data['options'][language],
                        show_for_values=question_data['show_for_values']
                        [language])
                    application_form_repository.add(question_translation)

        # Now that all the questions have been created, we can populate the dependencies
        for section, section_data in section_data_map.items():
            if section_data['depends_on_question_id']:
                section.depends_on_question_id = question_id_map[
                    section_data['depends_on_question_id']]

        for question, question_data in question_data_map.items():
            if question_data['depends_on_question_id']:
                question.depends_on_question_id = question_id_map[
                    question_data['depends_on_question_id']]

        app_form = application_form_repository.get_by_id(app_form.id)
        return app_form, 201