pulp_2_tests.tests.rpm.api_v2.test_orphan_remove

Location: Pulp 2 TestsTestspulp_2_tests.tests.rpm.api_v2.test_orphan_remove

Test Pulp’s handling of orphaned content units.

This module integrates tightly with Pulp Fixtures. Pulp Smash #134 and Pulp Smash #459 describe specific tests that should be in this module.

class pulp_2_tests.tests.rpm.api_v2.test_orphan_remove.OrphansTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Establish that API calls related to orphans function correctly.

At a high level, this test case does the following:

  1. Create an RPM repository and populate it with content. Delete the repository, thus leaving behind orphans.
  2. Make several orphan-related API calls, and assert that each call has the desired effect.
check_one_orphan_deleted(orphans_pre, orphans_post, orphan)

Ensure that a specific orphan is well and truly deleted.

Parameters:
  • orphans_pre – The response to GET pulp_smash.pulp2.constants.ORPHANS_PATH before the orphan was deleted.
  • orphans_post – The response to GET pulp_smash.pulp2.constants.ORPHANS_PATH after the orphan was deleted.
  • orphan – A dict describing the orphan that was deleted.
Returns:

Nothing.

classmethod setUpClass()

Create orphans.

Create, sync and delete an RPM repository. Doing this creates orphans that the test methods can make use of.

test_00_orphans_available()

Assert that an expected number of orphans is present.

If the expected number of orphans is present, set a class variable indicating such. The following test methods can conditionally run or skip based on this variable. If this method fails, it may indicate that other repositories exist and have references to the same content units.

test_01_get_by_href()

Get an orphan by its href.

test_01_get_by_invalid_type()

Get orphans by content type. Specify a non-existent content type.

test_02_delete_by_href()

Delete an orphan by its href.

test_02_delete_by_type_and_id()

Delete an orphan by its ID and type.

This test exercises Pulp #1923.

test_03_delete_by_content_type()

Delete orphans by their content type.

test_04_delete_all()

Delete all orphans.

test_05_no_orphans_exist()

Assert no orphans exist.

pulp_2_tests.tests.rpm.api_v2.test_orphan_remove.skip_if(func, var_name, result, *, exc=<class 'unittest.case.SkipTest'>)

Optionally skip a test method, based on a condition.

This decorator checks to see if func(getattr(self, var_name)) equals result. If so, an exception of type exc is raised. Otherwise, nothing happens, and the decorated test method continues as normal. Here’s an example of how to use this method:

>>> import unittest
>>> from pulp_smash.selectors import skip_if
>>> class MyTestCase(unittest.TestCase):
...
...     @classmethod
...     def setUpClass(cls):
...         cls.my_var = False
...
...     @skip_if(bool, 'my_var', False, unittest.SkipTest)
...     def test_01_skips(self):
...         pass
...
...     def test_02_runs(self):
...         type(self).my_var = True
...
...     @skip_if(bool, 'my_var', False, unittest.SkipTest)
...     def test_03_runs(self):
...         pass

If the same exception should be passed each time this method is called, consider using functools.partial:

>>> from functools import partial
>>> from unittest import SkipTest
>>> from pulp_smash.selectors import skip_if
>>> unittest_skip_if = partial(skip_if, exc=SkipTest)
Parameters:
  • var_name – A valid variable name.
  • result – A value to compare to func(getattr(self, var_name)).
  • exc – A class to instantiate and raise as an exception. Its constructor must accept one string argument.