def add_users():
    users = [
        User(username='******',
             slack='rando',
             email='*****@*****.**',
             name_first='Matt',
             name_last='Arcidy'),
        User(username='******',
             slack='ruthgrace',
             email='*****@*****.**',
             name_first='Ruth Grace',
             name_last='Wong'),
        User(username='******',
             slack='jams',
             email='*****@*****.**',
             name_first='Jeremey',
             name_last='Lleywen'),
        User(username='******',
             slack='sigint',
             email='*****@*****.**',
             name_first='Nick',
             name_last='Whatever')
    ]

    [db.session.add(user) for user in users]
    db.session.commit()
Example #2
0
def test_bad_formed_user():

    with pytest.raises(ValidateError):
        u = User(username=123, email="*****@*****.**")

    with pytest.raises(ValidateError):
        u = User(username=None, email="*****@*****.**")

    with pytest.raises(ValidateError):
        u = User(username="******", email=None)
Example #3
0
def model_objects():
    objects = {
        'u1': User(id=1, username="******", email="*****@*****.**"),
        'u2': User(id=2, username="******", email="*****@*****.**"),
        'u3': User(id=3, username="******", email="*****@*****.**"),
        'u4': User(id=4, username="******", email="*****@*****.**"),
        'usd': Currency(id=1, code="USD", name="US Dollar"),
        'btc': Currency(id=2, code="BTC", name="Bitcoin"),
        'acct1': Account(id=1, ccy_id=1, name="USD Credits"),
        'acct2': Account(id=2, ccy_id=1, name="USD Debits"),
        'acct3': Account(id=3, ccy_id=2, name="BTC Wallet"),
    }

    return objects
Example #4
0
def test_new_user():
    uname = "rando"
    em = "*****@*****.**"

    user = User(username=uname, email=em)

    assert user.username == uname
    assert user.email == em
Example #5
0
def test_insert_user():

    uname = 'rando'
    em = '*****@*****.**'

    user = User(username=uname, email=em)

    db.session.add(user)
    db.session.commit()

    retrieved_user = db.session.query(User).one()

    assert user.username == retrieved_user.username
    assert user.email == retrieved_user.email
Example #6
0
def facebook_connect(request):
    """
    Create or connect a user via facebook connect.
    """
    try:
        access_token = request.POST["access_token"]
        user_id = request.POST["id"]
        request_sig = request.POST["sig"]

        sig, expected_sig = get_sig_and_expected_sig(request_sig, settings.FACEBOOK_APP_SECRET)

        print sig, expected_sig
        if sig == expected_sig:
            try:
                f_user = FacebookUser.objects.get(facebook_id=user_id)
                print f_user
            except FacebookUser.DoesNotExist:
                print "Add to DB"
                # Facebook api to get the user profile
                profile = facebook.GraphAPI(access_token).get_object("me")

                first_name = profile["first_name"]
                last_name = profile["last_name"]

                # Create the user
                user = User()

                user.FB_ID = user_id
                user.name = first_name + " " + last_name
                user.points = 0

                # Attempt to set the email
                try:
                    if "email" in settings.FACEBOOK_SCOPE:
                        email = profile["email"]
                        user.email = email
                except AttributeError:
                    pass

                # Create the facebook user
                f_user = FacebookUser(facebook_id=user_id, contrib_user=user)

                # Set a password
                temp = hashlib.new("sha1")
                temp.update(str(datetime.datetime.now()))
                password = temp.hexdigest()

                # user.set_password(password)
                f_user.contrib_password = password

                # Save
                print "Saving..."
                # f_user.save()
                user.save()

            # Authenticate and login
            # authenticated_user = auth.authenticate(username=f_user.contrib_user.name,
            #                                       password=f_user.contrib_password)
            # auth.login(request, authenticated_user)

        else:

            content = {"is_error": True, "error_text": "Error connecting facebook connect user %s " % (user_id)}

            return json_response(content, 200)

    except Exception, e:
        print e
        content = {"is_error": True, "error_text": "Error in ajax call, exception: %s" % e}

        return json_response(content, 200)