Exemple #1
0
def test_login3():
    ems1 = EMS(userCSV='user.csv')
    assert (ems1.login(
        '*****@*****.**',
        'pass30778') == (ems1.getUserByEmail('*****@*****.**'),
                         'Successfully logged in...'))
    registerEMS(None)
Exemple #2
0
def test_guest_registration_success():
    ems1 = EMS()
    user1 = Guest(createUser(None, 'hahaha', 'testName23',
                             '*****@*****.**'))
    ems1.addUser(user1)
    assert (ems1.getUserByEmail('*****@*****.**').name == 'testName23')
    registerEMS(None)
 def test_invalid_early(self):
     system = EMS()
     user = system.get_user("4119993")
     with pytest.raises(Exception) as e_info:
         seminar = system.create_seminar(user, 'Test','Testing',\
              '2018-10-10 22:00:00','UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00',\
              '2018-10-11 22:00:00',1)
Exemple #4
0
def test_dumpAndLoad3():
    ems1 = EMS(userCSV='user.csv')
    user1 = Guest(
        createUser('z5135009', 'hahaha', 'name5135009', '*****@*****.**'))
    ems1.addUser(user1)
    ems1.dumpData(file='test-user.data')
    ems2 = EMS(binFile='test-user.data')
    os.remove('test-user.data')
    assert (
        ems2.getUserByEmail('*****@*****.**').email == '*****@*****.**')
    assert (
        ems2.getUserByEmail('*****@*****.**').email == '*****@*****.**')
    registerEMS(None)
    def test_automatic_close(self):
        system = EMS()
        user = system.get_user('6119988')
        seminar = (1,1,'Test Seminar',4119993,'Testing','2018-05-25 22:00:00','UNSW','2018-05-26 10:00:00','2018-05-26 22:00:00','2018-05-25 21:00:00',1,100,2)
        dbInserter.insert_Seminar(seminar)
        session = (1,'Hi','Tommy','Hi',50,1,1,1)
        dbInserter.insert_Session(session)
        session = (2,'Bye','Tommy','Bye',50,1,1,1)
        dbInserter.insert_Session(session)

        events_left = system.open_events_list("Seminar")

        self.assertTrue(events_left == [])
    def test_successful_create_seminar(self):
        system = EMS()
        user = system.get_user('4119993')

        sem = (1,1,'Test',4119993,'Testing','2018-12-10 22:00:00',\
        'UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00','2018-12-01 22:00:00',1,100,2)
        session1 = (1,'Hi','Hi','Hi',50,1,1,1)
        session2 = (2,'Bye','Bye','Bye',50,1,1,1)

        seminar = system.create_seminar(user, 'Test','Testing',\
        '2018-12-10 22:00:00','UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00',\
        '2018-12-01 22:00:00',1)

        self.assertEqual(system.create_session(seminar, 'Hi','Hi','Hi', 50), 1)
        self.assertEqual(system.create_session(seminar, 'Bye','Bye','Bye',50), 1)
        self.assertTrue(len(seminar.sessions) == 2)
        self.assertEqual(system.add_seminar(seminar), 1)
        self.assertEqual(system.add_sessions(seminar), 1)

        seminar_list = dbHandler.select_all_products("Seminar")
        session_list = dbHandler.select_all_products("Session")
        self.assertTrue(seminar_list != [])
        self.assertTrue(session_list != [])
        self.assertEqual(seminar_list[0], sem)
        self.assertEqual(session_list[0], session1)
        self.assertEqual(session_list[1], session2)
    def test_duplicate_seminar_different_convenor(self):
        system = EMS()
        user = system.get_user('4119998')
        seminar = (1,1,'Test Seminar',4119993,'Testing','2018-12-10 22:00:00',\
        'UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00','2018-12-01 22:00:00',1,100,2)
        dbInserter.insert_Seminar(seminar)
        session = (1,'Hi','Tommy','Hi',50,0,1,1)
        dbInserter.insert_Session(session)
        session = (2,'Bye','Tommy','Bye',50,0,1,1)
        dbInserter.insert_Session(session)

        seminar = system.create_seminar(user, 'Test','tested',\
        '2018-12-10 22:00:00','UNSW Law Library','2019-01-01 22:00:00','2019-01-30 22:00:00',\
        '2018-12-1 22:00:00',1)

        self.assertTrue(seminar, 1)

        self.assertEqual(system.create_session(seminar, 'Hi','Hi','Tommy',50), 1)
        self.assertEqual(system.create_session(seminar, 'Bye','Bye','Tommy',50), 1)
        self.assertTrue(len(seminar.sessions) == 2)
        self.assertEqual(system.add_seminar(seminar), 1)
        self.assertEqual(system.add_sessions(seminar), 1)

        seminar_list = dbHandler.select_all_products("Seminar")
        session_list = dbHandler.select_all_products("Session")
        self.assertTrue(len(seminar_list) == 2)
        self.assertTrue(len(session_list) == 4)
        sem1 = (2,1,'Test',4119998,'tested','2018-12-10 22:00:00','UNSW Law Library',\
        '2019-01-01 22:00:00','2019-01-30 22:00:00','2018-12-01 22:00:00',1,100,2)
        self.assertEqual(seminar_list[1], sem1)
        session3 = (3,'Hi','Tommy','Hi',50,0,2,1)
        session4 = (4,'Bye','Tommy','Bye',50,0,2,1)
        self.assertEqual(session_list[2], session3)
        self.assertEqual(session_list[3], session4)
