Distro Tracker test infrastructure.

class distro_tracker.test.TempDirsMixin[source]

Bases: object

Diverts all distro-tracker path settings to make them point to temporary directories while testing.

class distro_tracker.test.TestCaseHelpersMixin[source]

Bases: object

Helpers method injected into distro_tracker’s *TestCase objects.


Returns an absolute path name of file within the tests-data subdirectory in the calling TestCase.

get_temporary_directory(prefix=None, suffix=None)[source]
static compress(data, compression='gzip')[source]
set_http_response(url=None, method='GET', body=None, headers=None, status_code=200, json_data=None, compress_with=None)[source]

Imports a key from an ascii armored file located in tests-data/keys/ into Distro Tracker’s keyrings/.

class distro_tracker.test.DatabaseMixin[source]

Bases: object

Database-related assertions injected into distro_tracker’s *TestCase objects.


Creates a source package and any related object requested through the keyword arguments. The following arguments are supported: - name - version - directory - dsc_file_name - maintainer (dict with ‘name’ and ‘email’) - uploaders (list of emails) - architectures (list of architectures) - binary_packages (list of package names) - repository (shorthand of a repository) - repositories (list of repositories’ shorthand) - data (dict used to generate associated PackageData)

If the shorthand of the requested repository is ‘default’, then its default field will be set to True.


the created source package

Return type


add_to_repository(srcpkg, shorthand='default')[source]

Add a source package to a repository. Creates the repository if it doesn’t exist.

If the shorthand of the requested repository is ‘default’, then its default field will be set to True.

  • srcpkg (SourcePackage) – the source package to add to the repository

  • shorthand (str) – the shorthand of the repository


the repository entry that has been created

Return type


remove_from_repository(srcpkg, shorthand='default')[source]

Remove a source package from a repository.

  • srcpkg (SourcePackage) – the source package to add to the repository

  • shorthand (str) – the shorthand of the repository

add_package_data(pkgname, **kwargs)[source]

Creates PackageData objects associated to the package indicated in pkgname. Each named parameter results in PackageData instance with the key being the name of the parameter and the value being the value of the named parameter.


pkgname (str or PackageName) – the name of the package to which we want to associate data

static create_repository(codename='sid', name=None, shorthand=None, uri='http://localhost/debian', suite=None, components='main contrib non-free', default=False, optional=True, binary=False, source=True, architectures=None)[source]
class distro_tracker.test.SimpleTestCase(methodName='runTest')[source]

Bases: distro_tracker.test.TempDirsMixin, distro_tracker.test.TestCaseHelpersMixin, django.test.testcases.SimpleTestCase

class distro_tracker.test.TestCase(methodName='runTest')[source]

Bases: distro_tracker.test.TempDirsMixin, distro_tracker.test.TestCaseHelpersMixin, distro_tracker.test.DatabaseMixin, django.test.testcases.TestCase

class distro_tracker.test.TransactionTestCase(methodName='runTest')[source]

Bases: distro_tracker.test.TempDirsMixin, distro_tracker.test.TestCaseHelpersMixin, distro_tracker.test.DatabaseMixin, django.test.testcases.TransactionTestCase

tags = {'transaction'}
class distro_tracker.test.LiveServerTestCase(methodName='runTest')[source]

Bases: distro_tracker.test.TempDirsMixin, distro_tracker.test.TestCaseHelpersMixin, distro_tracker.test.DatabaseMixin, django.contrib.staticfiles.testing.StaticLiveServerTestCase

class distro_tracker.test.TemplateTestsMixin[source]

Bases: object

Helper methods to tests templates

assertLinkIsInResponse(response, link)[source]
assertLinkIsNotInResponse(response, link)[source]
class distro_tracker.test.UserAuthMixin[source]

Bases: object

Helpers methods to manage user authentication. One may define additional USERS before call self.setup_users() in self.setUp()

USERS = {'john': {}}

Creates users defined in self.USERS and use the ‘login’ parameter as follows: * If False: no user login * If True: login with the only user defined * If a particular username: login with the user who owns the username


Login with the user that owns the ‘username’ or with the only available user in self.users. If multiple users are available, you must specify the username or you will trigger a ValueError exception.

class distro_tracker.test.AptRepositoryMixin[source]

Bases: object

Helper method to mock an APT repository.

mock_apt_repository(repo, **kwargs)[source]
mock_apt_repository_add_metadata_file(repo, filename, content=None, test_content_file=None, compression='auto', **kwargs)[source]
mock_apt_repository_update_release_file(repo, enable_inrelease=True, acquire_by_hash=True, suite=None, codename=None, architectures=None, components=None, **kwargs)[source]