Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add docstrings (#16031)
Przemysław Ładac6f9bdb3187e
diff --git a/saleor/tests/utils.py b/saleor/tests/utils.pyindex 6ceac25dcc..9c8be8b85e 100644--- a/saleor/tests/utils.py+++ b/saleor/tests/utils.py@@ -9,18 +9,30 @@ from ..core.db.connection import allow_writerclass FakeDbReplicaConnection:+ """A class used to create a fake replica DB connection for use in tests.++ This class serves as a wrapper around the writer DB connection (alias "default")+ that simulates a replica DB connection by identifying itself with a replica alias+ and overriding cursor creation methods. It effectively results in one DB connection+ identified by two separate aliases, but with shared transactions.+ """+def __init__(self, replica_conn):self.replica_conn = replica_connself.writer_conn = connections[settings.DATABASE_CONNECTION_DEFAULT_NAME]def cursor(self, *args, **kwargs):with allow_writer():+ # Cursor creation is wrapped in allow_writer as it is effectively created+ # using the writer DB connectioncursor = self.writer_conn.cursor(*args, **kwargs)cursor.db = selfreturn cursordef chunked_cursor(self, *args, **kwargs):with allow_writer():+ # Cursor creation is wrapped in allow_writer as it is effectively created+ # using the writer DB connectioncursor = self.writer_conn.chunked_cursor(*args, **kwargs)cursor.db = selfreturn cursor@@ -32,6 +44,13 @@ class FakeDbReplicaConnection:def prepare_test_db_connections():+ """Override the replica DB connection with a fake one for testing purposes.++ This function allows simulation of replica DB usage in tests while using Django's+ TestCase, avoiding the need for the slower TransactionTestCase. For more details,+ refer to the Django documentation:+ https://docs.djangoproject.com/en/4.2/topics/testing/advanced/#testing-primary-replica-configurations+ """replica = settings.DATABASE_CONNECTION_REPLICA_NAMEconnections[replica] = FakeDbReplicaConnection(connections[replica]) # type: ignore