Exemple #8
0
def test_dumpAndLoad2():
    ems1 = EMS(userCSV='user.csv')
    user1 = Guest(
        createUser('z5135009', 'hahaha', 'name5135009', '*****@*****.**'))
    ems1.addUser(user1)
    ems1.dumpData(file='user.data')
    ems2 = EMS(binFile='user.data')

    assert (ems2.getUserByEmail('*****@*****.**').password == 'hahaha')
    assert (ems2.getUserByEmail('*****@*****.**').password == 'pass24064')
    registerEMS(None)
    def test_duplicate_seminar(self):
        system = EMS()
        user = system.get_user('4119993')
        seminar = (1,1,'Test Seminar',4119993,'Testing','2018-12-10 22:00:00','UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00','2018-12-1 22:00:00',1,100,2)
        dbInserter.insert_Seminar(seminar)
        session = (1,'Hi','Tommy','Hi',50,1,1,1)
        dbInserter.insert_Session(session)
        session = (2,'Bye','Tommy','Bye',50,1,1,1)
        dbInserter.insert_Session(session)

        seminar = system.create_seminar(user, 'Test','tested',\
        '2018-12-10 22:00:00','UNSW Law Library','2019-01-01 22:00:00','2019-01-30 22:00:00',\
        '2018-12-1 22:00:00',1)

        self.assertTrue(seminar, 0)

        seminar_list = dbHandler.select_all_products("Seminar")
        session_list = dbHandler.select_all_products("Session")
        self.assertTrue(len(seminar_list) == 1)
        self.assertTrue(len(session_list) == 2)
Exemple #10
0
def ems():
    ems1 = EMS()
    staff = Staff(createUser('z5135009', 'hahaha', 'name5135009', '*****@*****.**'))
    presenter = Guest(createUser(None, 'samplepass', 'Vicky', '*****@*****.**'))
    ems1.addUser(staff)
    ems1.addUser(presenter)
    return ems1
    def test_active_register_seminar(self):
        system = EMS()
        user = system.get_user('6119988')
        date_format = "%Y-%m-%d %H:%M:%S"
        yesterday = str(datetime.strftime(datetime.now() - timedelta(1), date_format))
        tomorrow = str(datetime.strftime(datetime.now() + timedelta(1), date_format))
        seminar = (1,1,'Test Seminar',4119993,'Testing','2018-12-10 22:00:00','UNSW',yesterday,tomorrow,'2018-12-1 22:00:00',1,100,0)
        dbInserter.insert_Seminar(seminar)
        session = (1,'Hi','Tommy','Hi',50,0,1,1)
        dbInserter.insert_Session(session)
        session = (2,'Bye','Tommy','Bye',50,0,1,1)
        dbInserter.insert_Session(session)

        test_sess = system.get_event('Session', 1)

        with pytest.raises(Exception) as e_info:
            updated = system.update_attendees('register', test_sess, 'Session', user.email)

        seminar_registration = dbHandler.select_all_products("User_Seminar")
        self.assertEqual(seminar_registration, [])
        session_registration = dbHandler.select_all_products("User_Session")
        self.assertEqual(session_registration, [])
