From 73a0b14e89189e036b9ec4dce140371e13d743ee Mon Sep 17 00:00:00 2001 From: rbi-aap Date: Fri, 7 Jun 2024 16:27:46 +1000 Subject: [PATCH] for behave test --- features/steps/steps.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/features/steps/steps.py b/features/steps/steps.py index 9bd4f6ae..ba4bb5b1 100644 --- a/features/steps/steps.py +++ b/features/steps/steps.py @@ -17,7 +17,7 @@ from wooper.general import ( get_body ) - +import logging @when('we save API token') def step_save_token(context): @@ -63,7 +63,6 @@ def we_set_api_time_limit(context, value): with context.app.test_request_context(): get_settings_collection().insert_one({"_id": "general_settings", "values": {"news_api_time_limit_days": value}}) - @then('we "{get}" "{text}" in atom xml response') def we_get_text_in_atom_xml_response(context, get, text): with context.app.test_request_context(context.app.config['URL_PREFIX']): @@ -74,3 +73,20 @@ def we_get_text_in_atom_xml_response(context, get, text): assert (text in get_body(context.response)) else: assert (text not in get_body(context.response)) + +@then('we "{get}" "{text}" in syndicate xml response') +def we_get_text_in_syndicate_xml_response(context, get, text): + with context.app.test_request_context(context.app.config['URL_PREFIX']): + response_body = get_body(context.response) + logging.info("Response body: %s", response_body) + assert (isinstance(get_body(context.response), str)) + try: + tree = lxml.etree.fromstring(response_body.encode('utf-8')) + assert '{http://www.w3.org/2005/Atom}feed' == tree.tag + if get == 'get': + assert (text in response_body) + else: + assert (text not in response_body) + except lxml.etree.XMLSyntaxError as e: + logging.error("XML parsing error: %s", e) + raise AssertionError("Response is not valid XML")