Working with databases¶
Defining data structures¶
In order for your tests to be manageable, it’s essential to distinctly be able to define and read what types are expected of your code. To help with this, lime-test makes use of lime-core’s ability to express data structures as dicts or YAML-documents.
The following shows an example of a fixture that sets up an empty database with a coworker and a company that relates to each other:
@pytest.fixture
def my_database(empty_database):
types = """
company:
name: string
rating:
type: option
options:
- poor
- good
- excellent
responsible:
type: belongsto
related: coworker
backref: companies
coworker:
company:
type: hasmany
related: company
backref: responsible
"""
limetypes = lime_type.create_limetypes_from_dsl(types)
lime_test.db.add_limetypes(empty_database, limetypes)
return empty_database
For more detailed information see create_limetypes_from_dsl()
. It’s
also possible to define object instances to use in your tests by using
lime_type.create_limeobjects_from_dsl()
.