Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RELEASE/2023-11-24 #86

Merged
merged 8 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ env:
TF_CLI_ARGS: -no-color

jobs:
workflow--check--branch-name:
runs-on: [self-hosted, ci]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }}
- uses: ./.github/actions/make/
with:
command: workflow--check--branch-name

parse-secrets:
runs-on: [self-hosted, ci]
needs: [workflow--check--branch-name]
steps:
- id: parse-secrets
run: |
echo "::add-mask::${{ secrets.CI_ROLE_NAME }}"

create-workspace-name:
runs-on: [self-hosted, ci]
needs: [workflow--check--branch-name]
outputs:
workspace: ${{ steps.create_workspace_name.outputs.workspace }}
steps:
Expand All @@ -38,16 +50,6 @@ jobs:
echo "workspace=ci-$(echo ${{ env.BRANCH_NAME }} | sed -n 's/.*\/\([^-]*\)-\([^-]*\).*/\1-\2/p')-${{ env.BRANCH_GITHUB_SHA_SHORT }}" >> $GITHUB_OUTPUT
fi

workflow--check--branch-name:
runs-on: [self-hosted, ci]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }}
- uses: ./.github/actions/make/
with:
command: workflow--check--branch-name

build-head:
runs-on: [self-hosted, ci]
needs: [parse-secrets]
Expand All @@ -61,6 +63,7 @@ jobs:

build-base:
runs-on: [self-hosted, ci]
needs: [workflow--check--branch-name]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -72,7 +75,7 @@ jobs:

workflow--codebase-checks:
runs-on: [self-hosted, ci]
needs: [workflow--check--branch-name, build-head]
needs: [build-head]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -108,6 +111,7 @@ jobs:

helpers--truststore-pull:
runs-on: [self-hosted, ci]
needs: [workflow--check--branch-name]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -187,7 +191,7 @@ jobs:

destroy-redundant-workspaces:
runs-on: [self-hosted, ci]
needs: [workflow--check--branch-name, build-head]
needs: [build-head]
steps:
- uses: actions/checkout@v4
with:
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"cSpell.words": ["Pynamo", "pynamodb"],
"editor.formatOnSave": true,
"black-formatter.args": ["--line-length=88"]
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2023-11-24
- [PI-124] Revert Domain to AR model
- [PI-130] Move Check Branch to the beginning of CI Pipeline

## 2023-11-23
- [PI-110] Step chain refactor
- [PI-100] NHS Context logging
Expand Down
2 changes: 2 additions & 0 deletions changelog/2023-11-24.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [PI-124] Revert Domain to AR model
- [PI-130] Move Check Branch to the beginning of CI Pipeline
12 changes: 0 additions & 12 deletions feature_tests/features/ods_organisation.failure.feature

This file was deleted.

12 changes: 0 additions & 12 deletions feature_tests/features/ods_organisation.success.feature

This file was deleted.

26 changes: 1 addition & 25 deletions feature_tests/features/product_team.failure.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,6 @@ Feature: Product Teams Failure Scenarios
Given ODS Organisations:
| ods_code | name |
| H8S7A | BURENDO |
And Users:
| user_id | name |
| [email protected] | Test User |
When User "[email protected]" creates Product Team {00702d39-e65f-49f5-b9ef-6570245bfe17} called " " for supplier H8S7A
Then the operation is not successful
And the error is BadEntityNameError

