|
| 1 | +import json |
| 2 | + |
1 | 3 | from behave import * # noqa |
2 | 4 | from behave.runner import Context |
3 | 5 |
|
@@ -130,6 +132,28 @@ def upsert_post_body_step(context: Context, section: str, pointer_id: str): |
130 | 132 | _create_or_upsert_body_step(context, "upsert_text", section, pointer_id) |
131 | 133 |
|
132 | 134 |
|
| 135 | +@when( |
| 136 | + "producer 'TSTCUS' requests update of a DocumentReference with pointerId '{pointer_id}' and only changing" |
| 137 | +) |
| 138 | +def update_post_body_step(context: Context, pointer_id: str): |
| 139 | + """ |
| 140 | + Updates an existing DocumentReference with new values for a specific section |
| 141 | + """ |
| 142 | + consumer_client = consumer_client_from_context(context, "TSTCUS") |
| 143 | + context.response = consumer_client.read(pointer_id) |
| 144 | + |
| 145 | + if context.response.status_code != 200: |
| 146 | + raise ValueError(f"Failed to read existing pointer: {context.response.text}") |
| 147 | + |
| 148 | + doc_ref = context.response.json() |
| 149 | + custom_data = json.loads(context.text) |
| 150 | + for key in custom_data: |
| 151 | + doc_ref[key] = custom_data[key] |
| 152 | + |
| 153 | + producer_client = producer_client_from_context(context, "TSTCUS") |
| 154 | + context.response = producer_client.update(doc_ref, pointer_id) |
| 155 | + |
| 156 | + |
133 | 157 | @when("producer '{ods_code}' upserts a DocumentReference with values") |
134 | 158 | def create_put_document_reference_step(context: Context, ods_code: str): |
135 | 159 | client = producer_client_from_context(context, ods_code) |
|
0 commit comments