Skip to content

Commit

Permalink
feature/PI-311-fix_per_account_smoke_tests WIP 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohoolio committed Apr 3, 2024
1 parent 31a870f commit 0b7096c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/actions/pytest-with-rerun/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ inputs:
description: "[Optional] Assume the CI AWS Role during this operation?"
required: false
default: ""
workspace:
description: "[Optional] Workspace to derive secret from"
required: false
default: ""
runs:
using: "composite"
steps:
- uses: ./.github/actions/make/
with:
command: test--${{ inputs.test-type }}
command: test--${{ inputs.test-type }} WORKSPACE="${{ inputs.workspace }}"
requires-aws: ${{ inputs.requires-aws }}

- uses: ./.github/actions/make/
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,11 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ needs.get-branch-from-workflow-file.outputs.branch_name }}
- uses: ./.github/actions/make/
- uses: ./.github/actions/pytest-with-rerun/
with:
command: test--smoke
test-type: smoke
workspace: ${{ env.WORKSPACE }}
requires-aws: true
cache-suffix: ${{ env.CACHE_NAME }}

set-success:
name: Set Success
Expand Down
15 changes: 15 additions & 0 deletions src/conftest.py → conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import boto3
import pytest
from event.aws.client import dynamodb_client
from event.logging.logger import setup_logger
from nhs_context_logging.fixtures import ( # noqa: F401
Expand Down Expand Up @@ -118,3 +119,17 @@ def test_data_paths(request: FixtureRequest):
yield paths
else:
yield


def pytest_addoption(parser):
parser.addoption(
"--workspace",
action="store",
default="per_workspace",
help="workspace",
)


@pytest.fixture
def workspace(request):
return request.config.getoption("--workspace")
2 changes: 1 addition & 1 deletion scripts/test/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test--s3: aws--login ## Run (pytest) tests that require s3 downloads
$(MAKE) _pytest _INTERNAL_FLAGS="-m 's3'" _CACHE_CLEAR=$(_CACHE_CLEAR) AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) AWS_SESSION_TOKEN=$(AWS_SESSION_TOKEN)

test--smoke: aws--login ## Run end-to-end smoke tests (pytest)
$(MAKE) _pytest _INTERNAL_FLAGS="-m 'smoke'" _CACHE_CLEAR=$(_CACHE_CLEAR) AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) AWS_SESSION_TOKEN=$(AWS_SESSION_TOKEN)
$(MAKE) _pytest _INTERNAL_FLAGS="-m 'smoke' --workspace=$(WORKSPACE)" _CACHE_CLEAR=$(_CACHE_CLEAR) AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) AWS_SESSION_TOKEN=$(AWS_SESSION_TOKEN)

test--%--rerun: ## Rerun failed integration or unit (pytest) tests
$(MAKE) test--$* _INTERNAL_FLAGS="--last-failed --last-failed-no-failures none" _CACHE_CLEAR=
Expand Down
6 changes: 1 addition & 5 deletions src/smoke_tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from event.json import json_loads

from test_helpers.sample_data import ORGANISATION
from test_helpers.terraform import read_terraform_output


class SmokeTestError(Exception):
Expand Down Expand Up @@ -83,9 +82,7 @@ def create_apigee_url(apigee_env: str, workspace: str):
def _prepare_base_request(workspace: str) -> tuple[str, dict]:
client = boto3.client("secretsmanager")
workspace = "dev" if workspace not in PERSISTENT_ENVS else workspace

secret_name = f"{workspace}-apigee-app-key"

secret = client.get_secret_value(SecretId=secret_name)
appkey = secret["SecretString"]

Expand All @@ -105,9 +102,8 @@ def _prepare_base_request(workspace: str) -> tuple[str, dict]:


@pytest.mark.smoke
def test_smoke_tests():
def test_smoke_tests(workspace):
print("🏃 Running 🏃 smoke test - 🤔") # noqa: T201
workspace = read_terraform_output("workspace.value")
base_url, headers = _prepare_base_request(workspace=workspace)
for request_method in REQUEST_METHODS:
response = request_method(base_url=base_url, headers=headers)
Expand Down

0 comments on commit 0b7096c

Please sign in to comment.