tests.api package

Contents

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.

setUp()[source]#

Hook method for setting up the test fixture before exercising it.

classmethod setUpClass()[source]#

Hook method for setting up class fixture before running tests in the class.

tearDown()[source]#

Hook method for deconstructing the test fixture after testing it.

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

test_startup_apache_kafka_function_starts_apache_kafka_zookeeper() None[source]#

Test that the function to start apache kafka starts Apache Kafka Zookeeper

Returns:

None

test_startup_apache_kafka_raises_exception_on_failed_apache_kafka_server_startup(mocked_eventlet_timeout: Mock) None[source]#

Test that function to start apache kafka raises exception if during the startup of apache kafka server there was a startup failure. :return: None

class tests.api.test_endpoints.ApplicationBackendStartupAndShutdownTest(methodName='runTest')[source]#

Bases: IsolatedAsyncioTestCase

Test case class for application backend lifecycle.

setUp()[source]#

Hook method for setting up the test fixture before exercising it.

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

async test_kafka_producer_for_chat_end_point_starts_at_startup(mocked_start_apache_kafka_producer: Mock) None[source]#

Test that apache kafka producer is started at backend startup.

Parameters:

mocked_start_apache_kafka_producer – Mocked function to start apache kafka producer

Returns:

None

async test_kafka_starts_at_startup(mocked_startup_apache_kafka: Mock) None[source]#

Test that apache kafka stated at backend startup

Parameters:

mocked_startup_apache_kafka – Mocked function to startup apache 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

test_endpoint_returns_server_error_on_exception_from_function_to_create_kafka_topic() None[source]#

Test that endpoints returns with server error in the event that there is a failure (characterised by an exception while creating the kafka topic). :return: None

test_endpoint_takes_request_json_body_of_expected_type() None[source]#

Test that endpoint takes json request body of expected type (currently SetUpChatRequestBody) :return: None

class tests.api.test_endpoints.WebSocketTestCase(methodName='runTest')[source]#

Bases: BaseTestDatabaseTestCase

Test case class for application web socket tests.

classmethod setUpClass()[source]#

Hook method for setting up class fixture before running tests in the class.

test_that_connection_to_invalid_chat_websocket_url_cannot_be_established() None[source]#

Test that connection establishment with invalid chat web socket url cannot be established. The web socket connection route must pass validation checks.

Returns:

None

tests.api.test_endpoints.setUpModule()[source]#

Function containing executions before tests in module are run. :return:

tests.api.test_endpoints.tearDownModule()[source]#

Function containing executions after tests in module are ran. :return:

Module contents#