Ejemplo n.º 1
0
    def test_gen_link(self):
        with self.client as c:
            with c.session_transaction() as session:
                session['profile'] = {'user_id': self.user_id}

            meeting_len = '50'
            buffer = '10'
            start = '12:00'
            end = '16:00'
            days_out = '1'
            weeks_out = '1'
            half_hours = False
            weekdays = [1, 2, 3]  # Tues, Wed, Thurs
            response = c.post('/generate_link',
                              json={
                                  'meeting_len': meeting_len,
                                  'buffer': buffer,
                                  'workday_start': start,
                                  'workday_end': end,
                                  'days_out': days_out,
                                  'weeks_out': weeks_out,
                                  'weekdays': weekdays,
                                  'half_hours': half_hours
                              })

            target = json.loads(response.data)
            self.assertRegex(target, '[a-zA-Z0-9]{16}')

            db = Dorm()
            links = db.get_user(self.user_id).get_links()
            self.assertEqual(len(links), 1)
            self.assertEqual(links[0].get_target(), target)
Ejemplo n.º 2
0
    def test_delete_link(self):
        with self.client as c:
            with c.session_transaction() as session:
                session['profile'] = {'user_id': self.user_id}

            # add a link
            db = Dorm()
            db.add_scheduling_link(self.user_id)

            links = db.get_user(self.user_id).get_links()
            self.assertEqual(len(links), 1)

            response = c.post('/delete_link',
                              json={'target': links[0].get_target()})
            self.assertEqual(json.loads(response.data), '')

            links = db.get_user(self.user_id).get_links()
            self.assertEqual(len(links), 0)
Ejemplo n.º 3
0
def callback_handling():
    # Handles response from token endpoint
    auth0.authorize_access_token()
    resp = auth0.get('userinfo')
    userinfo = resp.json()

    # Store the user information in flask session (used for checking login)
    session['jwt_payload'] = userinfo
    session['profile'] = {
        'user_id': userinfo['sub'],
        'name': userinfo['name'],
        'picture': userinfo['picture']
    }

    # check if user in db
    db = Dorm()
    user = db.get_user(userinfo['sub'])
    refresh_key = ''
    if not user:
        # get refresh key
        refresh_key = get_refresh_token(userinfo['sub'])
        user = User(userinfo['sub'],
                    userinfo['name'],
                    refresh_key,
                    email=userinfo['email'])
        db.create_user(user)
    else:
        refresh_key = get_refresh_token(userinfo['sub'], True)
        # update refresh key
        if refresh_key:
            db.update_refresh_key(userinfo['sub'], refresh_key)

        # check refresh key validity and force refresh if not valid
        else:
            success = True
            try:
                refresh_key = db.get_user(userinfo['sub']).get_refresh_key()
                success = get_avail(refresh_key)
            except:
                success = False
            if not success:
                session['error'] = 'refresh_key_error'

    return redirect(url_for('home'))
Ejemplo n.º 4
0
    def test_schedule_meeting(self):
        with self.client as c:
            with c.session_transaction() as session:
                session['profile'] = {'user_id': self.user_id}

            # add a link
            db = Dorm()
            db.add_scheduling_link(self.user_id)

            links = db.get_user(self.user_id).get_links()
            target = links[0].get_target()

            response = c.post('/schedule_meeting', json={'target': target})
            self.assertEqual(json.loads(response.data), 'Meeting scheduled!')
Ejemplo n.º 5
0
    def test_fetch_user(self):
        with self.client as c:
            with c.session_transaction() as session:
                session['profile'] = {'user_id': self.user_id}

            # add a link
            db = Dorm()
            db.add_scheduling_link(self.user_id)

            links = db.get_user(self.user_id).get_links()
            target = links[0].get_target()

            response = c.post('/fetch_user', json={'target': target})
            data = json.loads(response.data)
            self.assertEqual(data['name'], self.name)
Ejemplo n.º 6
0
def user_info():
    if 'profile' in session:
        db = Dorm()
        user = db.get_user(session['profile']['user_id'])
        return make_response(json.dumps(user.for_json()))
    return make_response(json.dumps('No user found'))
Ejemplo n.º 7
0
    def test_user_simple(self):
        cursor = self.conn.cursor()
        dorm = Dorm(DB_NAME)

        # verify users table empty
        cursor.execute('SELECT * FROM users')
        self.assertEqual(len(cursor.fetchall()), 0)

        user_id = 'evuong'
        name = 'Erin Vuong'
        refresh_key = 'awoeisld3$#9o'
        optimal_hour = datetime.time(hour=10, minute=30)
        optimal_day = 1
        email = '*****@*****.**'
        default_scaling_factor = 1.2
        user = User(user_id, name, refresh_key, optimal_hour, optimal_day,
                    email)

        # create user
        dorm.create_user(user)
        cursor.execute('SELECT * FROM users')
        users = cursor.fetchall()
        self.assertEqual(len(users), 1)
        user_found = users[0]
        self.assertEqual(len(user_found), 7)
        self.assertEqual(user_found[0], user_id)
        self.assertEqual(user_found[1], name)
        self.assertEqual(user_found[2], refresh_key)
        self.assertEqual(user_found[3], optimal_hour)
        self.assertEqual(user_found[4], optimal_day)
        self.assertEqual(user_found[5], email)
        self.assertEqual(user_found[6], default_scaling_factor)

        # get user
        get_user = dorm.get_user(user_id)
        self.assert_users_equal(get_user, user)

        # update refresh key
        refresh_key = 'sd9w3lsdkfsodi'
        dorm.update_refresh_key(user_id, refresh_key)

        # update optimal hour
        optimal_hour = datetime.time(hour=11, minute=30)
        dorm.update_optimal_hour(user_id, optimal_hour)

        # update optimal day
        optimal_day = 2
        dorm.update_optimal_day(user_id, optimal_day)

        # check info updated
        cursor.execute('SELECT * FROM users')
        users = cursor.fetchall()
        self.assertEqual(len(users), 1)
        user_found = users[0]
        self.assertEqual(len(user_found), 7)
        self.assertEqual(user_found[0], user_id)
        self.assertEqual(user_found[1], name)
        self.assertEqual(user_found[2], refresh_key)
        self.assertEqual(user_found[3], optimal_hour)
        self.assertEqual(user_found[4], optimal_day)
        self.assertEqual(user_found[5], email)
        self.assertEqual(user_found[6], default_scaling_factor)

        # get user
        user = User(user_id, name, refresh_key, optimal_hour, optimal_day,
                    email)
        get_user = dorm.get_user(user_id)
        self.assert_users_equal(get_user, user)

        # delete user
        dorm.delete_user(user_id)

        # verify users table empty
        cursor.execute('SELECT * FROM users')
        self.assertEqual(len(cursor.fetchall()), 0)

        # try getting a nonexistent user
        no_user = dorm.get_user(user_id)
        self.assertEqual(no_user, None)

        # try deleting a nonexistent user
        dorm.delete_user(user_id)