Manage Fixture objects.
Parameters: | db_session (Session) – sqlalchemy Session object |
---|
New in version 0.3.0: db_session argument was added.
Clean the cache.
Delete a fixture instance.
If it’s a SQLAlchemy model, it will be deleted from the session and the session will be committed.
Otherwise, delete_instance() will be run first. If the instance does not have it, delete() will be run. If the instance does not have it, nothing will happen.
Before and after the process, the before_delete() and after_delete() hook are run.
Return a fixture instance (but do not save it).
Parameters: |
|
---|---|
Return type: | instantiated but unsaved fixture |
Return a list of fixtures instances.
Parameters: |
|
---|---|
Return type: | list of instantiated but unsaved fixtures |
Install all fixtures.
Parameters: |
|
---|---|
Return type: | list of fixture_instance |
Install a fixture.
Parameters: |
|
---|---|
Return type: | fixture_instance |
Install a list of fixtures.
Parameters: |
|
---|---|
Return type: | list of fixture_instance |
Pre-load the fixtures.
Parameters: |
|
---|
Note that this does not effectively instantiate anything. It just does some pre-instantiation work, like prepending the root model package and doing some basic sanity check.
Changed in version 0.3.0: db_session argument was removed and put in the object’s constructor arguments.
Save a fixture instance.
If it’s a SQLAlchemy model, it will be added to the session and the session will be committed.
Otherwise, a save() method will be run if the instance has one. If it does not have one, nothing will happen.
Before and after the process, the before_save() and after_save() hook are run.
Add a hook.
Parameters: |
|
---|
Uninstall all installed fixtures.
Parameters: | do_not_delete (bool) – True if fixture should not be deleted. |
---|---|
Return type: | list of fixture_instance |
Uninstall a fixture.
Parameters: |
|
---|---|
Return type: | fixture_instance or None if no instance was uninstalled |
with the given key
Uninstall a list of installed fixtures.
If a given fixture was not previously installed, nothing happens and its instance is not part of the returned list.
Parameters: |
|
---|---|
Return type: | list of fixture_instance |
Class from which test cases should inherit to use fixtures.
Changed in version 0.3.0: use_fixtures_manager method renamed init_fixtures.
Changed in version 0.3.0: Extensive change to the function signatures.
Return a fixture instance (but do not save it).
Parameters: |
|
---|---|
Return type: | instantiated but unsaved fixture |
Return a list of fixtures instances.
Parameters: |
|
---|---|
Return type: | list of instantiated but unsaved fixtures |
Initialize the fixtures.
This function must be called before doing anything else.
Install all fixtures.
Parameters: |
|
---|---|
Return type: | list of fixture_instance |
Install a fixture.
Parameters: |
|
---|---|
Return type: | fixture_instance |
Install a list of fixtures.
Parameters: |
|
---|---|
Return type: | list of fixture_instance |
Uninstall all installed fixtures.
Parameters: | do_not_delete (bool) – True if fixture should not be deleted. |
---|---|
Return type: | list of fixture_instance |
Uninstall a fixture.
Parameters: |
|
---|---|
Return type: | fixture_instance or None if no instance was uninstalled |
with the given key
Uninstall a list of installed fixtures.
If a given fixture was not previously installed, nothing happens and its instance is not part of the returned list.
Parameters: |
|
---|---|
Return type: | list of fixture_instance |
Represent a fixture that can be installed.
Helper function to extract the relationship and attr from an argument to !rel
Iterator of all relationships and dependencies for this fixture
Return class object for this instance.
Instantiate the fixture using the model and return the instance.
Parameters: | include_relationships (boolean) – false if relationships should be removed. |
---|
Get a relationship and its attribute if necessary.
Update the object in place using its chain of inheritance.
Apply datetime delta in string format to a datetime object.
Parameters: |
|
---|---|
Return type: | datetime.DateTime instance |
>>> base = datetime.datetime(2012, 1, 1, 1, 1, 1)
>>> apply_delta(base, "+1h")
datetime.datetime(2012, 1, 1, 2, 1, 1)
>>> apply_delta(base, "+10h")
datetime.datetime(2012, 1, 1, 11, 1, 1)
>>> apply_delta(base, "-10d")
datetime.datetime(2011, 12, 22, 1, 1, 1)
>>> apply_delta(base, "+1m")
datetime.datetime(2012, 1, 31, 1, 1, 1)
>>> apply_delta(base, "-1y")
datetime.datetime(2011, 1, 1, 1, 1, 1)
>>> apply_delta(base, "+10d2h")
datetime.datetime(2012, 1, 11, 3, 1, 1)
>>> apply_delta(base, "-10d2h")
datetime.datetime(2011, 12, 21, 23, 1, 1)
>>> apply_delta(base, "-21y2m1d24h")
datetime.datetime(1990, 11, 5, 1, 1, 1)
>>> apply_delta(base, "+5M")
datetime.datetime(2012, 1, 1, 1, 6, 1)
>>> apply_delta(base, "+4M30s")
datetime.datetime(2012, 1, 1, 1, 5, 31)
Copy docstring from another class, using the same function name.
Return the epoch timestamp for the given datetime
Parameters: | a_datetime (datetime) – The datetime to translate |
---|---|
Return type: | float |
>>> a_datetime = datetime.datetime(2013, 11, 21, 1, 33, 11, 160611)
>>> datetime_to_epoch_timestamp(a_datetime)
1384997591.160611
Return a timedelta object based on the arguments.
Parameters: |
|
---|---|
Return type: | timedelta instance |
Since timedelta‘s largest unit are days, timedelta objects cannot be created with a number of months or years as an argument. This function lets you create timedelta objects based on a number of days, months and years.
>>> extended_timedelta(months=1)
datetime.timedelta(30)
>>> extended_timedelta(years=1)
datetime.timedelta(365)
>>> extended_timedelta(days=1, months=1, years=1)
datetime.timedelta(396)
>>> extended_timedelta(hours=1)
datetime.timedelta(0, 3600)