Beispiel #1
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)
Beispiel #2
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
Beispiel #3
0
    def loadUsers(self, csvPath):
        user = None
        reader = None

        # try to open given csv file
        # fail gracefully and log error
        try:
            reader = DictReader(open(csvPath, "r"))
        except OSError as err:
            print("Cannot Open {} to read: {}".format(csvPath, err),
                  file=sys.stderr)
            exit(1)

        # instantiate corresponding User obj and add it to EMS
        for row in reader:

            row['zid'] = 'z' + row.pop('zID')

            if row['role'] == 'trainee':
                user = Student(UserData.parseViewToModel(row))
            elif row['role'] == 'trainer':
                user = Staff(UserData.parseViewToModel(row))
            elif row['role'] == 'guest':
                row['zid'] = False
                user = Guest(UserData.parseViewToModel(row))
            if user:
                self.addUser(user)
                print("[{}] {} loaded: {}".format(user.uid,
                                                  type(user).__name__, user))
Beispiel #4
0
def test_guest_registration_success():
    ems1 = EMS()
    user1 = Guest(createUser(None, 'hahaha', 'testName23',
                             '*****@*****.**'))
    ems1.addUser(user1)
    assert (ems1.getUserByEmail('*****@*****.**').name == 'testName23')
    registerEMS(None)
Beispiel #5
0
def test_guest_registration_long_name():
    with pytest.raises(UserDataException) as exc_info:
        user1 = Guest(
            createUser(None, 'hahaha', 'LONG_NAME' * 50, '*****@*****.**'))
    assert (exc_info.type == UserDataException)
    assert (exc_info.value.fieldname == 'name')
    assert (str(exc_info.value) == 'Too long name')
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
def signup():
    # serve page on GET request
    if request.method == 'GET':
        return render_template('signup.html')

    # handle registration form
    try:
        userData = UserData.parseViewToModel(request.form)
        newGuest = Guest(userData)
        ems.addUser(newGuest)
    except Exception as err:
        msg = Message(str(err), 'danger')
        return render_template('signup.html',
                               msg=msg,
                               form=json.dumps(request.form))
    return redirect(url_for('login', msg='Successfully signed up'))
Beispiel #9
0
def test_guest_registration_empty_pwd():
    with pytest.raises(UserDataException) as exc_info:
        user1 = Guest(createUser(None, '', 'name23', '*****@*****.**'))
    assert (exc_info.type == UserDataException)
    assert (exc_info.value.fieldname == 'password')
    assert (exc_info.value.fieldname == 'password')
Beispiel #10
0
def test_guest_registration_empty_email():
    with pytest.raises(UserDataException) as exc_info:
        user1 = Guest(createUser(None, 'hahaha', 'hahah', ''))
    assert (exc_info.type == UserDataException)
    assert (exc_info.value.fieldname == 'email')
    assert (str(exc_info.value) == 'Invalid email: ')
Beispiel #11
0
def test_guest_registration_empty_name():
    with pytest.raises(UserDataException) as exc_info:
        user1 = Guest(createUser(None, 'hahaha', '', '*****@*****.**'))
    assert (exc_info.type == UserDataException)
    assert (exc_info.value.fieldname == 'name')
    assert (str(exc_info.value) == 'Empty name')