def checkDatabaseUse(self):
"""Enforce `database_use_permitted`."""
if self.database_use_possible and not self.database_use_permitted:
from django.db import connection
self.expectThat(
connection.connection,
testtools.matchers.Is(None),
"Test policy forbids use of the database.",
)
connection.close()
def assertAttributes(self, tested_object, attributes):
"""Check multiple attributes of `tested_object` against a dict.
:param tested_object: Any object whose attributes should be checked.
:param attributes: A dict of attributes to test, and their expected
values. Only these attributes will be checked.
"""
matcher = testtools.matchers.MatchesStructure.byEquality(**attributes)
self.assertThat(tested_object, matcher)