Exemple #12
0
def test_guest_registration_email_exist():
    ems1 = EMS()
    user1 = Guest(createUser(None, 'hahaha1', 'hahah', '*****@*****.**'))
    ems1.addUser(user1)
    with pytest.raises(UserDataException) as exc_info:
        user2 = Guest(createUser(None, 'hahaha', 'hahah', '*****@*****.**'))
        ems1.addUser(user2)
    assert (exc_info.type == UserDataException)
    assert (exc_info.value.fieldname == 'email')
    assert (str(exc_info.value) == 'Email already exists')
    registerEMS(None)
    def test_duplicate_session(self):
        system = EMS()
        user = system.get_user('4119993')

        seminar = system.create_seminar(user, 'Test','Testing',\
        '2018-12-10 22:00:00','UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00',\
        '2018-12-1 22:00:00',1)

        self.assertEqual(system.create_session(seminar, 'Hi','Hi','Hi', 50), 1)

        self.assertEqual(system.create_session(seminar, 'Hi','Bye','Hi',50), 0)
        self.assertTrue(len(seminar.sessions) == 1)
    def test_invalid_num_sessions(self):
        system = EMS()
        user = system.get_user('4119993')

        seminar = system.create_seminar(user, 'Test','Testing',\
        '2018-12-10 22:00:00','UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00',\
        '2018-12-1 22:00:00',1)

        self.assertEqual(system.create_session(seminar, 'Hi','Hi','Hi', 50), 1)
        self.assertTrue(len(seminar.sessions) == 1)
        self.assertEqual(system.add_seminar(seminar), 0)

        seminar_list = dbHandler.select_all_products("Seminar")
        session_list = dbHandler.select_all_products("Session")
        self.assertTrue(seminar_list == [])
        self.assertTrue(session_list == [])
    def test_capacity(self):
        system = EMS()
        user = system.get_user('4119993')

        sem = (1,1,'Test',4119993,'Testing','2018-12-10 22:00:00',\
        'UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00','2018-12-1 22:00:00',1,100,0)
        session1 = (1,'Hi','Hi','Hi',50,0,1,1)
        session2 = (2,'Bye','Bye','Bye',50,0,1,1)

        seminar = system.create_seminar(user, 'Test','Testing',\
        '2018-12-10 22:00:00','UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00',\
        '2018-12-1 22:00:00',1)

        with pytest.raises(Exception) as e_info:
            session = system.create_session(seminar, 'Hi','Hi','Hi', 0)
        with pytest.raises(Exception) as e_info:
            session = system.create_session(seminar, 'Bye','Bye','Bye',-1)

        self.assertTrue(len(seminar.sessions) == 0)
    def test_close_registrations(self):
        system = EMS()
        user = system.get_user('4119998')
        seminar = (1,0,'Test Seminar',4119993,'Testing','2018-12-10 22:00:00','UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00','2018-12-1 22:00:00',1,100,0)
        dbInserter.insert_Seminar(seminar)
        session1 = (1,'Hi','Tommy','Hi',50,0,1,0)
        dbInserter.insert_Session(session1)
        session2 = (2,'Bye','Tommy','Bye',50,0,1,0)
        dbInserter.insert_Session(session2)

        test_sess = system.get_event('Session', 1)

        with pytest.raises(Exception) as e_info:
            updated = system.update_attendees('register', test_sess, 'Session', user.email)

        test_sess = system.get_event('Session',1)
        self.assertEqual(test_sess.noAttendees, 0)
        session_list = dbHandler.select_all_products("Session")
        self.assertEqual(session_list[0], session1)
    def test_full_register_seminar(self):
        system = EMS()
        user = system.get_user('6119988')
        seminar = (1,1,'Test Seminar',4119993,'Testing','2018-12-10 22:00:00','UNSW','2019-01-01 22:00:00','2019-01-30 22:00:00','2018-12-1 22:00:00',1,100,100)
        dbInserter.insert_Seminar(seminar)
        session1 = (1,'Hi','Tommy','Hi',50,50,1,1)
        dbInserter.insert_Session(session1)
        session2 = (2,'Bye','Tommy','Bye',50,50,1,1)
        dbInserter.insert_Session(session2)

        test_sess = system.get_event('Session', 1)

        self.assertTrue(system.update_attendees('register', test_sess, 'Session', user.email) == 0)
        test_sess = system.get_event('Session',1)
        self.assertEqual(test_sess.noAttendees, 50)
        session1 = (1,'Hi','Tommy','Hi',50,50,1,1)
        session_list = dbHandler.select_all_products("Session")
        self.assertEqual(session_list[0], session1)

        seminar_registration = dbHandler.select_products("User_Seminar", "Email", "*****@*****.**")
        self.assertTrue(seminar_registration == [])
        session_registration = dbHandler.select_products("User_Session", "Email", "*****@*****.**")
        self.assertTrue(session_registration == [])
