|
| 1 | +from pytest_cases import parametrize_with_cases |
| 2 | + |
| 3 | +from infobip_channels.core.models import ResponseBase |
| 4 | +from infobip_channels.whatsapp.channel import WhatsAppChannel |
| 5 | +from infobip_channels.whatsapp.models.path_parameters.delete_template import ( |
| 6 | + DeleteTemplatePathParameters, |
| 7 | +) |
| 8 | +from tests.conftest import get_expected_delete_headers, get_response_object |
| 9 | +from tests.whatsapp.conftest import ( |
| 10 | + get_response_object_unofficial, |
| 11 | + get_whatsapp_channel_instance, |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +def delete_template_request( |
| 16 | + http_server, |
| 17 | + response, |
| 18 | + instantiation_type, |
| 19 | + path_parameters_type, |
| 20 | + **kwargs, |
| 21 | +): |
| 22 | + path_parameter_instance = path_parameter = DeleteTemplatePathParameters( |
| 23 | + sender="38598765321", template_name="test" |
| 24 | + ) |
| 25 | + http_server.expect_request( |
| 26 | + "/whatsapp/2/senders/38598765321/templates/test", |
| 27 | + method="DELETE", |
| 28 | + headers=get_expected_delete_headers(), |
| 29 | + ).respond_with_response(response) |
| 30 | + |
| 31 | + whatsapp_channel = get_whatsapp_channel_instance(instantiation_type, **kwargs) |
| 32 | + |
| 33 | + if path_parameters_type == "dict": |
| 34 | + path_parameter = path_parameter_instance.dict() |
| 35 | + |
| 36 | + return whatsapp_channel.delete_template(path_parameter) |
| 37 | + |
| 38 | + |
| 39 | +@parametrize_with_cases( |
| 40 | + "status_code, response_content, path_parameters_type, " |
| 41 | + "whatsapp_channel_instantiation_type", |
| 42 | + prefix="from_all_instantiation_types_case__valid_content", |
| 43 | +) |
| 44 | +def test_delete_template_from_all_instantiation_types_case__valid_content( |
| 45 | + httpserver, |
| 46 | + http_test_client, |
| 47 | + status_code, |
| 48 | + response_content, |
| 49 | + path_parameters_type, |
| 50 | + whatsapp_channel_instantiation_type, |
| 51 | +): |
| 52 | + response = delete_template_request( |
| 53 | + http_server=httpserver, |
| 54 | + response=get_response_object(status_code, response_content), |
| 55 | + instantiation_type=whatsapp_channel_instantiation_type, |
| 56 | + path_parameters_type=path_parameters_type, |
| 57 | + server_url=httpserver.url_for("/"), |
| 58 | + client=http_test_client( |
| 59 | + url=httpserver.url_for("/"), |
| 60 | + headers=WhatsAppChannel.build_delete_request_headers("secret"), |
| 61 | + ), |
| 62 | + ) |
| 63 | + |
| 64 | + assert response is not None |
| 65 | + assert response.status_code == status_code |
| 66 | + |
| 67 | + |
| 68 | +@parametrize_with_cases( |
| 69 | + "status_code, response_content, path_parameters_type, " |
| 70 | + "whatsapp_channel_instantiation_type", |
| 71 | + prefix="from_all_instantiation_types_case__invalid_content", |
| 72 | +) |
| 73 | +def test_create_template_from_all_instantiation_types_case__invalid_content( |
| 74 | + httpserver, |
| 75 | + http_test_client, |
| 76 | + http_test_client_unofficial, |
| 77 | + status_code, |
| 78 | + response_content, |
| 79 | + path_parameters_type, |
| 80 | + whatsapp_channel_instantiation_type, |
| 81 | +): |
| 82 | + if whatsapp_channel_instantiation_type == "client_unofficial": |
| 83 | + client = http_test_client_unofficial |
| 84 | + response_object = get_response_object_unofficial |
| 85 | + else: |
| 86 | + client = http_test_client |
| 87 | + response_object = get_response_object |
| 88 | + |
| 89 | + response = delete_template_request( |
| 90 | + http_server=httpserver, |
| 91 | + response=response_object(status_code, response_content), |
| 92 | + instantiation_type=whatsapp_channel_instantiation_type, |
| 93 | + path_parameters_type=path_parameters_type, |
| 94 | + server_url=httpserver.url_for("/"), |
| 95 | + client=client( |
| 96 | + url=httpserver.url_for("/"), |
| 97 | + headers=WhatsAppChannel.build_delete_request_headers("secret"), |
| 98 | + ), |
| 99 | + ) |
| 100 | + |
| 101 | + assert isinstance(response, ResponseBase) is False |
| 102 | + assert response is not None |
| 103 | + |
| 104 | + if whatsapp_channel_instantiation_type != "client_unofficial": |
| 105 | + assert response.status_code == status_code |
| 106 | + assert response.json() == response_content |
0 commit comments