Fixtures for writing tests for code using oslo.versionedobjects
Note
This module has several extra dependencies not needed at runtime
for production code, and therefore not installed by default. To
ensure those dependencies are present for your tests, add
oslo.versionedobjects[fixtures]
to your list of test dependencies.
oslo_versionedobjects.fixture.
FakeIndirectionAPI
(serializer=None)¶object_action
(context, objinst, objmethod, args, kwargs)¶object_backport
(context, objinst, target_version)¶object_class_action
(context, objname, objmethod, objver, args, kwargs)¶object_class_action_versions
(context, objname, objmethod, object_versions, args, kwargs)¶oslo_versionedobjects.fixture.
ObjectHashMismatch
(expected, actual)¶oslo_versionedobjects.fixture.
ObjectVersionChecker
(obj_classes=defaultdict(<type 'list'>, {}))¶get_dependency_tree
()¶get_hashes
(extra_data_func=None)¶Return a dict of computed object hashes.
Parameters: | extra_data_func – a function that is given the object class which gathers more relevant data about the class that is needed in versioning. Returns a tuple containing the extra data bits. |
---|
test_compatibility_routines
(use_manifest=False, init_args=None, init_kwargs=None)¶Test obj_make_compatible() on all object classes.
Parameters: |
|
---|
test_hashes
(expected_hashes, extra_data_func=None)¶test_relationships
(expected_tree)¶test_relationships_in_order
()¶oslo_versionedobjects.fixture.
StableObjectJsonFixture
¶Fixture that makes sure we get stable JSON object representations.
Since objects contain things like set(), which can’t be converted to JSON, we have some situations where the representation isn’t fully deterministic. This doesn’t matter at all at runtime, but does to unit tests that try to assert things at a low level.
This fixture mocks the obj_to_primitive() call and makes sure to sort the list of changed fields (which came from a set) before returning it to the caller.
setUp
()¶oslo_versionedobjects.fixture.
VersionedObjectRegistryFixture
¶Use a VersionedObjectRegistry as a temp registry pattern fixture.
The pattern solution is to backup the object registry, register a class locally, and then restore the original registry. This could be used for test objects that do not need to be registered permanently but will have calls which lookup registration.
register
(cls_name)¶setUp
()¶oslo_versionedobjects.fixture.
compare_obj
(test, obj, db_obj, subs=None, allow_missing=None, comparators=None)¶Compare a VersionedObject and a dict-like database object.
This automatically converts TZ-aware datetimes and iterates over the fields of the object.
Parameters: |
|
---|
One function of the ObjectVersionChecker is to generate fingerprints of versioned objects. These fingerprints are a combination of the object’s version and a hash of the RPC-critical attributes of the object: fields and remotable methods.
The test_hashes() method is used to retrieve the expected and actual fingerprints of the objects. When using this method to assert the versions of objects in a local project, the expected fingerprints are the fingerprints of the previous state of the objects. These fingerprints are defined locally in the project and passed to test_hashes(). The actual fingerprints are the dynamically-generated fingerprints of the current state of the objects. If the expected and actual fingerprints do not match on an object, this means the RPC contract that was previously defined in the object is no longer the same. Because of this, the object’s version must be updated. When the version is updated and the tests are run again, a new fingerprint for the object is generated. This fingerprint should be written over the previous version of the fingerprint. This shows the newly generated fingerprint is now the most recent state of the object.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.