Example #1
0
    def post(self):
        args = self.req_parser.parse_args()

        user = AppUser(username=args['username'],
                       usertype=args['usertype'],
                       email=args['email'],
                       password=args['password'])
        db.session.add(user)

        try:
            db.session.commit()
        except IntegrityError:
            return EMAIL_IN_USE

        return {
            'id': user.id,
            'token': generate_token(user).decode('UTF-8')
        }, 201
Example #2
0
    def seed_static_data(self, add_offer=True):
        db.session.add(UserCategory('Offer Category'))
        db.session.add(Country('Suid Afrika'))
        db.session.commit()
        db.session.commit()

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

        offer_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms',
                              1, 1, 'F', 'NWU', 'Math', 'NA', 1,
                              datetime(1984, 12, 12), 'Eng', '654321', True)
        offer_admin.verified_email = True
        db.session.add(offer_admin)

        db.session.commit()

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12),
            end_date=datetime(2020, 12, 12),
        )
        db.session.add(event)
        db.session.commit()

        if add_offer:
            offer = Offer(user_id=test_user.id,
                          event_id=event.id,
                          offer_date=datetime.now(),
                          expiry_date=datetime.now() + timedelta(days=15),
                          payment_required=False,
                          travel_award=True,
                          accommodation_award=False)
            db.session.add(offer)
            db.session.commit()

        self.headers = self.get_auth_header_for("*****@*****.**")
        self.adminHeaders = self.get_auth_header_for("*****@*****.**")

        db.session.flush()
Example #3
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 = [
            self.add_event({'en': 'Indaba'}, {'en': 'Indaba Event'},
                           datetime.now(), datetime.now(), 'ADAMOPTIM'),
            self.add_event({'en': 'Indaba2'}, {'en': 'Indaba Event 2'},
                           datetime.now(), datetime.now(), 'HACFTET', 2)
        ]

        application_forms = [
            self.create_application_form(1, True, False),
            self.create_application_form(2, False, False)
        ]
        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()
        self.add_response(1, 1, is_submitted=True)
        self.add_response(2, 2, is_submitted=True)
Example #4
0
 def setup_verified_user(self):
     user = AppUser(email='*****@*****.**', firstname='Some', lastname='Thing', user_title='Mr',password= '******', organisation_id=1)
     user.verify_token = 'existing token'
     user.verify()
     db.session.add(user)
     db.session.commit()
Example #5
0
    def seed_static_data(self, create_registration=False):
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

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

        test_user2 = AppUser('*****@*****.**', 'Something2', 'Thing2', 'Mrs', 1, 1,
                            'Female', 'University of Indaba', 'Machine Learning', 'None', 1,
                            datetime(1985, 2, 3),
                            'Zulu',
                            '123456')
        test_user2.verified_email = True
        db.session.add(test_user2)
        db.session.commit()

        event_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms', 1,
                              1, 'F', 'NWU', 'Math', 'NA', 1, datetime(1984, 12, 12), 'Eng', '123456', True)
        event_admin.verified_email = True
        db.session.add(event_admin)

        db.session.commit()

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12, 10, 10, 10),
            end_date=datetime(2020, 12, 12, 10, 10, 10),

        )
        db.session.add(event)
        db.session.commit()

        self.offer = Offer(
            user_id=test_user.id,
            event_id=event.id,
            offer_date=datetime.now(),
            expiry_date=datetime.now() + timedelta(days=15),
            payment_required=False,
            travel_award=True,
            accommodation_award=False,
            responded_at=datetime.now())
        self.offer.candidate_response = True
        self.offer.accepted_travel_award = True
        db.session.add(self.offer)
        db.session.commit()

        self.offer2 = Offer(
            user_id=test_user2.id,
            event_id=event.id,
            offer_date=datetime.now(),
            expiry_date=datetime.now() + timedelta(days=15),
            payment_required=True,
            travel_award=True,
            accommodation_award=False,
            responded_at=datetime.now())
        db.session.add(self.offer2)
        db.session.commit()

        self.offer3 = Offer(
            user_id=event_admin.id,
            event_id=event.id,
            offer_date=datetime.now(),
            expiry_date=datetime.now() + timedelta(days=15),
            payment_required=True,
            travel_award=False,
            accommodation_award=True,
            responded_at=datetime.now())
        db.session.add(self.offer3)
        db.session.commit()

        self.form = RegistrationForm(
            event_id=event.id
        )
        db.session.add(self.form)
        db.session.commit()

        section = RegistrationSection(
            registration_form_id=self.form.id,
            name="Section 1",
            description="the section description",
            order=1,
            show_for_travel_award=True,
            show_for_accommodation_award=False,
            show_for_payment_required=False,
        )
        db.session.add(section)
        db.session.commit()

        section2 = RegistrationSection(
            registration_form_id=self.form.id,
            name="Section 2",
            description="the section 2 description",
            order=1,
            show_for_travel_award=True,
            show_for_accommodation_award=False,
            show_for_payment_required=False,
        )
        db.session.add(section2)
        db.session.commit()

        self.question = RegistrationQuestion(
            section_id=section.id,
            registration_form_id=self.form.id,
            description="Question 1",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text"
        )
        db.session.add(self.question)
        db.session.commit()

        self.question2 = RegistrationQuestion(
            section_id=section2.id,
            registration_form_id=self.form.id,
            description="Question 2",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text"
        )
        db.session.add(self.question2)
        db.session.commit()

        self.question3 = RegistrationQuestion(
            section_id=section2.id,
            registration_form_id=self.form.id,
            description="Question 3",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text"
        )
        db.session.add(self.question3)
        db.session.commit()

        self.headers = self.get_auth_header_for("*****@*****.**")
        self.headers2 = self.get_auth_header_for("*****@*****.**")
        self.adminHeaders = self.get_auth_header_for("*****@*****.**")

        if create_registration:
            self.registration1 = Registration(self.offer.id, self.form.id, confirmed=False)
            db.session.add(self.registration1)
            db.session.commit()
            self.registration2 = Registration(self.offer2.id, self.form.id, confirmed=True)
            db.session.add(self.registration2)
            db.session.commit()
            self.registration3 = Registration(self.offer3.id, self.form.id, confirmed=False)
            db.session.add(self.registration3)
            db.session.commit()

        db.session.flush()
