save_lime_objects¶
Scope: function | Returns: callable
The save_lime_objects fixture returns a callable that saves one or more LimeObject instances to the database using a unit of work and returns the committed objects.
Signature¶
save_lime_objects(
*lime_objects: LimeObject,
application: LimeApplication | None = None,
) -> LimeObject | list[LimeObject]
Returns the single committed object when called with one argument, or a list when called with multiple.
Basic usage¶
Declare save_lime_objects alongside one of the application fixtures (lime_app, lime_app_non_admin, or lime_app_other_non_admin). The application is resolved automatically:
def test_person_is_saved(lime_app, save_lime_objects):
person = lime_app.limetypes.person(firstname="Alice")
saved = save_lime_objects(person)
assert saved.id is not None
Saving multiple objects¶
Saving multiple objects at once returns a list:
def test_multiple_objects(lime_app, save_lime_objects):
alice = lime_app.limetypes.person(firstname="Alice")
bob = lime_app.limetypes.person(firstname="Bob")
alice_saved, bob_saved = save_lime_objects(alice, bob)
assert alice_saved.id is not None
assert bob_saved.id is not None
Providing an explicit application¶
Pass application directly when you need to save with a specific application instance:
def test_saved_as_non_admin(lime_app_non_admin, save_lime_objects):
person = lime_app_non_admin.limetypes.person(firstname="Alice")
saved = save_lime_objects(person, application=lime_app_non_admin)
assert saved.id is not None
Application resolution¶
When application is not provided, save_lime_objects looks for the first active fixture among lime_app, lime_app_non_admin, and lime_app_other_non_admin in that order. If none of them is declared in the test, calling the fixture raises a RuntimeError.