# # COMMENTED OUT SINCE CAN'T TEST THIS WITH DOMAIN CODE
# Scenario: Failure - unknown supplier
# Given ODS Organisations:
# | ods_code | name |
# And Users:
# | user_id | name |
# | [email protected] | Test User |
# When User "[email protected]" creates Product Team {00702d39-e65f-49f5-b9ef-6570245bfe17} called "BURENDO" for supplier H8S7A
# Then the operation is not successful
# And the error is InvalidTypeError
# # COMMENTED OUT SINCE CAN'T TEST THIS WITH DOMAIN CODE
# Scenario: Failure - unknown user
# Given ODS Organisations:
# | ods_code | name |
# | H8S7A | BURENDO |
# And Users:
# | user_id | name |
# When User "[email protected]" creates Product Team {00702d39-e65f-49f5-b9ef-6570245bfe17} called "BURENDO" for supplier H8S7A
# Then the operation is not successful
# And the error is NotFoundError
And the error is ValidationError
27 changes: 9 additions & 18 deletions feature_tests/features/product_team.success.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,21 @@ Feature: Product Teams Success Scenarios
Given ODS Organisations:
| ods_code | name |
| <ods_code> | <ods_name> |
And Users:
| user_id | name |
| <user_id> | Test User |
When User "<user_id>" creates Product Team <id> called "<name>" for supplier <ods_code>
Then the operation is successful
And the result is a ProductTeam with:
| property | value |
| id | <id> |
| name | <name> |
And the result organisation is an OdsOrganisation with:
| property | value |
| id | <ods_code> |
And the result owner is a User with:
| property | value |
| id | <user_id> |
And the following events were raised:
| id | <id> |
| name | <name> |
| ods_code | <ods_code> |
And the following events were raised for the result:
| event |
| ProductTeamCreatedEvent |
And event #1 is ProductTeamCreatedEvent with:
| property | value |
| product_team.id | <id> |
| product_team.name | <name> |
| product_team.organisation.id | <ods_code> |
| product_team.owner.id | <user_id> |
And event #1 of the result is ProductTeamCreatedEvent with:
| property | value |
| id | <id> |
| name | <name> |
| ods_code | <ods_code> |

Examples:
| id | name | ods_code | ods_name | user_id |
Expand Down
8 changes: 3 additions & 5 deletions feature_tests/steps/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import parse
from behave import register_type
from domain.core.error import BadEntityNameError, InvalidOdsCodeError, InvalidTypeError
from domain.core.product import ProductTeamCreatedEvent
from domain.core.product_team import ProductTeamCreatedEvent
from pydantic import ValidationError

from feature_tests.steps.context import Context

Expand Down Expand Up @@ -65,10 +65,8 @@ def inner(context: Context, *args, **kwargs):


EXPECTED_TYPES = {
"BadEntityNameError": BadEntityNameError,
"InvalidTypeError": InvalidTypeError,
"ProductTeamCreatedEvent": ProductTeamCreatedEvent,
"InvalidOdsCodeError": InvalidOdsCodeError,
"ValidationError": ValidationError,
}


Expand Down
4 changes: 1 addition & 3 deletions feature_tests/steps/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

from behave.model import Table
from behave.runner import Context as BehaveContext
from domain.core.product import OdsOrganisation
from domain.core.ods_organisation import OdsOrganisation
from domain.core.questionnaire import Questionnaire
from domain.core.user import User
from domain.events.event import Event


@dataclass
class Context(BehaveContext):
# Extra domain specific fields
questionnaires: dict[str, Questionnaire]
users: dict[str, User]
ods_organisations: dict[str, OdsOrganisation]
events: list[Event]
error: list
Expand Down
13 changes: 7 additions & 6 deletions feature_tests/steps/event_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
from feature_tests.steps.context import Context


@then("the following events were raised")
@then("the following events were raised for the result")
def step_impl(context: Context):
assert len(context.events) == len(
assert len(context.result.events) == len(
context.table.rows
), "event count mismatch: too many raised"
), f"event count mismatch: expected {len(context.table.rows)} got {len(context.subject.events)}"

for row, event in zip(context.table, context.events):
type_name = row["event"]
assert_type_matches(obj=event, expected_type_name=type_name)


