Skip to content

Commit

Permalink
for behave test
Browse files Browse the repository at this point in the history
  • Loading branch information
rbi-aap committed Jun 7, 2024
1 parent 165cc8a commit 73a0b14
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions features/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from wooper.general import (
get_body
)

import logging

@when('we save API token')
def step_save_token(context):
Expand Down Expand Up @@ -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']):
Expand All @@ -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")

0 comments on commit 73a0b14

Please sign in to comment.