Ejemplo n.º 1
0
    def test_create(self):
        uid1 = User.create("jack", "password")
        assert uid1 is not None
        with pytest.raises(sqlalchemy.exc.IntegrityError):
            User.create("jack", "password")

        uid2 = User.create("tom", "password2")
        assert uid2 is not None
Ejemplo n.º 2
0
    def test_retrieval(self):
        uid1 = User.create("jack", "password")
        user = User.get(uid1)
        user2 = User.get_by_name("jack")
        assert user.id == user2.id

        assert None is User.get(999)
        assert None is User.get_by_name("not-existed")
Ejemplo n.º 3
0
def register():
    username = request.values.get("username")
    password = request.values.get("password")

    try:
        user_id = User.create(username, password)
    except sqlalchemy.exc.IntegrityError:
        return jsonify({
            "error": 1001,
            "error_msg": "duplicated",
        })
    except BaseException:
        return jsonify({
            "error": 1000,
            "error_msg": "unknown",
        })

    return jsonify({"error": 0, "user_id": user_id})
Ejemplo n.º 4
0
 def test_contacts(self):
     jack_id = User.create("jack", "password")
     rose_id = User.create("rose", "password")
     ContactRelation.connect(jack_id, rose_id)
     jack = User.get(jack_id)
     jack.get_contacts()
Ejemplo n.º 5
0
 def test_login_challenge(self):
     uid = User.create("jack", "password")
     assert uid is not None
     assert uid == User.login_challenge("jack", "password")
     assert None is User.login_challenge("jack2", "password")
     assert None is User.login_challenge("jack2", "password2")