API: testing¶
- class pubtools.pulplib.FakeController[source]¶
A controller for fake instances of
Client, to be used within automated tests.This class provide clients which have the same public interface as
Client. These clients can do most of the same actions as a real client, but use a simple in-memory implementation rather than issuing requests to a remote Pulp server. Client data may be inspected and modified via the FakeController instance.Example
# imagine we have a function like this def delete_old_repos(client, days): # code here using client to find/delete all repos older # than given number of days ... # then we can use a fake client to test it like this def test_delete_old_repos(): controller = FakeController() # Insert repositories into fake data repo_now = YumRepository(id='current-repo', created=datetime.utcnow()) repo_old = FileRepository(id='old-repo', created=datetime.min) controller.insert_repository(repo_now) controller.insert_repository(repo_old) # Run the code under test against the fake client # It should succeed without crashing delete_old_repos(controller.client, 5) # The set of repos should now contain only the recent repo assert controller.repositories == [repo_now]
Limitations:
- new_client()[source]¶
Returns a new fake Client attached to this controller.
All clients created from the same controller will share the same underlying state; changes made via one client will be visible to all other clients attached to this controller.
New in version 2.32.0.
- property client¶
A shared client instance attached to this controller.
This property may be used if only a single client is required. Otherwise,
new_client()can be used to obtain multiple clients.
- property repositories¶
The list of existing repositories in the fake client.
- insert_repository(repository)[source]¶
Add a repository to the set of existing repositories in the fake client.
- Parameters:
repository (
Repository) – A repository object to insert.
- insert_units(repository, units)[source]¶
Add units to the set of existing content for a repository.
- Parameters:
repository (
Repository) – A repository object, orNoneto insert units as orphans.units (list[
Unit]) – A list of units to be inserted.
New in version 1.5.0.
New in version 2.21.0: Added ability to insert orphan units.
- property content_type_ids¶
The list of content type IDs the fake client will claim to support.
New in version 1.4.0.
- set_content_type_ids(type_ids)[source]¶
Set the list of content type IDs the fake client will claim to support.
New in version 1.4.0.
- property publish_history¶
A list of repository publishes triggered via clients associated with this controller.
Each element of this list is a named tuple with the following attributes, in order:
repository:Repositoryfor which publish was triggeredtasks:list of
Taskgenerated as a result of this publish
- property sync_history¶
A list of repository syncs triggered via clients associated with this controller.
Each element of this list is a named tuple with the following attributes, in order:
repository:Repositoryfor which sync was triggeredtasks:list of
Taskgenerated as a result of this syncsync_config:SyncConfig(of the appropriate subclass) used for this sync
New in version 2.5.0.
- property tasks¶
The list of existing tasks in the fake.
- insert_task(task)[source]¶
Add a task to the set of existing tasks in the fake.
- Parameters:
task (
Task) – A task object to insert.
- property repo_lock_history¶
A list containing all lock actions carried out. Possible actions are: lock, unlock, multi-unlock