Пример #1
0
def test_can_delete(db, monkeypatch):
    db.create_all()

    user = User(email="*****@*****.**")
    user.save()

    def fake_request():
        return {"user": user}

    monkeypatch.setattr("starlette_audit.tables.get_request", fake_request)

    obj = MyModel(name="foo")
    obj.save()

    id = obj.id

    obj.delete()

    logs = AuditLog.query.filter(AuditLog.entity_type == "mymodel",
                                 AuditLog.entity_type_id == id).all()

    # all logs should remain intact after deleting

    assert len(logs) == 2

    assert logs[0].data == {"id": id, "name": "foo"}
    assert logs[0].extra_data == {}
    assert logs[0].operation == "INSERT"
    assert logs[0].created_by_id == user.id

    assert logs[1].data == {"id": id, "name": "foo"}
    assert logs[1].extra_data == {}
    assert logs[1].operation == "DELETE"
    assert logs[1].created_by_id == user.id
Пример #2
0
def test_can_update(db, monkeypatch):
    db.create_all()

    user = User(email="*****@*****.**")
    user.save()

    def fake_request():
        return {"user": user}

    monkeypatch.setattr("starlette_audit.tables.get_request", fake_request)

    obj = MyModel(name="foo")
    obj.save()

    obj.name = "bar"
    obj.save()

    id = obj.id

    logs = AuditLog.query.filter(AuditLog.entity_type == "mymodel",
                                 AuditLog.entity_type_id == id).all()

    assert len(logs) == 2
    assert logs[1].data == {"id": id, "name": "bar"}
    assert logs[1].extra_data == {}
    assert logs[1].operation == "UPDATE"
    assert logs[1].created_by_id == user.id
Пример #3
0
def user():
    data = {"email": "*****@*****.**", "first_name": "Test", "last_name": "User"}

    try:
        return User.query.filter(User.email == data["email"]).one()
    except:
        usr = User(**data)
        usr.set_password("password")
        usr.save()
        return usr
Пример #4
0
def user():
    from starlette_auth.tables import User  # noqa isort:skip

    data = {
        "email": "*****@*****.**",
        "first_name": "Test",
        "last_name": "User"
    }

    try:
        return User.query.filter(email == data["email"]).one()
    except:
        usr = User(**data)
        usr.set_password("password")
        usr.save()
        return usr
Пример #5
0
def user():
    test_user = User(email="*****@*****.**")
    test_user.set_password("password")
    test_user.save()

    return test_user