示例#1
0
文件: tests.py 项目: s-mawjee/Baobab
    def test_get_attendance_list(self):
        self.seed_static_data()

        # Create an unconfirmed user
        attendee2 = AppUser('*****@*****.**', 'attendee2', 'attendee2',
                            'Ms', 1, 1, 'M', 'Wits', 'CS', 'NA', 1,
                            datetime(1984, 12, 12), 'Eng', 'abc')

        self.attendee2 = attendee2
        db.session.add(attendee2)
        db.session.commit()

        offer2 = Offer(user_id=attendee2.id,
                       event_id=self.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(offer2)
        db.session.commit()

        registration2 = Registration(offer_id=offer2.id,
                                     registration_form_id=self.form.id,
                                     confirmed=False)
        db.session.add(registration2)
        db.session.commit()

        header = self.get_auth_header_for('*****@*****.**')

        user_id = 1
        params = {'event_id': 1}
        result = self.app.get('/api/v1/registration/confirmed',
                              headers=header,
                              data=params)
        data = json.loads(result.data)
        self.assertEqual(len(data), 2)
        self.assertEqual(data[0]['user_id'], user_id)

        params = {'user_id': user_id, 'event_id': 1}
        self.app.post('/api/v1/attendance', headers=header, data=params)

        # Exclude signed in
        params = {'event_id': 1, 'exclude_already_signed_in': True}
        result2 = self.app.get('/api/v1/registration/confirmed',
                               headers=header,
                               data=params)
        data2 = json.loads(result2.data)
        self.assertEqual(len(data2), 1)

        # Include signed in - possible to undo
        params = {'exclude_already_signed_in': 'false', 'event_id': 1}
        LOGGER.debug(params)
        result2 = self.app.get('/api/v1/registration/confirmed',
                               headers=header,
                               data=params)
        data2 = json.loads(result2.data)
        self.assertEqual(len(data2), 2)
示例#2
0
    def seed_static_data(self, add_offer=True):
        test_user = self.add_user('*****@*****.**')
        offer_admin = self.add_user('*****@*****.**',
                                    'event_admin',
                                    is_admin=True)
        self.add_organisation('Deep Learning Indaba', 'blah.png',
                              'blah_big.png', 'deeplearningindaba')
        db.session.add(UserCategory('Offer Category'))
        db.session.add(Country('Suid Afrika'))
        db.session.commit()

        event = self.add_event(name="Tech Talk",
                               description="tech talking",
                               start_date=datetime(2019, 12, 12),
                               end_date=datetime(2020, 12, 12),
                               key='SPEEDNET')
        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()
示例#3
0
    def post(self):
        args = self.req_parser.parse_args()
        user_id = args['user_id']
        event_id = args['event_id']
        email_template = args['email_template']
        offer_date = datetime.strptime((args['offer_date']),
                                       '%Y-%m-%dT%H:%M:%S.%fZ')
        expiry_date = datetime.strptime((args['expiry_date']),
                                        '%Y-%m-%dT%H:%M:%S.%fZ')
        payment_required = args['payment_required']
        travel_award = args['travel_award']
        accommodation_award = args['accommodation_award']
        user = db.session.query(AppUser).filter(AppUser.id == user_id).first()
        event_name = db.session.query(Event).filter(
            Event.id == event_id).first().name

        existing_offer = db.session.query(Offer).filter(
            Offer.user_id == user_id, Offer.event_id == event_id).first()
        if existing_offer:
            return errors.DUPLICATE_OFFER

        existing_outcome = outcome_repository.get_latest_by_user_for_event(
            user_id, event_id)
        if existing_outcome:
            if existing_outcome.status == Status.REJECTED:
                return errors.CANDIDATE_REJECTED
            existing_outcome.reset_latest()

        new_outcome = Outcome(event_id, user_id, Status.ACCEPTED,
                              g.current_user['id'])
        outcome_repository.add(new_outcome)

        offer_entity = Offer(user_id=user_id,
                             event_id=event_id,
                             offer_date=offer_date,
                             expiry_date=expiry_date,
                             payment_required=payment_required,
                             travel_award=travel_award,
                             accommodation_award=accommodation_award)

        db.session.add(offer_entity)
        db.session.commit()

        if user.email:
            email_body_template = email_template or OFFER_EMAIL_BODY
            send_mail(
                recipient=user.email,
                subject='{} Application Status Update'.format(event_name),
                body_text=email_body_template.format(
                    user_title=user.user_title,
                    first_name=user.firstname,
                    last_name=user.lastname,
                    event_name=event_name,
                    host=misc.get_baobab_host(),
                    expiry_date=offer_entity.expiry_date.strftime("%Y-%m-%d")))

            LOGGER.debug("Sent an offer email to {}".format(user.email))

        return offer_info(offer_entity), 201
示例#4
0
    def post(self):
        args = self.req_parser.parse_args()
        user_id = args['user_id']
        event_id = args['event_id']
        email_template = args['email_template']
        offer_date = datetime.strptime((args['offer_date']), '%Y-%m-%dT%H:%M:%S.%fZ')
        expiry_date = datetime.strptime((args['expiry_date']), '%Y-%m-%dT%H:%M:%S.%fZ')
        payment_required = args['payment_required']
        travel_award = args['travel_award']
        accommodation_award = args['accommodation_award']
        user = db.session.query(AppUser).filter(AppUser.id == user_id).first()
        event = db.session.query(Event).filter(Event.id == event_id).first()
        event_name = event.get_name('en')
        event_email_from = event.email_from

        existing_offer = db.session.query(Offer).filter(Offer.user_id == user_id, Offer.event_id == event_id).first()
        if existing_offer:
            return errors.DUPLICATE_OFFER

        existing_outcome = outcome_repository.get_latest_by_user_for_event(user_id, event_id)
        if existing_outcome:
            if existing_outcome.status == Status.REJECTED:
                return errors.CANDIDATE_REJECTED
            existing_outcome.reset_latest()

        new_outcome = Outcome(
            event_id,
            user_id,
            Status.ACCEPTED,
            g.current_user['id']
        )
        outcome_repository.add(new_outcome)

        offer_entity = Offer(
            user_id=user_id,
            event_id=event_id,
            offer_date=offer_date,
            expiry_date=expiry_date,
            payment_required=payment_required,
            travel_award=travel_award,
            accommodation_award=accommodation_award
        )

        db.session.add(offer_entity)
        db.session.commit()

        email_user(
            'offer',
            template_parameters=dict(
                host=misc.get_baobab_host(),
                expiry_date=offer_entity.expiry_date.strftime("%Y-%m-%d"),
                event_email_from=event_email_from
            ),
            event=event,
            user=user)

        return offer_info(offer_entity), 201
示例#5
0
    def test_offer(self):
        """Test statuses when offer."""
        self.seed_static_data()

        outcome = Outcome(self.event.id, self.user1.id, OutcomeStatus.ACCEPTED,
                          self.user2.id)
        db.session.add(outcome)

        self.add_response(self.application_form.id,
                          self.user1.id,
                          is_submitted=True)

        # Test pending offer
        offer = Offer(user_id=self.user1.id,
                      event_id=self.event.id,
                      offer_date=date.today(),
                      expiry_date=date.today() + timedelta(days=1),
                      payment_required=False,
                      travel_award=False,
                      accommodation_award=False)
        db.session.add(offer)
        db.session.commit()

        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertEqual(status.application_status, 'Submitted')
        self.assertEqual(status.outcome_status, outcome.status.name)
        self.assertEqual(status.offer_status, 'Pending')

        # Test accepted offer
        offer.candidate_response = True
        db.session.commit()
        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertIsNone(status.invited_guest)
        self.assertIsNone(status.registration_status)
        self.assertEqual(status.application_status, 'Submitted')
        self.assertEqual(status.outcome_status, outcome.status.name)
        self.assertEqual(status.offer_status, 'Accepted')

        # Should still be accepted when past the expiry date
        offer.expiry_date = date.today() - timedelta(days=2)
        db.session.commit()
        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.offer_status, 'Accepted')

        # Test expired offer
        offer.candidate_response = None
        db.session.commit()
        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.offer_status, 'Expired')

        # Test rejected offer
        offer.candidate_response = False
        db.session.commit()
        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.offer_status, 'Rejected')
