Skip to content

Commit 2e782f5

Browse files
committed
[feature/PI-563-read_a_questionnaire] read questionnaire
1 parent 8cb9a61 commit 2e782f5

File tree

28 files changed

+400
-98
lines changed

28 files changed

+400
-98
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"cSpell.words": [
1212
"attrlist",
1313
"changetype",
14+
"deserialise",
15+
"deserialiser",
16+
"DESERIALISERS",
1417
"filterstr",
1518
"firstchangenumber",
1619
"getbuffer",

infrastructure/swagger/05_paths.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,29 @@ paths:
546546
security:
547547
- ${authoriser_name}: []
548548
- app-level0: []
549+
550+
/Questionnaire/{questionnaire_id}:
551+
get:
552+
operationId: readQuestionnaire
553+
summary: readQuestionnaire endpoint for APIGEE integration
554+
parameters:
555+
- name: questionnaire_id
556+
in: path
557+
required: true
558+
description: logical identifier
559+
schema:
560+
type: string
561+
- *RequestHeaderVersion
562+
- *RequestHeaderRequestId
563+
- *RequestHeaderCorrelationId
564+
responses:
565+
"200":
566+
$ref: "#/components/responses/Questionnaire"
567+
"4XX":
568+
<<: *Response4XX
569+
x-amazon-apigateway-integration:
570+
<<: *ApiGatewayIntegration
571+
uri: ${method_readQuestionnaire}
572+
security:
573+
- ${authoriser_name}: []
574+
- app-level0: []

infrastructure/swagger/12_components--responses.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ components:
2424
enum: ["OK"]
2525
headers:
2626
<<: *ResponseHeaders
27+
28+
Questionnaire:
29+
description: Questionnaire response body
30+
content:
31+
application/json:
32+
schema:
33+
type: object
34+
properties:
35+
tbc:
36+
type: string
37+
2738
ProductTeamResponse:
2839
description: Read Product Team operation successful
2940
content:
@@ -89,4 +100,3 @@ components:
89100
updated_on:
90101
type: string
91102
deleted_on:
92-
type: string

infrastructure/terraform/per_workspace/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ module "lambdas" {
104104
environment_variables = {
105105
DYNAMODB_TABLE = module.table.dynamodb_table_name
106106
}
107-
attach_policy_statements = true
107+
attach_policy_statements = length((fileset("${path.module}/../../../src/api/${each.key}/policies", "*.json"))) > 0
108108
policy_statements = {
109109
for file in fileset("${path.module}/../../../src/api/${each.key}/policies", "*.json") : replace(file, ".json", "") => {
110110
effect = "Allow"

src/api/readQuestionnaire/index.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from api_utils.api_step_chain import execute_step_chain
2+
from event.logging.logger import setup_logger
3+
4+
from .src.v1.steps import steps as v1_steps
5+
6+
versioned_steps = {"1": v1_steps}
7+
cache = {}
8+
9+
10+
def handler(event: dict, context=None):
11+
setup_logger(service_name=__file__)
12+
return execute_step_chain(
13+
event=event,
14+
cache=cache,
15+
versioned_steps=versioned_steps,
16+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from builder.lambda_build import build
2+
3+
if __name__ == "__main__":
4+
build(__file__)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
2+
from domain.core.questionnaire.v2 import Questionnaire
3+
from domain.repository.questionnaire_repository import QuestionnaireRepository
4+
from domain.request_models.v1 import QuestionnairePathParams
5+
from domain.response.validation_errors import mark_validation_errors_as_inbound
6+
from event.step_chain import StepChain
7+
8+
9+
@mark_validation_errors_as_inbound
10+
def parse_path_params(data, cache) -> QuestionnairePathParams:
11+
event = APIGatewayProxyEvent(data[StepChain.INIT])
12+
return QuestionnairePathParams(**event.path_parameters)
13+
14+
15+
def read_questionnaire(data, cache) -> Questionnaire:
16+
path_params: QuestionnairePathParams = data[parse_path_params]
17+
repo = QuestionnaireRepository()
18+
return repo.read(name=path_params.questionnaire_id)
19+
20+
21+
def questionnaire_to_dict(data, cache) -> dict:
22+
questionnaire: Questionnaire = data[read_questionnaire]
23+
return questionnaire.state()
24+
25+
26+
steps = [
27+
parse_path_params,
28+
read_questionnaire,
29+
questionnaire_to_dict,
30+
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from event.json import json_loads
2+
3+
TABLE_NAME = "hiya"
4+
ODS_CODE = "F5H1R"
5+
PRODUCT_TEAM_ID = "F5H1R.641be376-3954-4339-822c-54071c9ff1a0"
6+
PRODUCT_TEAM_NAME = "product-team-name"
7+
PRODUCT_ID = "P.XXX-YYY"
8+
PRODUCT_NAME = "cpm-product-name"
9+
PRODUCT_TEAM_KEYS = [{"key_type": "product_team_id_alias", "key_value": "BAR"}]
10+
11+
12+
def test_index():
13+
from api.readQuestionnaire.index import handler
14+
15+
response = handler(
16+
event={
17+
"headers": {"version": "1"},
18+
"pathParameters": {"questionnaire_id": "spine_endpoint"},
19+
}
20+
)
21+
assert response["statusCode"] == 200
22+
23+
response_body: dict = json_loads(response["body"])
24+
questions: dict = response_body.pop("questions")
25+
assert response_body == {
26+
"name": "spine_endpoint",
27+
"version": "1",
28+
}
29+
assert len(questions) == 32
30+
31+
32+
def test_index_no_such_questionnaire():
33+
from api.readQuestionnaire.index import handler
34+
35+
response = handler(
36+
event={
37+
"headers": {"version": "1"},
38+
"pathParameters": {"questionnaire_id": "oops"},
39+
}
40+
)
41+
assert response["statusCode"] == 404
42+
43+
response_body = json_loads(response["body"])
44+
assert response_body == {
45+
"errors": [
46+
{
47+
"code": "RESOURCE_NOT_FOUND",
48+
"message": "Could not find Questionnaire for key ('oops')",
49+
},
50+
],
51+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Read Questionnaire - failure scenarios
2+
These scenarios demonstrate failure to read from the GET Questionnaire endpoint
3+
4+
Background:
5+
Given "default" request headers:
6+
| name | value |
7+
| version | 1 |
8+
| Authorization | letmein |
9+
10+
Scenario: Read an existing Questionnaire
11+
When I make a "GET" request with "default" headers to "Questionnaire/does-not-exist"
12+
Then I receive a status code "404" with body
13+
| path | value |
14+
| errors.0.code | RESOURCE_NOT_FOUND |
15+
| errors.0.message | Could not find Questionnaire for key ('does-not-exist') |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Read Questionnaire - success scenarios
2+
These scenarios demonstrate successful reads from the GET Questionnaire endpoint
3+
4+
Background:
5+
Given "default" request headers:
6+
| name | value |
7+
| version | 1 |
8+
| Authorization | letmein |
9+
10+
Scenario Outline: Read an existing Questionnaire
11+
When I make a "GET" request with "default" headers to "Questionnaire/<questionnaire_name>"
12+
Then I receive a status code "200" with body
13+
| path | value |
14+
| name | <questionnaire_name> |
15+
| version | 1 |
16+
| questions | << ignore >> |
17+
18+
Examples:
19+
| questionnaire_name |
20+
| spine_endpoint |
21+
| spine_device |

0 commit comments

Comments
 (0)