From 4d099079d93ca6986f3c77b4a9460377467a147e Mon Sep 17 00:00:00 2001 From: Albin Antony Date: Thu, 11 Jan 2024 17:03:32 +0530 Subject: [PATCH] Add #23 Add bdd test for issue_614.feature --- gherkin/features/issue_614/issue_614.feature | 2 +- gherkin/steps/issue_614.py | 54 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 gherkin/steps/issue_614.py diff --git a/gherkin/features/issue_614/issue_614.feature b/gherkin/features/issue_614/issue_614.feature index 67e4d83..8c41503 100644 --- a/gherkin/features/issue_614/issue_614.feature +++ b/gherkin/features/issue_614/issue_614.feature @@ -35,7 +35,7 @@ Feature: Update consent record @positive Scenario Outline: Update consent record with new request body and without query params - When I update consent record with id "", request body `{"consentRecord":{"optIn":true}}` and without query params + When I update consent record with id "", request body `{new request body}` and without query params Then It returns a consent record and revision. Check if consent record contains optIn as true Examples: diff --git a/gherkin/steps/issue_614.py b/gherkin/steps/issue_614.py new file mode 100644 index 0000000..17a5976 --- /dev/null +++ b/gherkin/steps/issue_614.py @@ -0,0 +1,54 @@ +import json + +import requests +from behave import * + + +@when( + 'I update consent record with id "{consentRecordId}", request body `{"optIn":false}` and without query params' +) +def step_impl(context, consentRecordId): + base_url = context.config.userdata.get("base_url") + data = {"optIn": False} + # Construct the full API endpoint URL + url = base_url + f"/service/individual/record/consent-record/{consentRecordId}" + # Make the PUT request + response = requests.put(url + "/", verify=False, json=data) + context.response = response + + +@then( + "It returns a consent record and revision. Check if consent record contains optIn as false" +) +def step_impl(context): + response_data = json.loads(context.response.content) + assert "consentRecord" in response_data, "Response does not contains consent record" + assert "revision" in response_data, "Response does not contains revision" + assert ( + response_data["consentRecord"]["optIn"] == False + ), "Consent record does not contain optIn as false" + + +@when( + 'I update consent record with id "{consentRecordId}", request body `{new request body}` and without query params' +) +def step_impl(context, consentRecordId): + base_url = context.config.userdata.get("base_url") + data = {"consentRecord": {"optIn": True}} + # Construct the full API endpoint URL + url = base_url + f"/service/individual/record/consent-record/{consentRecordId}" + # Make the PUT request + response = requests.put(url + "/", verify=False, json=data) + context.response = response + + +@then( + "It returns a consent record and revision. Check if consent record contains optIn as true" +) +def step_impl(context): + response_data = json.loads(context.response.content) + assert "consentRecord" in response_data, "Response does not contains consent record" + assert "revision" in response_data, "Response does not contains revision" + assert ( + response_data["consentRecord"]["optIn"] == True + ), "Consent record does not contain optIn as true"