Exemple #18
0
import json
from flask_sqlalchemy import SQLAlchemy
from app import *
from model.User import *
from model.EMS import EMS
from model.Session import Session
from model.userManager import login_manager
from model.Venue import Venue
from model.Event import *
from datetime import datetime, timedelta
from util.decorators import requires_fields
from util.helpers import string_to_date, days_before_date

# ran using "python -m pytest test_sem.py"

e = EMS()
u = Staff(name='Admin', id=1234, password=1234, email='*****@*****.**')
u1 = Staff(name='teacher',
           id=12345,
           password=12345,
           email='*****@*****.**')
s = Student(name='Austin',
            id=5116890,
            password=1234,
            email='*****@*****.**')
g1 = Guest(name='g1', email='*****@*****.**', password='')
g2 = Guest(name='g2', email='*****@*****.**', password='')
g3 = Guest(name='g3', email='*****@*****.**', password='')
venue = Venue(name='venue1', location='sydney')

# register for a seminar
Exemple #19
0
def test_login2():
    ems1 = EMS(userCSV='user.csv')
    assert (ems1.login('*****@*****.**',
                       'hahaha') == (None, 'Wrong password!'))
    registerEMS(None)
Exemple #20
0
from flask import Flask
from os.path import isfile
from sys import argv 
from config import config
from model.EMS import EMS
from flask_login import LoginManager


app = Flask(__name__, static_url_path='/static')
app.config.from_object(config)

# init login_manager
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = "login"

@login_manager.user_loader
def load_user(email):
    return ems.getUserByEmail(email)

# instantiate EMS 
ems = None

binFile = argv[1] if len(argv) > 1 else 'emsData.bin'
if len(argv) <= 1 and not isfile(binFile):
    ems = EMS(userCSV='user.csv', debug=type(config).__name__ == 'Development')
else:
    ems = EMS(binFile=binFile, debug=type(config).__name__ == 'Development')

Exemple #21
0
def test_login1():
    ems1 = EMS(userCSV='user.csv')
    assert (ems1.login('*****@*****.**',
                       'hahaha') == (None, 'User does not exist!'))
    registerEMS(None)
Exemple #22
0
from flask_login import LoginManager
from model.EMS import EMS
from model.User import User
from model.Course import Course
import database.create_table as dbCreator
import database.insert_table as dbInserter
import database.delete_table as dbDeleter


def valid_time(time):
    return time > 0


app = Flask(__name__)

system = EMS()
#store tmp seminar before actually create a course
seminar = None

db_name = "EMS.db"
dbCreator.create_user_table(db_name)
dbCreator.create_course_table(db_name)
dbCreator.create_seminar_table(db_name)
dbCreator.create_session_table(db_name)
dbCreator.create_user_course_table(db_name)
dbCreator.create_user_seminar_table(db_name)
dbCreator.create_user_session_table(db_name)

course = (1, 1, 't', 4119988, 't', '2018-12-10 22:00:00', 100, 0, 't',
          '2019-01-01 22:00:00', '2019-01-30 22:00:00', '2018-12-01 22:00:00',
          100)
Exemple #23
0
from flask_login import LoginManager, login_user, logout_user, login_required, current_user
import jinja2
import json
from flask_sqlalchemy import SQLAlchemy
from app import *
from model.User import User
from model.EMS import EMS
from model.Session import Session
from model.userManager import login_manager
from model.Venue import Venue
from model.Event import *
from datetime import datetime
from util.decorators import requires_fields
from util.helpers import string_to_date, days_before_date

ems = EMS()


# return corresponding page of events
def pagination(event_type, page):
    events = ems.get_events_by_type(event_type)
    events = events[page * 8:page * 8 + 8]
    events_list = [events[i:i + 4] for i in range(0, len(events), 4)]
    return events_list


#index redirect
@app.route('/', methods=['GET'])
def root():
    return redirect(url_for('index'))
Exemple #24
0
def test_login4():
    ems1 = EMS(userCSV='user.csv')
    assert (ems1.login('*****@*****.**',
                       'pass27204') == (None, 'Wrong password!'))