Example #6
0
    def seed_static_data(self):
        user_category = UserCategory('PhD')
        db.session.add(user_category)

        country = Country('South Africa')
        db.session.add(country)

        attendee = AppUser('*****@*****.**', 'attendee', 'attendee', 'Mr',
                           1, 1, 'M', 'Wits', 'CS', 'NA', 1,
                           datetime(1984, 12, 12), 'Eng', 'abc')

        self.attendee = attendee

        registration_admin = AppUser('*****@*****.**', 'registration', 'admin',
                                     'Ms', 1, 1, 'F', 'NWU', 'Math', 'NA', 1,
                                     datetime(1984, 12, 12), 'Eng', 'abc')
        users = [attendee, registration_admin]

        for user in users:
            user.verify()
        db.session.add_all(users)

        event = Event(
            'indaba 2019',
            'The Deep Learning Indaba 2019, Kenyatta University, Nairobi, Kenya ',
            datetime(2019, 8, 25), datetime(2019, 8, 31))
        self.event = event
        db.session.add(self.event)

        event_role = EventRole('registration-admin', 2, 1)
        db.session.add(event_role)
        db.session.commit()
        offer = Offer(user_id=attendee.id,
                      event_id=event.id,
                      offer_date=datetime.now(),
                      expiry_date=datetime.now() + timedelta(days=15),
                      payment_required=False,
                      accommodation_award=True,
                      travel_award=True,
                      accepted_accommodation_award=True,
                      accepted_travel_award=True)
        db.session.add_all([offer])

        form = RegistrationForm(event_id=event.id)
        db.session.add(form)
        db.session.commit()
        self.form = form
        section = RegistrationSection(
            registration_form_id=form.id,
            name="Section 1",
            description="the section description",
            order=1,
            show_for_travel_award=True,
            show_for_accommodation_award=False,
            show_for_payment_required=False,
        )
        db.session.add(section)
        db.session.commit()
        rq = RegistrationQuestion(section_id=section.id,
                                  registration_form_id=form.id,
                                  description="Will you be bringing a poster?",
                                  type="short-text",
                                  is_required=True,
                                  order=1,
                                  placeholder="the placeholder",
                                  headline="Will you be bringing a poster?",
                                  validation_regex="[]/",
                                  validation_text=" text")
        db.session.add(rq)
        db.session.commit()

        registration = Registration(offer_id=offer.id,
                                    registration_form_id=form.id,
                                    confirmed=True)

        db.session.add_all([registration])
        db.session.commit()
        ra = RegistrationAnswer(registration_id=registration.id,
                                registration_question_id=rq.id,
                                value="yes")
        db.session.add_all([ra])
        db.session.commit()
