Skip to content

Commit

Permalink
Merge pull request #66 from GovStackWorkingGroup/behave
Browse files Browse the repository at this point in the history
TECH-757: Migrate pytest-bdd to behave
  • Loading branch information
dborowiecki authored Dec 3, 2023
2 parents 52629fd + e674b9a commit 3f7d2e2
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 190 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2.1
setup: true

orbs:
test-harness: govstack-working-group/[email protected].5
test-harness: govstack-working-group/[email protected].6

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
Expand All @@ -21,4 +21,6 @@ workflows:
- test-harness/execute-tests:
requires:
- test-harness/create-config
context:
- bb-testing

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Test and docker stuff
test/gherkin/test_data/
test/gherkin/result/
test/*/test_data/
test/*/result/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
6 changes: 3 additions & 3 deletions test/gherkin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM python:3.8
FROM python:3.10

COPY requirements.txt /requirements.txt

RUN pip install -r /requirements.txt

COPY . /tests
COPY ./features /tests

WORKDIR /tests/

#ENV CONSENTBB_API_HOST=localhost:8080
ENV CONSENTBB_API_HOST=localhost:8888
ENV CONSENTBB_API_PATH=/api

CMD pytest --cucumberjson=/data/results.json /tests
CMD behave --format json --summary --outfile=/data/results.json /tests
37 changes: 0 additions & 37 deletions test/gherkin/conftest.py

This file was deleted.

8 changes: 0 additions & 8 deletions test/gherkin/features/config_policy_create.feature

This file was deleted.

16 changes: 0 additions & 16 deletions test/gherkin/features/config_policy_read.feature

This file was deleted.

28 changes: 28 additions & 0 deletions test/gherkin/features/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import requests


from behave import fixture, use_fixture


@fixture
def client(context):
url = "https://{}{}".format(
os.environ["CONSENTBB_API_HOST"],
os.environ["CONSENTBB_API_PATH"]
)

context.session = requests.Session()

# Save our api_url on the session. This property doesn't have anything at all to do with
# the requests library, it's our own little thing :)
context.session.api_url = url

# We are self-signing SSL certificates in example deployments.
context.session.verify = False
yield context.session
context.session.close()


def before_all(context):
use_fixture(client, context,)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@method=GET @endpoint=/service/policy/{policyId}/
Feature: The Consent Building Block exists

@smoke
Expand Down
37 changes: 37 additions & 0 deletions test/gherkin/features/steps/smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json
import os

from behave import given, when, then


@given("A URL of a Consent Building Block instance")
def step_impl(context):

# We just use the API url given from the context, a more advanced
# setup could try other API base urls.
assert context.session.api_url
context.api_url = context.session.api_url


@when("I call a basic public API endpoint")
def step_impl(context):
"""
This method currently calls a well-known API with fixture data (policy ID=1).
However, we would like to call a GovStack status API instead, but this isn't yet a feature that has
been developed across building blocks.
"""
context.response = context.session.get(
os.path.join(context.api_url, "service/policy/1/")
)


@then("I get some valid JSON data back")
def step_impl(context):
if not context.response.status_code == 200:
raise AssertionError(f"Got status code {context.response.status_code}\n\nContent:\n{context.response.content}")
response_data = json.loads(context.response.content)
assert isinstance(response_data, dict)
# This is the Policy object
assert isinstance(response_data["policy"], dict)
# This is the Revision object
assert isinstance(response_data["revision"], dict)
File renamed without changes.
8 changes: 0 additions & 8 deletions test/gherkin/pytest.ini

This file was deleted.

5 changes: 2 additions & 3 deletions test/gherkin/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pytest
pytest-bdd
requests
behave>=1.2.6,<1.3
requests>=2.31.0,<3
8 changes: 7 additions & 1 deletion test/gherkin/test_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ mkdir -p test-data-volume

docker-compose up --build

echo "Gherkin tests finished. Fetching and moving test report."

TEST_REPORT=./result/example_result.message

mkdir -p ./result
cp ./test_data/results.json ./result/example_result.message
cp ./test_data/results.json $TEST_REPORT

echo "Wrote $TEST_REPORT, ready for uploading."
Empty file removed test/gherkin/tests/__init__.py
Empty file.
18 changes: 0 additions & 18 deletions test/gherkin/tests/shared_steps.py

This file was deleted.

62 changes: 0 additions & 62 deletions test/gherkin/tests/test_config_policy.py

This file was deleted.

31 changes: 0 additions & 31 deletions test/gherkin/tests/test_smoke.py

This file was deleted.

0 comments on commit 3f7d2e2

Please sign in to comment.