示例#6
0
    def add_offer(self, user_id, event_id=1, offer_date=None, expiry_date=None, payment_required=False, travel_award=False, accommodation_award=False, candidate_response=None):
        offer_date = offer_date or datetime.now()
        expiry_date = expiry_date or datetime.now() + timedelta(10)

        offer = Offer(
            user_id=user_id, 
            event_id=event_id, 
            offer_date=offer_date, 
            expiry_date=expiry_date,
            payment_required=payment_required,
            travel_award=travel_award,
            accommodation_award=accommodation_award,
            candidate_response=candidate_response)

        db.session.add(offer)
        db.session.commit()
        return offer
示例#7
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()
示例#8
0
    def test_registered(self):
        """Test statusess for registered attendees."""
        self.seed_static_data()

        outcome = Outcome(self.event.id, self.user1.id, OutcomeStatus.ACCEPTED,
                          self.user2.id)
        db.session.add(outcome)

        self.add_response(self.application_form.id,
                          self.user1.id,
                          is_submitted=True)

        offer = Offer(user_id=self.user1.id,
                      event_id=self.event.id,
                      offer_date=date.today(),
                      expiry_date=date.today() + timedelta(days=1),
                      payment_required=False,
                      travel_award=False,
                      accommodation_award=False,
                      candidate_response=True)
        db.session.add(offer)
        db.session.commit()

        registration = Registration(offer.id, self.registration_form.id)
        db.session.add(registration)
        db.session.commit()

        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertIsNone(status.invited_guest)
        self.assertEqual(status.registration_status, 'Not Confirmed')
        self.assertEqual(status.application_status, 'Submitted')
        self.assertEqual(status.outcome_status, outcome.status.name)
        self.assertEqual(status.offer_status, 'Accepted')

        registration.confirm()
        db.session.commit()

        status = event_status.get_event_status(self.event.id, self.user1.id)
        self.assertEqual(status.registration_status, 'Confirmed')
