sgmock¶

This Python package is a mock Shotgun server for use in unit testing, and a series of tools for building test fixtures. It emulates the experience of using shotgun_api3 with a Shotgun server near version 4.0. It is fairly incomplete, but is enough for testing the majority of our own tools which tend to focus heavily on consuming data from Shotgun instead of manipulating it.
This mockup does not perfectly emulate the Shotgun experience. In general, it makes the assumption that your usage of the Shotgun API is correct, and that you are testing your manipulation of the data that comes out of it. For example:
- schemas are not enforced (nor do they exist at all);
- there are no default values, and unspecified fields will not be retrievable later;
- entities do not require a
project
.
Also, the mockup starts with absolutely no entities. That includes things that you would normally have by default, e.g. pipeline steps.
If you ask the mockup to do something that it doesn’t understand then we try to fail quickly and fail really hard. Usually with a ShotgunError
or NotImplementedError
.
Good luck, and happy testing!
API Reference¶
sgmock.shotgun
¶
Mock replacement for shotgun_api3
module.
-
class
sgmock.shotgun.
Shotgun
(base_url=None, *args, **kwargs)¶ A mock Shotgun server, replicating the
shotgun_api3
interface.The constructor is a dummy and eats all arguments.
-
batch
(requests)¶ Perform a series of requests in one request.
This mock does not have transactions, so a failed request will leave the data store in a partially mutated state.
Parameters: requests (list) – A series of dicts
representing requests.Returns: list
of results from calling methods individually.
-
create
(entity_type, data, return_fields=None, _log=True, _generate_events=True)¶ Store an entity of the given type and data; return the new entity.
Parameters:
-
delete
(entity_type, entity_id, _generate_events=True)¶ Delete a single entity.
This mock does not have retired entities, so once it is deleted an entity is gone.
Parameters: Return bool: True
if the entity did exist.
-
-
exception
sgmock.shotgun.
ShotgunError
¶ Exception for all server logic.
-
exception
sgmock.shotgun.
Fault
¶ Exception for all remote API logic; unused in this mock.
sgmock.fixture
¶
sgmock.unittest
¶
-
class
sgmock.unittest.
TestCase
(methodName='runTest')¶ Extensions to
unittest.TestCase
which understand entities, and backport many methods from Python2.7.-
assertSameEntity
(a, b, msg=None)¶ Assert that the two given entities refer to the same object.
E.g.: Both are dicts and their types and ids match.
-
assertNotSameEntity
(a, b, msg=None)¶ Assert that the two given entities do not refer to the same object.
E.g.: Both are dicts and their types and ids do not match.
-
assertIs
(expr1, expr2, msg=None)[source]¶ Just like self.assertTrue(a is b), but with a nicer default message.
-
assertIsNot
(expr1, expr2, msg=None)[source]¶ Just like self.assertTrue(a is not b), but with a nicer default message.
-
assertIsNone
(obj, msg=None)[source]¶ Same as self.assertTrue(obj is None), with a nicer default message.
-
assertIn
(member, container, msg=None)[source]¶ Just like self.assertTrue(a in b), but with a nicer default message.
-
assertNotIn
(member, container, msg=None)[source]¶ Just like self.assertTrue(a not in b), but with a nicer default message.
-