Esempio n. 1
0
    def setUp(self):
        base.Base.setUp(self)
        db.create_all()
        u0 = user.User(username='******')
        u1 = user.User(username='******')
        oa0 = user.TwitterOAuth(
            user=u0,
            screen_name='twitter0',
            token='token',
            token_secret='token_secret',
            friends=[
                user.Friend('twitter1', 't1', ''),
                user.Friend('twitter2', 't2', '')
            ],
        )
        oa1 = user.TwitterOAuth(
            user=u1,
            screen_name='twitter1',
            token='token',
            token_secret='token_secret',
            friends=[user.Friend('twitter2', 't2', '')],
        )
        db.session.add_all([u0, u1, oa0, oa1])
        db.session.commit()
        self.u0 = u0
        self.u1 = u1

        # Register a printer for user so we can test friends printers
        u0.claim_printer('vcty-8s95-40hq-6k1z', 'u0 printer')
        hardware.Printer.phone_home('dd5ebbcce362f584')

        u1.claim_printer('pmo0-bjf1-ste8-51c1', 'u1 printer')
        hardware.Printer.phone_home('35fef3793dce4692')
Esempio n. 2
0
def process_authorization(token, token_secret, screen_name, next_url):
    """Process the incoming twitter oauth data. Validation has already
    succeeded at this point and we're just doing the book-keeping."""

    flask.session['twitter_token'] = (token, token_secret)
    flask.session['twitter_screen_name'] = screen_name

    oauth = user_model.TwitterOAuth.query.filter_by(
        screen_name=screen_name, ).first()

    # Create local user model for keying resources (e.g. claim codes)
    # if we haven't seen this twitter user before.
    if oauth is None:
        new_user = user_model.User(username=screen_name, )

        oauth = user_model.TwitterOAuth(
            user=new_user,
            screen_name=screen_name,
            token=token,
            token_secret=token_secret,
            last_friend_refresh=datetime.datetime.utcnow(),
        )

        # Fetch friends list from twitter. TODO: error handling.
        friends = get_friends(new_user)
        oauth.friends = friends

        db.session.add(new_user)
        db.session.add(oauth)
        db.session.commit()

    login.login_user(oauth.user)

    return flask.redirect(next_url)
Esempio n. 3
0
 def setUp(self):
     testing.TestCase.setUp(self)
     db.create_all()
     self.testuser = user.User(username="******",
                               twitter_oauth=user.TwitterOAuth(
                                   screen_name='testuser',
                                   friends=[],
                                   token="token",
                                   token_secret="token_secret",
                               ))
     db.session.add(self.testuser)
     db.session.commit()
Esempio n. 4
0
def user(screen_name):
    new_user = user_model.User(
        username=screen_name,
    )
    oauth = user_model.TwitterOAuth(
        user=new_user,
        screen_name=screen_name,
        token='token',
        token_secret='secret',
    )
    db.session.add(new_user)
    db.session.add(oauth)
    db.session.commit()
Esempio n. 5
0
 def setUp(self):
     base.Base.setUp(self)
     self.testuser2 = user.User(username="******")
     db.session.add(self.testuser2)
     db.session.commit()