LiveServerTestCase
Do basically the same as TransactionTestCase but also launch a live HTTP server in a separate thread so that the tests may use another testing framework, such as Selenium for example, instead of the built-in dummy client. It inherits from TransactionTestCase instead of TestCase because the threads don't share the same transactions (unless if using in-memory sqlite) and each thread needs to commit all their transactions so that the other thread can see the changes.
Attributes
| Attribute | Type | Description |
|---|---|---|
| host | string = "localhost" | The hostname or IP address where the live HTTP server will listen for incoming requests. |
| port | integer = 0 | The port number on which the live server listens, where 0 indicates that a free port should be automatically assigned. |
| server_thread_class | class = "LiveServerThread" | The class used to instantiate the background thread that manages the live HTTP server lifecycle. |
| static_handler | class = "_StaticFilesHandler" | The handler class responsible for serving static files during the execution of live server tests. |
Constructor
Signature
def LiveServerTestCase()
Methods
live_server_url()
@classmethod
def live_server_url() - > string
Provides the full URL of the live HTTP server, including the protocol, host, and dynamically assigned port.
Returns
| Type | Description |
|---|---|
string | The base URL used to access the running test server from external tools like Selenium. |
allowed_host()
@classmethod
def allowed_host() - > string
Retrieves the hostname that the live server is configured to listen on.
Returns
| Type | Description |
|---|---|
string | The hostname or IP address string used for the server configuration and ALLOWED_HOSTS setting. |
setUpClass()
@classmethod
def setUpClass() - > null
Initializes the test class by updating the ALLOWED_HOSTS setting and launching the background server thread.
Returns
| Type | Description |
|---|---|
null |