def test_invalid_username(self): print("test_invalid_username") try: Eventsystem.validate_login(6110000, 'pass6890') except ErrorMessage as error: assert error.msg == 'Please ensure the zid and password'
def test_validate_number(self): print('test_validate_number') assert Eventsystem.valida_seminar_capa(10) is True try: Eventsystem.valida_seminar_capa(-10) except ErrorMessage as error: assert error.msg == 'Capacity should greater than zero'
def registercomfirme(eventId): event = Event.query.filter_by(event_id=int(eventId)).one() user = Eventsystem.get_user(current_user) if event: Eventsystem.cal_fee(event.start, user, event) return render_template('comfirm.html', event=event, user=user) else: user.fee = 0 return 'Not find'
def user_past(): user = Eventsystem.get_user(current_user) events = user.event_users_all.all() seminars = user.seminar_users_all.all() try: Eventsystem.check_regist(events, seminars) return render_template('userpast.html', events=events, seminars=seminars) except ErrorMessage as error: return render_template('userpast.html', dash=True, message=error.msg)
def registerguest(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] try: guest = Eventsystem.make_register(username, password) Eventsystem.add_register(guest) return render_template('successful.html', user=guest) except ErrorMessage as error: return render_template('register.html', re=True, message=error.msg) return render_template('register.html')
class TestStudentRegisterSeminar(object): seminar = Seminar.query.filter_by(seminar_id=2).one() assert seminar is not None session = Session.query.filter_by(session_id=3).one() assert session is not None user = User.query.filter_by(user_id=1).one() assert user is not None assert Eventsystem.Validate_Session_regist( user, session.sessions_all.all()) is True assert Eventsystem.speakerof_seesion(user, session) is True Eventsystem.cal_fee(session.start, user, session) assert user.fee == 0.0
def registsessioncomfirm(sessionId): session = Session.query.filter_by(session_id=int(sessionId)).one() sesminar = Eventsystem.getSeminar(session) user = Eventsystem.get_user(current_user) if session: Eventsystem.cal_fee(session.start, user, session) if Eventsystem.guest_speaker(sesminar, user): user.fee = 0 return render_template('registsessioncomfirm.html', session=session, user=user) else: user.fee = 0 return redirect(url_for('page_not_found'))
def register(eventId): event = Event.query.filter_by(event_id=int(eventId)).one() user = Eventsystem.get_user(current_user) try: Eventsystem.validateRegistCourse(event) Eventsystem.check_in(user, event) event.users.append(user) db.session.commit() return render_template('info.html', event=event) except ErrorMessage as error: return render_template('info.html', event=event, event_in=True, message=error.msg)
def user_cancele(eventId): event = Event.query.filter_by(event_id=int(eventId)).one() user = Eventsystem.get_user(current_user) try: Eventsystem.validate_cancele(event.end) user = Eventsystem.check_userin(user, event.users) event.users.remove(user) db.session.commit() return render_template('info.html', event=event, cance=True, message='Cancele success') except ErrorMessage as error: return render_template('info.html', event=event, canerror=True, message=error.msg)
def Sessioncancele(sessionId): session = Session.query.filter_by(session_id=int(sessionId)).one() seminar = Eventsystem.getSeminar(session) Eventsystem.remove_session_user(session, seminar) Eventsystem.remove_all_user(session) session.status = 'CANCELED' Eventsystem.add_session(session) return redirect(url_for('index'))
def test_post_seminar(self): print('test_post_seminar') seminar = Eventsystem.make_seminar('hello', 'hehe', '01-08-2018', '01-09-2018', 10, 'OPEN', '1479201404') assert seminar is not None assert seminar.title == 'hello' assert seminar.capacity == 10 assert seminar.status == 'OPEN' assert seminar.creater == '1479201404'
def Seminarcancele(SeminarId): seminar = Seminar.query.filter_by(seminar_id=int(SeminarId)).one() Eventsystem.remove_all_user(seminar) Eventsystem.cancele_all_session(seminar) seminar.status = 'CANCELED' Eventsystem.add_seminar(seminar) return redirect(url_for('index'))
def registsession(sessionId): session = Session.query.filter_by(session_id=int(sessionId)).one() user = Eventsystem.get_user(current_user) seminar = Eventsystem.getSeminar(session) try: Eventsystem.validateRegistSession(session) Eventsystem.validateRegistSeminar(seminar) Eventsystem.Validate_Session_regist(user, session.sessions_all.all()) Eventsystem.speakerof_seesion(user, session) session.users.append(user) db.session.commit() if Eventsystem.validate_Seminar_regist(user, seminar.users): seminar.users.append(user) db.session.commit() return render_template('sessioninfo.html', sessions=session, succ=True, message='Success regist') except ErrorMessage as error: return render_template('sessioninfo.html', regist=True, message=error.msg, sessions=session)
def login(): if request.method == 'POST': zid = request.form['zid'] password = request.form['password'] if Eventsystem.check_digital(zid): try: user = Eventsystem.validate_login(int(zid), password) login_user(user) return redirect(url_for('index')) except ErrorMessage as error: return render_template('login.html', val=True, message=error.msg) else: try: user = Eventsystem.validate_login_guest(zid, password) login_user(user) return redirect(url_for('index')) except ErrorMessage as error: return render_template('login.html', val=True, message=error.msg) return render_template('login.html')
def test_start_end(self): print('test_start_end') assert Eventsystem.check_data('01-06-2018', '01-09-2018') is True assert Eventsystem.validate_period('01-06-2018', '01-09-2018', 10) is True try: Eventsystem.check_data('01-07-2018', '01-06-2018') except ErrorMessage as error: assert error.msg == 'Please ensure the start date is before the end date' try: Eventsystem.validate_period('01-06-2018', '02-06-2018', 10) except ErrorMessage as error: assert error.msg == 'Early period should between start and end' try: Eventsystem.validate_period('01-06-2018', '02-06-2018', -10) except ErrorMessage as error: assert error.msg == 'Early period should greater or equal zero'
def postSeminar(): if request.method == 'POST': title = request.form['title'] start = request.form['start'] end = request.form['end'] capacity = request.form['capacity'] detail = request.form['detail'] status = 'OPEN' try: Eventsystem.check_start(start) Eventsystem.check_data(start, end) Eventsystem.valida_seminar_capa(capacity) seminar = Eventsystem.make_seminar(title, detail, start, end, capacity, status, current_user.name) Eventsystem.add_seminar(seminar) return redirect(url_for('index')) except ErrorMessage as error: return render_template('postseminar.html', val_post=True, post_info=error.msg) return render_template('postseminar.html')
def cancelesession(sessionId): session = Session.query.filter_by(session_id=int(sessionId)).one() user = Eventsystem.get_user(current_user) seminar = Eventsystem.getSeminar(session) try: Eventsystem.validate_cancele(session.end) user = Eventsystem.check_userin(user, session.users) session.users.remove(user) db.session.commit() except ErrorMessage as error: return render_template('sessioninfo.html', sessions=session, not_in=True, message=error.msg) if Eventsystem.getUser(user, seminar): pass else: seminar.users.remove(user) db.session.commit() return render_template('sessioninfo.html', sessions=session)
def test_successful_login(self): print("test_successful_login") user = Eventsystem.validate_login(6119988, 'pass6890') assert user is not None assert user.role == 'trainee'
def test_used_username(self): print('test_used_username') try: Eventsystem.make_register('*****@*****.**', 'li1998') except ErrorMessage as error: assert error.msg == 'This is username have been used, change another one'
def test_validate_email(self): print('test_validate_email') try: Eventsystem.make_register('11111111', 'li') except ErrorMessage as error: assert error.msg == 'Please enter email type as a username'
def test_validate_username(self): print('test_validate_username') try: Eventsystem.make_register('*****@*****.**', 'li') except ErrorMessage as error: assert error.msg == 'Please enter correct email'
def test_guest_validate_login(self): print('test_guest_validate_login') try: Eventsystem.validate_login_guest('*****@*****.**', 'li199980812') except ErrorMessage as error: assert error.msg == 'Please ensure the username and password'
def test_guest_login(self): print('test_guest_login') user = Eventsystem.validate_login_guest('*****@*****.**', 'li1998') assert user is not None assert user.role == 'guest'
def test_empty_password(self): print('test_empty_password') try: Eventsystem.validate_login(6119988, '') except ErrorMessage as error: assert error.msg == 'Please prvoide a valid password'
def test_empty_username(self): print("test_empty_username") try: Eventsystem.validate_login('', 'pass') except ErrorMessage as error: assert error.msg == 'Please prvoide a valid zid'
def index(): Eventsystem.check_statu() return render_template('index.html', events=Event.query.all(), seminars=Seminar.query.all())
def addsession(SeminarId): seminar = Seminar.query.filter_by(seminar_id=int(SeminarId)).one() if request.method == 'POST': title = request.form['title'] start = request.form['start'] end = request.form['end'] fee = request.form['fee'] capacity = request.form['capacity'] detail = request.form['detail'] speaker = request.form['speaker'] early_period = request.form['early_period'] status = 'OPEN' try: Eventsystem.check_start(start) Eventsystem.check_data(start, end) Eventsystem.validate_capacity(seminar, capacity) Eventsystem.validate_period(start, end, early_period) Eventsystem.chcek_speaker(speaker) session = Session(title, detail, start, end, capacity, status, current_user.name, speaker, fee, early_period) Eventsystem.add_session(session) seminar.sessions.append(session) db.session.commit() return redirect(url_for('index')) except ErrorMessage as error: return render_template('postsession.html', val_post=True, post_info=error.msg) return render_template('postsession.html')
def test_validate_start(self): print('test_validate_start') try: Eventsystem.check_start('01-01-2018') except ErrorMessage as error: assert error.msg == 'Please enter start date before today'
def post(): if request.method == 'POST': title = request.form['title'] start = request.form['start'] end = request.form['end'] fee = request.form['fee'] capacity = request.form['capacity'] detail = request.form['detail'] status = 'OPEN' early_period = request.form['early_period'] try: Eventsystem.check_start(start) Eventsystem.check_data(start, end) Eventsystem.valida_seminar_capa(capacity) Eventsystem.validate_period(start, end, early_period) event = Eventsystem.make_course(title, detail, start, end, capacity, status, current_user.name, fee, early_period) Eventsystem.add_course(event) return redirect(url_for('index')) except ErrorMessage as error: return render_template('post.html', val_post=True, post_info=error.msg) return render_template('post.html')
def cancele(eventId): event = Event.query.filter_by(event_id=int(eventId)).one() Eventsystem.remove_all_user(event) event.status = 'CANCELED' Eventsystem.add_course(event) return redirect(url_for('index'))