Skip to content

Commit 88407de

Browse files
NRL-518 Add step for upserts, refactor create and upsert into one method
1 parent d7d3c78 commit 88407de

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

tests/features/steps/2_request.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,16 @@ def create_post_document_reference_step(context: Context, ods_code: str):
9494
context.add_cleanup(lambda: context.repository.delete_by_id(doc_ref_id))
9595

9696

97-
@when(
98-
"producer 'TSTCUS' requests creation of a DocumentReference with default test values except '{section}' is"
99-
)
100-
def create_post_body_step(context: Context, section: str):
97+
def _create_or_upsert_body_step(
98+
context: Context, method: str, pointer_id: str = "TSTCUS-sample-id-00000"
99+
):
101100
client = producer_client_from_context(context, "TSTCUS")
102101

103102
if not context.text:
104103
raise ValueError("No document reference text snippet provided")
105104

106-
doc_ref = create_test_document_reference_with_defaults(section, context.text)
107-
context.response = client.create_text(doc_ref)
105+
doc_ref = create_test_document_reference_with_defaults("content", context.text)
106+
context.response = getattr(client, method)(doc_ref)
108107

109108
if context.response.status_code == 201:
110109
doc_ref_id = context.response.headers["Location"].split("/")[-1]
@@ -114,6 +113,20 @@ def create_post_body_step(context: Context, section: str):
114113
context.add_cleanup(lambda: context.repository.delete_by_id(doc_ref_id))
115114

116115

116+
@when(
117+
"producer 'TSTCUS' requests creation of a DocumentReference with default test values except '{section}' is"
118+
)
119+
def create_post_body_step(context: Context, section: str):
120+
_create_or_upsert_body_step(context, "create_text")
121+
122+
123+
@when(
124+
"producer 'TSTCUS' requests upsert of a DocumentReference with pointerId '{pointer_id}' and default test values except '{section}' is"
125+
)
126+
def upsert_post_body_step(context: Context, section: str, pointer_id: str):
127+
_create_or_upsert_body_step(context, "upsert_text", pointer_id)
128+
129+
117130
@when("producer '{ods_code}' upserts a DocumentReference with values")
118131
def create_put_document_reference_step(context: Context, ods_code: str):
119132
client = producer_client_from_context(context, ods_code)

tests/utilities/api_clients.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ def upsert(self, doc_ref):
213213
cert=self.config.client_cert,
214214
)
215215

216+
def upsert_text(self, doc_ref):
217+
return requests.put(
218+
f"{self.api_url}/DocumentReference",
219+
data=doc_ref,
220+
headers=self.request_headers,
221+
cert=self.config.client_cert,
222+
)
223+
216224
def update(self, doc_ref, doc_ref_id: str):
217225
return requests.put(
218226
f"{self.api_url}/DocumentReference/{doc_ref_id}",

0 commit comments

Comments
 (0)