fixture

class camelot.model.fixture.Fixture(*args, **kwargs)[source]

Keep track of static data loaded into the database. This class keeps track of data inserted into the database by storing the primary key and the class name of the inserted data, and associating this with a fixture key specified by the developer.

The developer can then use the fixture key to find out if this data has been stored in the database, or to update it in future versions of the application.

Only classes which have an integer field as their primary key can be tracked.

classmethod find_fixture(entity, fixture_key, fixture_class=None)[source]

Find data that has been stored for a fixture key.

Parameters:
  • entity – the class of the stored data
  • fixture_key – a string used to refer to the stored data
  • fixture_class – a string used to refer to a group of stored data
Returns:

a instance of type entity, or None if no fixture is found

classmethod find_fixture_key(entity, primary_key)[source]

Find the fixture key for an object of type entity with primary key

Parameters:
  • entity – the class of the stored data
  • primary_key – the integer primary key of the stored data
Returns:

a string with the fixture_key that refers to this data, None if no such data is found

classmethod find_fixture_key_and_class(obj)[source]

Find out if an object was stored in the database through the fixture mechanism and return its fixture_key and fixture_class

Parameters:obj – the object stored in the database
Returns:(fixture_key, fixture_class) if the object was registered

through the fixture mechanism, (None, None) otherwise

classmethod find_fixture_keys_and_classes(entity)[source]

Load all fixture keys of a certain entity class in batch.

Parameters:entity – the class of the stored data
Returns:a dictionary mapping the primary key of a on object of type entity to a tuple of type (fixture key, fixture class)
classmethod find_fixture_reference(entity, fixture_key, fixture_class=None)[source]

Find the Fixture instance that refers to the data stored for a fixture key.

Parameters:
  • entity – the class of the stored data
  • fixture_key – a string used to refer to the stored data
  • fixture_class – a string used to refer to a group of stored data
Returns:

a Fixture instance refering to the stored data, or None of no data was found.

id

The primary key

classmethod insert_or_update_fixture(entity, fixture_key, values, fixture_class=None)[source]

Store data in the database through the fixture mechanism, to be able to keep track of it later.

Parameters:
  • entity – the class of the stored data
  • fixture_key – a string used to refer to the stored data
  • values – a dictionary with the data that should be insert or updated in the database
  • fixture_class – a string used to refer to a group of stored data
Returns:

an object of type entity, either created or modified

classmethod remove_all_fixtures(entity)[source]

Remove all data of a certain class from the database, if it was stored through the fixture mechanism.

Parameters:entity – the class of the stored data
classmethod remove_fixture(entity, fixture_key, fixture_class)[source]

Remove data from the database, if it was stored through the fixture mechanism.

Parameters:
  • entity – the class of the stored data
  • fixture_key – a string used to refer to the stored data
  • fixture_class – a string used to refer to a group of stored data
class camelot.model.fixture.FixtureVersion(*args, **kwargs)[source]

Keep track of the version the fixtures have in the current database, the subversion revision number is a good candidate to be used as a fixture version.

classmethod get_current_version(fixture_class=None, session=None)[source]

Get the current version of the fixtures in the database for a certain fixture class.

Parameters:
  • fixture_class – the fixture class for which to get the version
  • session – the session to use to query the database, if None is given, the default Camelot session is used
Returns:

an integer representing the current version, 0 if no version found

classmethod set_current_version(fixture_class=None, fixture_version=0, session=None)[source]

Set the current version of the fixtures in the database for a certain fixture class.

Parameters:
  • fixture_class – the fixture class for which to get the version
  • fixture_version – the version number to which to set the fixture version
  • session – the session to use to query the database, if None is given, the default Camelot session is used