tests.api package#
Submodules#
tests.api.test_endpoints module#
Module for tests for application api endpoints.
- Classes:
SetUpChatEndpointTestCase WebSocketTestCase
- class tests.api.test_endpoints.ApplicationBackendStartupAndShutdownFunctionsTest(methodName='runTest')[source]#
Bases:
IsolatedAsyncioTestCase
Test case class for testing functions called during start up and shut down of backend.
- classmethod setUpClass()[source]#
Hook method for setting up class fixture before running tests in the class.
- test_at_successful_end_of_apache_startup_there_are_state_attributes_set_for_kafka_zookeeper_and_server_processes(*_) None [source]#
Test that after successful startup of apache kafka, there are state attributes set for kafka zookeeper and server processes :return: None
- async test_close_apache_kafka_producer_calls_close_on_the_server_AIOKafkaProducer_object() None [source]#
Test that function to close server Apache Kafka Producer (in this case AIOKafkaProducer) closes the server producer AIOKafkaProducer object.
- Returns:
None
- async test_close_apache_kafka_producer_triggers_warning_when_supplied_fastapi_application_instance_has_no_kafka_producer_state_attribute()[source]#
Test that functon to close server Apache Kafka Producer triggers a warning in the case that there is no kafka producer state attribute on the passed fastapi application argument. :return: None
- test_shutdown_apache_kafka_raises_exception_if_existing_kafka_zookeeper_and_server_for_app_instance_is_non_existent() None [source]#
Test that the function to shut down Apache Kafka raises an exception if kafka zookeeper and or server don’t exist for the app instance upon which the shutdown was called with.
- Returns:
None
- test_shutdown_apache_kafka_raises_warning_on_erroneous_official_kafka_shutdown_executable_call(mocked_subprocess_popen) None [source]#
Test that function to shut down Apache Kafka raises warning if there was an error while executing subprocess to run official kafka shutdown executables. :return: None
- test_shutdown_apache_kafka_uses_subprocess_stop_if_there_is_an_error_with_using_the_official_kafka_stop_executables(mocked_subprocess_popen: Mock, *_) None [source]#
Test that the function to shut down Apache Kafka uses subprocess termination if there was an error with the official Kafka stop executables.
- test_start_apache_kafka_function_raises_exception_when_zookeeper_does_not_start_within_set_timeout(mocked_eventlet_timeout: Mock) None [source]#
Test that the function to start apache kafka raises exception when apache kafka zookeeper server doesn’t start after the set timeout period (and thus there is no attempt to start up the apache kafka server.
- Returns:
None
- async test_start_apache_kafka_producer_does_not_recreate_another_producer_on_the_same_instance_of_fastapi() None [source]#
Test that function to start apache kafka producer does not create more than one for a single fastapi app instance.
- Returns:
None
- test_start_apache_kafka_producer_sets_fastapi_app_kafka_producer_attribute() None [source]#
Test that function to start apache kafka producer sets the fastapi state kafka_producer attribute.
- Returns:
None
- async test_start_apache_kafka_producer_starts_AIOKafkaProducer_with_expected_argument_for_boostrap_servers() None [source]#
Test that function to start apache kafka producer starts AIOKafkaProducer with expected values. :return: None
- test_start_apache_kafka_producer_starts_the_kafka_producer() None [source]#
Test that function to start apache kafka producer calls .start() on the AIOKafkaProducer object. :return: None
- test_start_apache_kafka_producer_takes_a_fastapi_object_argument(mocked_start_apache_kafka_producer: Mock) None [source]#
Test that function to start apache kafka producer takes FastAPI app instance argument.
- Parameters:
mocked_start_apache_kafka_producer – Mocked start_apache_kafka_producer() object.
- Returns:
None
- test_startup_apache_kafka_function_only_continues_to_start_kafka_server_after_zookeeper_subprocess_prints_expected_start_text() None [source]#
Test that the function to start apache kafka goes on to start the apache kafka server only after the zookeeper subprocess output has printed out the expected text for a successful zookeeper server start.
- Returns:
None
- test_startup_apache_kafka_function_prints_contents_of_apache_kafka_server_start_after_starting_kafka_zookeeper(mocked_eventlet_timeout: Mock) None [source]#
Test that function to start apache kafka prints contents of the apache kafka server process to terminal after successful start of apache kafka zookeeper. :return: None
- test_startup_apache_kafka_function_prints_contents_of_startup_output_to_terminal_during_execution() None [source]#
Test that the function to start apache kafka prints the contents of the subprocess call to the terminal running the initiating [parent] program. :return: None
- test_startup_apache_kafka_function_raises_exception_on_apache_kafka_server_start_timeout(mocked_eventlet_timeout: Mock) None [source]#
Test that function to start apache kafka raises exception if there is a timeout for the kafka server to start. :return: None
- test_startup_apache_kafka_function_raises_exception_on_erroneous_startup_to_kafka_server() None [source]#
Test that an erroneous call to start Apache Kafka server will raise an exception and thus no further start up of the backend server.
- Returns:
None
- test_startup_apache_kafka_function_raises_exception_on_failed_or_erroneous_startup() None [source]#
Test that function to start apache kafka starts Apache Kafka Zookeeper raises exception if there’s an erroneous start.
- Returns:
None
- test_startup_apache_kafka_function_starts_apache_kafka_server_after_successful_start_of_zookeeper(*_) None [source]#
Test that apache kafka startup function starts up apache kafka server after successfully starting zookeeper. :return: None
- class tests.api.test_endpoints.ApplicationBackendStartupAndShutdownTest(methodName='runTest')[source]#
Bases:
IsolatedAsyncioTestCase
Test case class for application backend lifecycle.
- async test_kafka_producer_and_consumer_are_closed_at_shutdown(close_apache_producer: Mock, shutdown_apache: Mock) None [source]#
Test that apache kafka producer and consumer is closed at close of backend.
- Parameters:
close_apache_producer – Mocked function closing the kafka producer
shutdown_apache – Mocked function for shutting down kafka
- Returns:
None
- class tests.api.test_endpoints.SetUpChatEndpointTestCase(methodName='runTest')[source]#
Bases:
BaseTestDatabaseTestCase
Test case class for end point setting up chat.
- classmethod setUpClass()[source]#
Hook method for setting up class fixture before running tests in the class.
- test_endpoint_creates_kafka_topic_for_the_chat_before_returning_response_on_successful_function_call() None [source]#
Test that endpoint calls function to create kafka topic before returning a response. :return: None
- test_endpoint_creates_new_application_controller_for_chat_session(*_) None [source]#
Test that endpoint creates application controller. :return: None
- test_endpoint_creates_new_chat_uuid_in_database_chats_table(*_) None [source]#
Test that request to endpoint creates new unique UUID record in test database :return: None
- test_endpoint_does_not_create_new_application_controller_if_there_is_a_failure_to_create_kafka_topic(mocked_application_controller: Mock) None [source]#
Test that endpoint does not create application controller in the event that creation of kafka topic was unsuccessful. :return: None
- test_endpoint_only_takes_post_requests(*_) None [source]#
Test that the endpoint only takes post request. :return: None
- test_endpoint_redirect_url_matches_that_of_the_expected_chat_url(*_) None [source]#
Test that URL redirected to from endpoint matches expected chat url :return: None
- test_endpoint_returns_redirect_response_pointing_to_the_url_for_the_chat(*_) None [source]#
Test that response to endpoint is a redirect request which points to the URL for the chat. :return: None
- class tests.api.test_endpoints.WebSocketTestCase(methodName='runTest')[source]#
Bases:
BaseTestDatabaseTestCase
Test case class for application web socket tests.