def test_authentication_response(self): self.seed_static_data() response = self.app.post('/api/v1/user', data=USER_DATA) data = json.loads(response.data) user = db.session.query(AppUser).filter( AppUser.id == data['id']).first() response = self.app.get('/api/v1/verify-email?token=' + user.verify_token) role1 = EventRole('admin', data['id'], self.event1_id) role2 = EventRole('reviewer', data['id'], self.event2_id) db.session.add(role1) db.session.add(role2) db.session.commit() db.session.flush() response = self.app.post('/api/v1/authenticate', data=AUTH_DATA) data = json.loads(response.data) self.assertEqual(data['firstname'], USER_DATA['firstname']) self.assertEqual(data['lastname'], USER_DATA['lastname']) self.assertEqual(data['title'], USER_DATA['user_title']) self.assertEqual(data['roles'], [ { 'event_id': self.event1_id, 'role': 'admin' }, { 'event_id': self.event2_id, 'role': 'reviewer' }, ])
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()
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()
def seed_static_data(self): test_user = self.add_user('*****@*****.**') test_user2 = self.add_user('*****@*****.**') event_admin = self.add_user('*****@*****.**') db.session.commit() self.add_organisation('Deep Learning Indaba') self.add_organisation('Deep Learning IndabaX') db.session.commit() db.session.add(UserCategory('Postdoc')) db.session.add(Country('South Africa')) self.event1 = self.add_event('Indaba', 'Indaba Event', datetime.now(), datetime.now(), 'LBFSOLVER') self.event2 = self.add_event('IndabaX', 'IndabaX Sudan', datetime.now(), datetime.now(), 'NAGSOLVER', 2) db.session.commit() adminRole = EventRole('admin', event_admin.id, self.event1.id) db.session.add(adminRole) db.session.commit() self.event1_id = self.event1.id self.event2_id = self.event2.id self.headers = self.get_auth_header_for("*****@*****.**") self.adminHeaders = self.get_auth_header_for("*****@*****.**") db.session.flush()
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()
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()
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 = self.add_event({'en': 'Indaba 2019'}, {'en': 'Deep Learning Indaba'}, datetime(2019, 8, 25), datetime(2019, 8, 31), 'COOLER', 1, '*****@*****.**', 'indaba.deeplearning') db.session.add(event) db.session.commit() email_templates = [ EmailTemplate('application-not-submitted', None, 'Application Not Submitted', '', 'en'), EmailTemplate('application-not-started', None, 'Application Not Started', '', 'en') ] 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 = self.create_application_form(1, True, False) db.session.add(application_form) db.session.commit() submitted_response = self.add_response(application_form.id, self.test_users[0].id, is_submitted=True) withdrawn_response = self.add_response(application_form.id, self.test_users[3].id, is_withdrawn=True) self.add_response(application_form.id, self.test_users[1].id) self.add_response(application_form.id, self.test_users[4].id) self.add_email_template('application-not-submitted') self.add_email_template('application-not-started')
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()
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()
def seed_static_data(self): 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) test_user2 = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr', 1, 1, 'Male', 'University', 'Computer Science', 'None', 1, datetime(1984, 12, 12), 'Zulu', '123456') test_user2.verified_email = True db.session.add(test_user2) db.session.add(UserCategory('Postdoc')) db.session.add(Country('South Africa')) event_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms', 1, 1, 'F', 'NWU', 'Math', 'NA', 1, datetime(1984, 12, 12), 'Eng', '123456') event_admin.verified_email = True db.session.add(event_admin) self.event1 = Event('Indaba', 'Indaba Event', datetime.now(), datetime.now()) self.event2 = Event('IndabaX', 'IndabaX Sudan', datetime.now(), datetime.now()) db.session.add(self.event1) db.session.add(self.event2) adminRole = EventRole('admin', 3, 1) db.session.add(adminRole) db.session.commit() self.event1_id = self.event1.id self.event2_id = self.event2.id self.headers = self.get_auth_header_for("*****@*****.**") self.adminHeaders = self.get_auth_header_for("*****@*****.**") db.session.flush()
def setup_responses(self): 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) 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) self.add_response(1, 1, is_submitted=True) self.add_response(1, 2, is_withdrawn=True) self.add_response(2, 3, is_submitted=True)
def add_reviewer_role(self, user_id, event_id): event_role = EventRole('reviewer', user_id, event_id) db.session.add(event_role) db.session.commit()
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()
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()