|
| 1 | +# coding=utf-8 |
| 2 | +"""Ping/echo API feature tests. |
| 3 | +
|
| 4 | +These tests document how the API framework in util/api.py (de)serializes |
| 5 | +various character encodings, end-to-end through the normal API request path |
| 6 | +(python-irodsclient, iRODS and back). |
| 7 | +""" |
| 8 | + |
| 9 | +__copyright__ = 'Copyright (c) 2026, Utrecht University' |
| 10 | +__license__ = 'GPLv3, see LICENSE' |
| 11 | + |
| 12 | +from pytest_bdd import ( |
| 13 | + parsers, |
| 14 | + scenarios, |
| 15 | + then, |
| 16 | + when, |
| 17 | +) |
| 18 | + |
| 19 | +from conftest import api_request |
| 20 | + |
| 21 | +scenarios('../../features/api/api_ping.feature') |
| 22 | + |
| 23 | +# String payloads echoed back verbatim by api_ping |
| 24 | +STRING_PAYLOADS = { |
| 25 | + "empty_string": "", |
| 26 | + "ascii_only_letters": "Hello world", |
| 27 | + "ascii_with_numbers": "The 39 steps", |
| 28 | + "ascii_with_punctuation": "Hello `~!@#$%^&*()-_=+;:'\"\\|<>,.?/", |
| 29 | + "ascii_with_newline": "Line 1\nLine 2", |
| 30 | + "ascii_long_10k": 9000 * "a", |
| 31 | + "non_ascii_letters": "blåbær smör mjólk brauð", |
| 32 | + "control_chars": "tab\there newline\nreturn\rnuli\0bell\a", |
| 33 | + "cjk": "日本語 한국어", # Kanji and Korean Unicode |
| 34 | + "emoji_astral": "\U0001f600\U0001f389", # Unicode outside basic multilingual plane (BMP) |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +@when(parsers.parse('the ping API is queried with the "{case}" payload'), target_fixture="api_response") |
| 39 | +def ping_query(user, case): |
| 40 | + return api_request(user, "ping", {"x": STRING_PAYLOADS[case]}) |
| 41 | + |
| 42 | + |
| 43 | +@then(parsers.parse('the ping response returns the "{case}" payload unchanged')) |
| 44 | +def ping_response_echoes(api_response, case): |
| 45 | + _, body = api_response |
| 46 | + payload = STRING_PAYLOADS[case] |
| 47 | + |
| 48 | + assert body["status"] == "ok", body |
| 49 | + assert body["data"] == payload |
| 50 | + |
| 51 | + |
| 52 | +@then(parsers.parse('the ping response is an error named "{name}"')) |
| 53 | +def ping_response_error(api_response, name): |
| 54 | + _, body = api_response |
| 55 | + assert body["status"] == "error_" + name, body |
0 commit comments