|
| 1 | +"""Tests for env.template functionality.""" |
| 2 | +from notecard import env |
| 3 | + |
| 4 | + |
| 5 | +def test_env_template_basic(run_fluent_api_notecard_api_mapping_test): |
| 6 | + """Test env.template with no body parameter.""" |
| 7 | + run_fluent_api_notecard_api_mapping_test( |
| 8 | + env.template, 'env.template', {}) |
| 9 | + |
| 10 | + |
| 11 | +def test_env_template_with_boolean(run_fluent_api_notecard_api_mapping_test): |
| 12 | + """Test env.template with boolean type hint.""" |
| 13 | + run_fluent_api_notecard_api_mapping_test( |
| 14 | + env.template, 'env.template', {'body': {'my_bool': True}}) |
| 15 | + |
| 16 | + |
| 17 | +def test_env_template_with_string_pre_321( |
| 18 | + run_fluent_api_notecard_api_mapping_test): |
| 19 | + """Test string type hint in env.template. |
| 20 | +
|
| 21 | + For pre v3.2.1 format.""" |
| 22 | + body = {'my_string': '42'} |
| 23 | + run_fluent_api_notecard_api_mapping_test( |
| 24 | + env.template, 'env.template', {'body': body}) |
| 25 | + |
| 26 | + |
| 27 | +def test_env_template_with_string_post_321( |
| 28 | + run_fluent_api_notecard_api_mapping_test): |
| 29 | + """Test string type hint in env.template. |
| 30 | +
|
| 31 | + For post v3.2.1 format.""" |
| 32 | + body = {'my_string': 'variable'} |
| 33 | + run_fluent_api_notecard_api_mapping_test( |
| 34 | + env.template, 'env.template', {'body': body}) |
| 35 | + |
| 36 | + |
| 37 | +def test_env_template_with_signed_integers( |
| 38 | + run_fluent_api_notecard_api_mapping_test): |
| 39 | + """Test signed integer hints. |
| 40 | +
|
| 41 | + Covers all supported sizes.""" |
| 42 | + body = { |
| 43 | + 'int8': 11, # 1 byte signed |
| 44 | + 'int16': 12, # 2 byte signed |
| 45 | + 'int24': 13, # 3 byte signed |
| 46 | + 'int32': 14, # 4 byte signed |
| 47 | + 'int64': 18 # 8 byte signed |
| 48 | + } |
| 49 | + run_fluent_api_notecard_api_mapping_test( |
| 50 | + env.template, 'env.template', {'body': body}) |
| 51 | + |
| 52 | + |
| 53 | +def test_env_template_with_unsigned_integers( |
| 54 | + run_fluent_api_notecard_api_mapping_test): |
| 55 | + """Test unsigned integer hints. |
| 56 | +
|
| 57 | + Covers all supported sizes.""" |
| 58 | + body = { |
| 59 | + 'uint8': 21, # 1 byte unsigned |
| 60 | + 'uint16': 22, # 2 byte unsigned |
| 61 | + 'uint24': 23, # 3 byte unsigned |
| 62 | + 'uint32': 24 # 4 byte unsigned |
| 63 | + } |
| 64 | + run_fluent_api_notecard_api_mapping_test( |
| 65 | + env.template, 'env.template', {'body': body}) |
| 66 | + |
| 67 | + |
| 68 | +def test_env_template_with_floats(run_fluent_api_notecard_api_mapping_test): |
| 69 | + """Test env.template with float type hints.""" |
| 70 | + body = { |
| 71 | + 'float16': 12.1, # 2 byte float |
| 72 | + 'float32': 14.1, # 4 byte float |
| 73 | + 'float64': 18.1 # 8 byte float |
| 74 | + } |
| 75 | + run_fluent_api_notecard_api_mapping_test( |
| 76 | + env.template, 'env.template', {'body': body}) |
| 77 | + |
| 78 | + |
| 79 | +def test_env_template_with_mixed_types( |
| 80 | + run_fluent_api_notecard_api_mapping_test): |
| 81 | + """Test mixed type hints. |
| 82 | +
|
| 83 | + Tests bool, str, float, int.""" |
| 84 | + body = { |
| 85 | + 'active': True, |
| 86 | + 'name': '32', |
| 87 | + 'temperature': 14.1, |
| 88 | + 'counter': 12 |
| 89 | + } |
| 90 | + run_fluent_api_notecard_api_mapping_test( |
| 91 | + env.template, 'env.template', {'body': body}) |
| 92 | + |
| 93 | + |
| 94 | +def test_env_template_response(card): |
| 95 | + """Test env.template response contains bytes field.""" |
| 96 | + card.Transaction.return_value = {'bytes': 42} |
| 97 | + response = env.template(card) |
| 98 | + assert 'bytes' in response |
| 99 | + assert isinstance(response['bytes'], int) |
0 commit comments