示例#9
0
    def seed_static_data(self):
        test_user = self.add_user('*****@*****.**', 'Some', 'Thing', 'Mr')
        event_admin = self.add_user('*****@*****.**',
                                    'event_admin',
                                    is_admin=True)
        self.add_organisation('Deep Learning Indaba', 'blah.png',
                              'blah_big.png')
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

        event = self.add_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),
                               key='SPEEDNET')
        db.session.commit()

        self.event_id = event.id

        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)

        offer.candidate_response = True
        offer.accepted_travel_award = True

        db.session.add(offer)
        db.session.commit()
        self.offer_id = offer.id

        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()

        section2 = RegistrationSection(
            registration_form_id=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()

        question = RegistrationQuestion(section_id=section.id,
                                        registration_form_id=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(question)
        db.session.commit()

        question2 = RegistrationQuestion(section_id=section2.id,
                                         registration_form_id=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(question2)
        db.session.commit()

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

        db.session.flush()
示例#10
0
    def seed_static_data(self, create_registration=False):
        test_user = self.add_user('*****@*****.**', 'Some', 'Thing', 'Mr')
        test_user2 = self.add_user('*****@*****.**', 'Something2',
                                   'Thing2', 'Mrs')
        event_admin = self.add_user('*****@*****.**',
                                    'event_admin',
                                    is_admin=True)

        self.add_organisation('Deep Learning Indaba', 'blah.png',
                              'blah_big.png')
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        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),
                      key='SPEEDNET',
                      organisation_id=1,
                      email_from='*****@*****.**',
                      url='indaba.deeplearning',
                      application_open=datetime.now(),
                      application_close=datetime.now(),
                      review_open=datetime.now(),
                      review_close=datetime.now(),
                      selection_open=datetime.now(),
                      selection_close=datetime.now(),
                      offer_open=datetime.now(),
                      offer_close=datetime.now(),
                      registration_open=datetime.now(),
                      registration_close=datetime.now())
        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()
示例#11
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()
示例#12
0
文件: tests.py 项目: s-mawjee/Baobab
    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()
示例#13
0
文件: tests.py 项目: s-mawjee/Baobab
    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()
示例#14
0
    def seed_static_data(self):
        self.add_organisation('Deep Learning Indaba')
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

        test_user = self.add_user('*****@*****.**')
        test_user_2 = self.add_user('*****@*****.**')
        db.session.commit()

        event = self.add_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),
                               key='REGINAL',
                               organisation_id=1,
                               email_from='*****@*****.**',
                               url='indaba.deeplearning')

        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()
示例#15
0
    def seed_static_data(self):
        self.add_organisation('Deep Learning Indaba', 'blah.png',
                              'blah_big.png', 'deeplearningindaba')
        user_category = UserCategory('PhD')
        db.session.add(user_category)
        db.session.commit()

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

        self.attendee = self.add_user(email='*****@*****.**')

        registration_admin = self.add_user('*****@*****.**')

        event = self.add_event(
            'indaba 2019',
            'The Deep Learning Indaba 2019, Kenyatta University, Nairobi, Kenya ',
            datetime(2019, 8, 25), datetime(2019, 8, 31), 'JOLLOF')
        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=self.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()