distro_tracker.test

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.

DISTRO_TRACKER_PATH_SETTINGS = {'DISTRO_TRACKER_CACHE_DIRECTORY': 'cache', 'DISTRO_TRACKER_KEYRING_DIRECTORY': 'keyring', 'DISTRO_TRACKER_LOG_DIRECTORY': 'logs', 'DISTRO_TRACKER_MAILDIR_DIRECTORY': 'maildir', 'DISTRO_TRACKER_TEMPLATE_DIRECTORY': 'templates', 'MEDIA_ROOT': 'media', 'STATIC_ROOT': 'static'}
class distro_tracker.test.TestCaseHelpersMixin[source]

Bases: object

Helpers method injected into distro_tracker’s *TestCase objects.

get_test_data_path(name)[source]

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

add_test_template_dir(name='tests-templates')[source]
get_temporary_directory(prefix=None, suffix=None)[source]
mock_http_request(**kwargs)[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]
import_key_into_keyring(filename)[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.

assertDoesNotExist(obj)[source]
assertDoesExist(obj)[source]
create_source_package(**kwargs)[source]

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.

Returns

the created source package

Return type

SourcePackage

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.

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

  • shorthand (str) – the shorthand of the repository

Returns

the repository entry that has been created

Return type

SourcePackageRepositoryEntry

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

Remove a source package from a repository.

Parameters
  • 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.

Parameters

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': {}}
setup_users(login=False)[source]

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(username=None)[source]

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.

get_user(username=None)[source]
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]