Example #7
0
class EventAPITest(ApiTestCase):

    test_event_data_dict = {
        'name':
        'Test Event',
        'description':
        'Test Event Description',
        'start_date':
        datetime(2020, 6, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'end_date':
        datetime(2020, 6, 6).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'key':
        'testevent',
        'organisation_id':
        1,
        'email_from':
        '*****@*****.**',
        'url':
        'testindaba.com',
        'application_open':
        datetime(2020, 1, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'application_close':
        datetime(2020, 2, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'review_open':
        datetime(2020, 2, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'review_close':
        datetime(2020, 3, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'selection_open':
        datetime(2020, 3, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'selection_close':
        datetime(2020, 5, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'offer_open':
        datetime(2020, 5, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'offer_close':
        datetime(2020, 5, 30).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'registration_open':
        datetime(2020, 5, 30).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'registration_close':
        datetime(2020, 6, 1).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
        'event_type':
        'EVENT'
    }

    def seed_static_data(self):
        self.add_organisation('Test Indaba', 'blah.png', 'blah_big.png',
                              'testindaba')

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

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

        self.test_admin_user = AppUser(email='*****@*****.**',
                                       firstname='Some',
                                       lastname='One',
                                       user_title='Mr',
                                       password='******',
                                       organisation_id=1,
                                       is_admin=True)
        self.test_admin_user.verify()
        db.session.add(self.test_admin_user)
        db.session.commit()
        self.test_user = AppUser(email='*****@*****.**',
                                 firstname='Some',
                                 lastname='One',
                                 user_title='Mr',
                                 password='******',
                                 organisation_id=1)
        self.test_user.verify()
        db.session.add(self.test_user)
        db.session.commit()

        event = self.add_event('Indaba 2019', 'Deep Learning Indaba',
                               datetime(2019, 8, 25), datetime(2019, 8, 31),
                               'COOLER')
        db.session.commit()

        db.session.flush()

    def get_auth_header_for(self, email):
        body = {'email': email, 'password': '******'}
        response = self.app.post('api/v1/authenticate', data=body)
        data = json.loads(response.data)
        header = {'Authorization': data['token']}
        LOGGER.debug('here')
        return header

    def test_post_event_unauthed(self):
        self.seed_static_data()
        response = self.app.post('api/v1/event',
                                 data=self.test_event_data_dict)
        self.assertEqual(response.status_code, 401)

    def test_put_event_unauthed(self):
        self.seed_static_data()
        response = self.app.put('api/v1/event', data=self.test_event_data_dict)
        self.assertEqual(response.status_code, 401)

    def test_post_event_not_admin(self):
        self.seed_static_data()
        header = self.get_auth_header_for(self.test_user.email)
        response = self.app.post('api/v1/event',
                                 headers=header,
                                 data=self.test_event_data_dict)
        self.assertEqual(response.status_code, 403)

    def test_post_event_is_admin(self):
        self.seed_static_data()
        header = self.get_auth_header_for(self.test_admin_user.email)
        response = self.app.post('api/v1/event',
                                 headers=header,
                                 data=self.test_event_data_dict)
        self.assertEqual(response.status_code, 201)

    def test_post_event_eventrole_added(self):
        self.seed_static_data()
        header = self.get_auth_header_for(self.test_admin_user.email)
        event_response = self.app.post('api/v1/event',
                                       headers=header,
                                       data=self.test_event_data_dict)
        event_data = json.loads(event_response.data)
        self.assertEqual(event_response.status_code, 201)

        body = {'email': self.test_admin_user.email, 'password': '******'}
        response = self.app.post('api/v1/authenticate', data=body)
        data = json.loads(response.data)
        self.assertEqual(len(data['roles']), 1)
        for event_role in data['roles']:
            if event_role['event_id'] == event_data['id']:
                self.assertEqual(data['roles'][0]['role'], 'admin')

    def test_put_event_is_admin(self):
        self.seed_static_data()
        header = self.get_auth_header_for(self.test_admin_user.email)
        # update(put) event
        self.test_event_data_dict['id'] = 1
        self.test_event_data_dict['name'] = 'Test Event Updated'
        response = self.app.put('api/v1/event',
                                headers=header,
                                data=self.test_event_data_dict)
        data = json.loads(response.data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(data['name'], 'Test Event Updated')

    def test_put_event_not_admin(self):
        self.seed_static_data()

        # update(put) event by non-admin user
        # get auth header for non admin user
        header = self.get_auth_header_for(self.test_user.email)

        self.test_event_data_dict['id'] = 1
        self.test_event_data_dict['name'] = 'Test Event Updated'

        response = self.app.put('api/v1/event',
                                headers=header,
                                data=self.test_event_data_dict)
        self.assertEqual(response.status_code, 403)
Example #8
0
    def seed_static_data(self):
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

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

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

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12, 10, 10, 10),
            end_date=datetime(2020, 12, 12, 10, 10, 10),
        )
        db.session.add(event)
        db.session.commit()

        offer = Offer(user_id=test_user.id,
                      event_id=event.id,
                      offer_date=datetime.now(),
                      expiry_date=datetime.now() + timedelta(days=15),
                      payment_required=False,
                      accommodation_award=True,
                      travel_award=True,
                      accepted_accommodation_award=True,
                      accepted_travel_award=True)
        db.session.add(offer)
        db.session.commit()

        offer_2 = Offer(
            user_id=test_user_2.id,
            event_id=event.id,
            offer_date=datetime.now(),
            expiry_date=datetime.now() + timedelta(days=15),
            payment_required=True,
            accommodation_award=False,
            travel_award=False,
            accepted_accommodation_award=False,
            accepted_travel_award=False,
        )
        db.session.add(offer_2)
        db.session.commit()

        form = RegistrationForm(event_id=event.id)
        db.session.add(form)
        db.session.commit()

        section = RegistrationSection(
            registration_form_id=form.id,
            name="Section 1",
            description="the section description",
            order=1,
            show_for_travel_award=True,
            show_for_accommodation_award=False,
            show_for_payment_required=False,
        )
        db.session.add(section)
        db.session.commit()

        rq = RegistrationQuestion(section_id=section.id,
                                  registration_form_id=form.id,
                                  description="Will you be bringing a poster?",
                                  type="short-text",
                                  is_required=True,
                                  order=1,
                                  placeholder="the placeholder",
                                  headline="Will you be bringing a poster?",
                                  validation_regex="[]/",
                                  validation_text=" text")
        db.session.add(rq)
        db.session.commit()

        registration = Registration(offer_id=offer.id,
                                    registration_form_id=form.id,
                                    confirmed=True)
        db.session.add(registration)
        db.session.commit()

        registration_2 = Registration(offer_id=offer_2.id,
                                      registration_form_id=form.id,
                                      confirmed=True)
        db.session.add(registration_2)
        db.session.commit()

        ra = RegistrationAnswer(registration_id=registration_2.id,
                                registration_question_id=rq.id,
                                value="yes")
        db.session.add(ra)
        db.session.commit()

        template = InvitationTemplate(
            event_id=event.id,
            template_path="Indaba 2019  - Invitation Letter - General.docx",
            send_for_travel_award_only=False,
            send_for_accommodation_award_only=False,
            send_for_both_travel_accommodation=True)
        db.session.add(template)

        template_2 = InvitationTemplate(
            event_id=event.id,
            template_path=
            "Indaba 2019 - Invitation Letter - Travel & Accomodation.docx",
            send_for_travel_award_only=False,
            send_for_accommodation_award_only=False,
            send_for_both_travel_accommodation=False)
        db.session.add(template_2)
        db.session.commit()

        self.headers = self.get_auth_header_for("*****@*****.**")
        self.headers_2 = self.get_auth_header_for("*****@*****.**")

        db.session.flush()
Example #9
0
    def post(self, invitedGuest=False):
        args = self.req_parser.parse_args()
        email = args['email']
        firstname = args['firstname']
        lastname = args['lastname']
        user_title = args['user_title']
        policy_agreed = args['policy_agreed']
        user_primaryLanguage = args['language']

        if(invitedGuest):
            password = self.randomPassword()
        else:
            password = args['password']

        if(password is None):
            return MISSING_PASSWORD
        
        if not policy_agreed:
            return POLICY_NOT_AGREED

        LOGGER.info("Registering email: {}".format(email))

        user = AppUser(
            email=email,
            firstname=firstname,
            lastname=lastname,
            user_title=user_title,
            password=password,
            organisation_id=g.organisation.id)
        user.user_primaryLanguage = user_primaryLanguage

        db.session.add(user)

        try:
            db.session.commit()
        except IntegrityError:
            LOGGER.error("email: {} already in use".format(email))
            return EMAIL_IN_USE

        if(not invitedGuest):
            email_user(
                'verify-email',
                template_parameters=dict(
                    system=g.organisation.system_name,
                    organisation=g.organisation.name,
                    host=misc.get_baobab_host(),
                    token=user.verify_token
                ),
                user=user,
                subject_parameters=dict(system=g.organisation.system_name))

            LOGGER.debug("Sent verification email to {}".format(user.email))
        else:
            user.verified_email = True
            try:
                db.session.commit()
            except IntegrityError:
                LOGGER.error("Unable to verify email: {}".format(email))
                return VERIFY_EMAIL_INVITED_GUEST

        return user_info(user, []), 201
Example #10
0
    def seed_static_data(self):
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

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

        event_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms',
                              1, 1, 'F', 'NWU', 'Math', 'NA', 1,
                              datetime(1984, 12, 12), 'Eng', '123456', True)
        event_admin.verified_email = True
        db.session.add(event_admin)

        db.session.commit()

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12, 10, 10, 10),
            end_date=datetime(2020, 12, 12, 10, 10, 10),
        )
        db.session.add(event)
        db.session.commit()

        self.form = RegistrationForm(event_id=event.id)
        db.session.add(self.form)
        db.session.commit()

        self.event_id = event.id

        section = RegistrationSection(
            registration_form_id=self.form.id,
            name="Section 1",
            description="the section description",
            order=1,
            show_for_travel_award=None,
            show_for_accommodation_award=None,
            show_for_payment_required=None,
        )
        db.session.add(section)
        db.session.commit()

        section2 = RegistrationSection(
            registration_form_id=self.form.id,
            name="Section 2",
            description="the section 2 description",
            order=1,
            show_for_travel_award=None,
            show_for_accommodation_award=None,
            show_for_payment_required=None,
        )
        db.session.add(section2)
        db.session.commit()

        self.question = RegistrationQuestion(section_id=section.id,
                                             registration_form_id=self.form.id,
                                             description="Question 1",
                                             type="short-text",
                                             is_required=True,
                                             order=1,
                                             placeholder="the placeholder",
                                             headline="the headline",
                                             validation_regex="[]/",
                                             validation_text=" text")
        db.session.add(self.question)
        db.session.commit()

        self.question2 = RegistrationQuestion(
            section_id=section2.id,
            registration_form_id=self.form.id,
            description="Question 2",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text")
        db.session.add(self.question2)
        db.session.commit()

        self.question3 = RegistrationQuestion(
            section_id=section2.id,
            registration_form_id=self.form.id,
            description="Question 3",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text")
        db.session.add(self.question3)
        db.session.commit()

        self.headers = self.get_auth_header_for("*****@*****.**")
        self.adminHeaders = self.get_auth_header_for("*****@*****.**")

        db.session.flush()
Example #11
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()
Example #12
0
    def post(self, invitedGuest=False):
        args = self.req_parser.parse_args()
        email = args['email']
        firstname = args['firstname']
        lastname = args['lastname']
        user_title = args['user_title']
        nationality_country_id = args['nationality_country_id']
        residence_country_id = args['residence_country_id']
        user_gender = args['user_gender']
        affiliation = args['affiliation']
        department = args['department']
        user_disability = args['user_disability']
        user_category_id = args['user_category_id']

        if (invitedGuest):
            password = self.randomPassword()
        else:
            password = args['password']

        if (password is None):
            return MISSING_PASSWORD

        user_dateOfBirth = datetime.strptime((args['user_dateOfBirth']),
                                             '%Y-%m-%dT%H:%M:%S.%fZ')
        user_primaryLanguage = args['user_primaryLanguage']

        LOGGER.info("Registering email: {}".format(email))

        user = AppUser(email=email,
                       firstname=firstname,
                       lastname=lastname,
                       user_title=user_title,
                       nationality_country_id=nationality_country_id,
                       residence_country_id=residence_country_id,
                       user_gender=user_gender,
                       affiliation=affiliation,
                       department=department,
                       user_disability=user_disability,
                       user_category_id=user_category_id,
                       user_dateOfBirth=user_dateOfBirth,
                       user_primaryLanguage=user_primaryLanguage,
                       password=password)

        db.session.add(user)

        try:
            db.session.commit()
        except IntegrityError:
            LOGGER.error("email: {} already in use".format(email))
            return EMAIL_IN_USE

        if (not invitedGuest):
            send_mail(recipient=user.email,
                      subject='Baobab Email Verification',
                      body_text=VERIFY_EMAIL_BODY.format(
                          user_title, firstname, lastname, get_baobab_host(),
                          user.verify_token))

            LOGGER.debug("Sent verification email to {}".format(user.email))
        else:
            user.verified_email = True
            try:
                db.session.commit()
            except IntegrityError:
                LOGGER.error("Unable to verify email: {}".format(email))
                return VERIFY_EMAIL_INVITED_GUEST

        return user_info(user, []), 201