Skip to content

Commit e91d221

Browse files
committed
[feature/PI-565-questionnaire_rethink] refactor read questionnaire api
1 parent 0b5b425 commit e91d221

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

src/api/readQuestionnaire/src/v1/steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
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
2+
from domain.core.questionnaire.v3 import Questionnaire
3+
from domain.repository.questionnaire_repository.v2 import QuestionnaireRepository
44
from domain.request_models.v1 import QuestionnairePathParams
55
from domain.response.validation_errors import mark_validation_errors_as_inbound
66
from event.step_chain import StepChain

src/api/readQuestionnaire/tests/test_index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ def test_index():
1515
response = handler(
1616
event={
1717
"headers": {"version": "1"},
18-
"pathParameters": {"questionnaire_id": "spine_endpoint"},
18+
"pathParameters": {"questionnaire_id": "spine_mhs"},
1919
}
2020
)
2121
assert response["statusCode"] == 200
2222

2323
response_body: dict = json_loads(response["body"])
24-
questions: dict = response_body.pop("questions")
24+
json_schema: dict = response_body.pop("json_schema")
2525
assert response_body == {
26-
"name": "spine_endpoint",
26+
"name": "spine_mhs",
2727
"version": "1",
2828
}
29-
assert len(questions) == 32
29+
assert len(json_schema["properties"]) == 25
3030

3131

3232
def test_index_no_such_questionnaire():

src/api/tests/feature_tests/features/readQuestionnaire.success.feature

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Feature: Read Questionnaire - success scenarios
1010
Scenario Outline: Read an existing Questionnaire
1111
When I make a "GET" request with "default" headers to "Questionnaire/<questionnaire_name>"
1212
Then I receive a status code "200" with body
13-
| path | value |
14-
| name | <questionnaire_name> |
15-
| version | 1 |
16-
| questions | << ignore >> |
13+
| path | value |
14+
| name | <questionnaire_name> |
15+
| version | 1 |
16+
| json_schema | << ignore >> |
1717

1818
Examples:
1919
| questionnaire_name |
20-
| spine_endpoint |
21-
| spine_device |
22-
| spine_ENDpoint |
23-
| SPINE_DEVICE |
20+
| spine_as |
21+
| spine_mhs |
22+
| spine_MHS |
23+
| SPINE_AS |

src/layers/domain/core/questionnaire/v3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from uuid import UUID, uuid4
33

44
import jsonschema
5+
from domain.core.aggregate_root import AggregateRoot
56
from domain.core.base import BaseModel
67
from domain.core.timestamp import now
78
from pydantic import Field, Json, validator
@@ -15,7 +16,7 @@ class QuestionnaireResponseValidationError(Exception): ...
1516
class QuestionnaireResponseMissingValue(Exception): ...
1617

1718

18-
class Questionnaire(BaseModel):
19+
class Questionnaire(AggregateRoot):
1920
name: str
2021
version: str
2122
json_schema: Json

src/layers/domain/repository/questionnaire_repository/v2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def read_schema(path: Path) -> str:
2828
class QuestionnaireRepository:
2929

3030
def read(self, name: str) -> Questionnaire:
31-
path = get_latest_schema_path_by_name(name=name)
31+
path = get_latest_schema_path_by_name(name=name.lower())
3232
if not path:
3333
raise ItemNotFound(name, item_type=Questionnaire)
3434
version = version_from_file_path(path)

0 commit comments

Comments
 (0)