def oauth_authorized(resp): if resp is None or resp['member_id'] is None: flash(u'You denied the request to sign in.', 'alert-error') return redirect(url_for('index')) meetup_id = resp['member_id'] oauth_token = resp['oauth_token'] oauth_secret = resp['oauth_token_secret'] user = controller.fetch_user(meetup_id, (oauth_token, oauth_secret)) session['user_id'] = user.id return redirect(url_for('snipes'))
def test_fetch_user(self): """ 1. calling controller.fetch_user without providing a token or secret does not modify the user's existing token or secret """ user = User(meetup_id='1234', token='old_token', secret='old_secret') db.session.add(user) db.session.commit() fetched_user = controller.fetch_user(meetup_id='1234') assert user.id == fetched_user.id assert user.token, user.secret == ('old_token', 'old_secret')
def test_fetch_new_user(self): """ 3. calling controller.fetch_user for a user with a meetup_id that is not in the database returns a newly created user """ meetup_id = '1243483483' assert not User.query.filter(User.meetup_id == meetup_id).first() user = controller.fetch_user( meetup_id=meetup_id, token_secret=('new_token', 'new_secret')) assert user assert User.query.filter(User.meetup_id == meetup_id).first()
def test_fetch_user_update_token_secret(self): """ 2. calling controller.fetch_user and providing an updated token and secret updates them in the database """ user = User(meetup_id='1234', token='old_token', secret='old_secret') db.session.add(user) db.session.commit() fetched_user = controller.fetch_user( meetup_id='1234', token_secret=('new_token', 'new_secret')) assert user.id == fetched_user.id assert user.token, user.secret == ('new_token', 'new_secret')