openedx.core.djangolib.testing package#
Submodules#
openedx.core.djangolib.testing.utils module#
Utility classes for testing django applications.
CacheIsolationMixinA mixin helping to write tests which are isolated from cached data.
CacheIsolationTestCaseA TestCase baseclass that has per-test isolated caches.
- class openedx.core.djangolib.testing.utils.CacheIsolationMixin#
Bases:
objectThis class can be used to enable specific django caches for the specific TestCase that it’s mixed into.
Usage:
Use the ENABLED_CACHES to list the names of caches that should be enabled in the context of this TestCase. These caches will use a loc_mem_cache with the default settings.
Set the class variable CACHES to explicitly specify the cache settings that should be overridden. This class will insert those values into django.conf.settings, and will reset all named caches before each test.
If both CACHES and ENABLED_CACHES are not None, raises an error.
- CACHES = None#
- ENABLED_CACHES = None#
- classmethod clear_caches()#
Clear all of the caches defined in settings.CACHES.
- classmethod end_cache_isolation()#
End cache isolation by flushing the cache and then returning settings.CACHES to its original state.
- setUp()#
- classmethod setUpClass()#
- classmethod start_cache_isolation()#
Start cache isolation by overriding the settings.CACHES and flushing the cache.
- classmethod tearDownClass()#
- class openedx.core.djangolib.testing.utils.CacheIsolationTestCase(methodName='runTest')#
Bases:
CacheIsolationMixin,TestCaseA TestCase that isolates caches (as described in
CacheIsolationMixin) at class setup, and flushes the cache between every test.
- class openedx.core.djangolib.testing.utils.FilteredQueryCountMixin#
Bases:
objectMixin to add to any subclass of Django’s TestCase that replaces assertNumQueries with one that accepts a ignorelist of tables to filter out of the count.
- assertNumQueries(num, func=None, table_ignorelist=None, *args, **kwargs)#
Used to replace Django’s assertNumQueries with the same capability, with the addition of the following argument:
- table_ignorelist (List): A list of table names to filter out of the
set of queries that get counted.
Important: TestCase must include FilteredQueryCountMixin for this to work.
- openedx.core.djangolib.testing.utils.assert_redact_before_delete(sql_list, table, expected_redacted_value_list, num_redact_delete_pairs=1)#
Assert that PII is redacted before deleted.
Redacting before deleting protects downstream sync of data from holding PII in soft-deleted records. This helper ensures UPDATE and DELETE queries for
tableoccur in consecutive pairs, and that each UPDATE contains the expected redacted values.
- openedx.core.djangolib.testing.utils.get_mock_request(user=None)#
Create a request object for the user, if specified.
- openedx.core.djangolib.testing.utils.skip_unless_cms(func)#
Only run the decorated test in the CMS test suite
- openedx.core.djangolib.testing.utils.skip_unless_lms(func)#
Only run the decorated test in the LMS test suite