@then("event #{ix:Number} is {type_name:String} with")
@then("event #{ix:Number} of the result is {type_name:String} with")
def step_impl(context: Context, ix, type_name):
assert ix <= len(context.events), "Invalid event index"
event = context.events[ix - 1]
events = context.result.events
assert ix <= len(events), "Invalid event index"
event = events[ix - 1]
assert_type_matches(obj=event, expected_type_name=type_name)
for row in context.table:
path = row["property"]
Expand Down
2 changes: 1 addition & 1 deletion feature_tests/steps/ods_organisation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def _add_ods_org_to_context(context: Context, ods_code: str, name: str):
context.ods_organisations[ods_code] = Root.create_ods_organisation(
id=ods_code, name=name
ods_code=ods_code, name=name
)


Expand Down
6 changes: 1 addition & 5 deletions feature_tests/steps/product_team_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
)
@catch_errors
def step_impl(context: Context, user_id, id, name, ods_code):
owner = context.users[user_id]
context.subject = context.ods_organisations[ods_code]
(product_team, event) = context.subject.create_product_team(
id=id, name=name, owner=owner
)
product_team = context.subject.create_product_team(id=id, name=name)
context.result = product_team
context.events.append(event)
4 changes: 3 additions & 1 deletion feature_tests/steps/questionnaire_steps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid

from behave import given, then, when
from domain.core.questionnaire import Questionnaire, QuestionType

Expand All @@ -6,7 +8,7 @@

@given("Questionnaire {id}")
def given__questionnaire(context: Context, id: str):
q = Questionnaire(id, id)
q = Questionnaire(id=uuid.uuid4(), name=id)
context.questionnaires[id] = q


Expand Down
1 change: 1 addition & 0 deletions feature_tests/steps/result_steps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from behave import then
from domain.core.reference import Reference

from feature_tests.steps.common import parse_value, read_value_from_path
from feature_tests.steps.context import Context
Expand Down
19 changes: 0 additions & 19 deletions feature_tests/steps/user_steps.py

This file was deleted.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pydantic = "1.10.13"
nhs-context-logging = "^0.3.0"
requests = "^2.31.0"
aws-lambda-powertools = "^2.26.0"
pynamodb = "^5.5.0"
email-validator = "^2.1.0.post1"

[tool.poetry.group.dev.dependencies]
Expand All @@ -34,10 +33,11 @@ hypothesis = "^6.87.3"
aws-lambda-powertools = { extras = ["aws-sdk"], version = "^2.26.0" }
parse = "^1.19.1"
pytest-mock = "^3.12.0"
moto = "^4.2.7"
datamodel-code-generator = "^0.24.2"
pyyaml = "^6.0.1"
proxygen-cli = "^2.0.15"
moto = "^4.2.9"
urllib3 = "<2"

[build-system]
requires = ["poetry-core"]
Expand All @@ -47,5 +47,5 @@ build-backend = "poetry.core.masonry.api"
profile = "black"

[tool.pytest.ini_options]
markers = ["unit", "integration", "smoke", "slow"]
markers = ["unit", "integration", "smoke", "slow", "wip"]
addopts = "--import-mode=importlib"
17 changes: 17 additions & 0 deletions src/api/createProductTeam/src/v1/steps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from http import HTTPStatus

from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent
from domain.core.product_team import ProductTeam, ProductTeamCreatedEvent
from domain.core.root import Root
from domain.fhir.r4 import Organization # StrictOrganization
from event.step_chain import StepChain

Expand All @@ -13,6 +15,21 @@ def _parse_fhir_organisation(organisation: dict) -> Organization:
return org


def _create_product_team(
event: APIGatewayProxyEvent,
) -> tuple[ProductTeam, ProductTeamCreatedEvent]:
_product_team: dict = event.json_body

organisation = Root.create_ods_organisation(
ods_code=_product_team["ods_code"], name="Test"
)
product_team = organisation.create_product_team(
id=_product_team["id"],
name=_product_team["name"],
)
return product_team


def parse_fhir_organisation(data, cache) -> Organization:
event = APIGatewayProxyEvent(data[StepChain.INIT])
return _parse_fhir_organisation(organisation=event.json_body)
Expand Down
Loading
Loading