Ejemplo n.º 1
0
def test_all_with_multiple_rows(db_session):
    nipsa_user1 = models.NipsaUser("test_id1")
    db_session.add(nipsa_user1)
    nipsa_user2 = models.NipsaUser("test_id2")
    db_session.add(nipsa_user2)
    nipsa_user3 = models.NipsaUser("test_id3")
    db_session.add(nipsa_user3)

    assert models.NipsaUser.all() == [nipsa_user1, nipsa_user2, nipsa_user3]
Ejemplo n.º 2
0
def add_nipsa(request, userid):
    """NIPSA a user.

    Add the given user's ID to the list of NIPSA'd user IDs.
    If the user is already NIPSA'd then nothing will happen (but an "add_nipsa"
    message for the user will still be published to the queue).

    """
    nipsa_user = models.NipsaUser.get_by_userid(userid)
    if not nipsa_user:
        nipsa_user = models.NipsaUser(userid)
        request.db.add(nipsa_user)

    _publish(request, json.dumps({"action": "add_nipsa", "userid": userid}))
Ejemplo n.º 3
0
def test_init():
    nipsa_user = models.NipsaUser("test_id")
    assert nipsa_user.userid == "test_id"
Ejemplo n.º 4
0
def test_null_id(db_session):
    with pytest.raises(exc.IntegrityError):
        db_session.add(models.NipsaUser(None))
        db_session.flush()
Ejemplo n.º 5
0
def test_two_rows_with_same_id(db_session):
    db_session.add(models.NipsaUser("test_id"))
    with pytest.raises(exc.IntegrityError):
        db_session.add(models.NipsaUser("test_id"))
        db_session.flush()
Ejemplo n.º 6
0
def test_all_with_one_row(db_session):
    nipsa_user = models.NipsaUser("test_id")
    db_session.add(nipsa_user)

    assert models.NipsaUser.all() == [nipsa_user]
Ejemplo n.º 7
0
def test_get_by_userid_with_matching_user(db_session):
    nipsa_user = models.NipsaUser("test_id")
    db_session.add(nipsa_user)

    assert models.NipsaUser.get_by_userid("test_id") == nipsa_user