Skip to content

Commit

Permalink
feat: Better tests (ability to remember response count)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Christie committed Jan 16, 2025
1 parent 4511fbd commit e29b03e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
8 changes: 5 additions & 3 deletions behaviour/features/squonk-basic-job-execution.feature
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ Feature: Verify a fragalysis stack can run Squonk Jobs against public Targets
And I can get the "Behaviour Snapshot" Snapshot ID
And I can get the last JobFileTransfer SUB_PATH
When I login
And I run fragmenstein-combine with the following variables
And I do a GET request at /api/compound-sets
And remember the count
And I run "fragmenstein-combine" from the "fragmenstein" collection with the following variables
"""
{
"protein": "fragalysis-files/{SUB_PATH}/A71EV2A-x0152_A_201_1_A71EV2A-x3977+A+202+1_apo-desolv.pdb",
Expand All @@ -107,10 +109,10 @@ Feature: Verify a fragalysis stack can run Squonk Jobs against public Targets
"""
Then the response should be ACCEPTED
And the response should contain a JobRequest ID
And the JobRequest should have a job_status value of SUCCESS within 1 minute
And the JobRequest should have a job_status value of SUCCESS within 2 minutes
And the JobRequest should have an upload_status value of SUCCESS within 20 seconds
When I do a GET request at /api/compound-sets
Then the length of the list in the response should be 1
Then the count must be one larger than the remembered count

Scenario: Delete the last FileTransfer
Given I can login
Expand Down
5 changes: 3 additions & 2 deletions behaviour/features/steps/api_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A collection of functions to simplify access to the stack's API,
"""
A collection of functions to simplify access to the stack's REST API,
used primarily to reduce the number of lines in the step file.
"""

Expand Down Expand Up @@ -151,7 +152,7 @@ def initiate_job_request(
"""Runs a Job in Squonk."""

# Convert the Job specification to a string
# and then replace all the occurences of `{SUB_PATH}` with the job_sub_path
# and then replace all the occurrences of `{SUB_PATH}` with the job_sub_path
job_spec_str = json.dumps(job_spec)
job_spec_str = job_spec_str.replace("{SUB_PATH}", job_sub_path)

Expand Down
5 changes: 4 additions & 1 deletion behaviour/features/steps/awx_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""AWX utilities for steps."""
"""
AWX utilities for steps.
Logic that allows us to run AWX Job Templates (to wipe and create stacks).
"""

import os
import shlex
Expand Down
3 changes: 2 additions & 1 deletion behaviour/features/steps/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common config for the behaviour test steps.
"""
Common config for the behaviour test steps.
Essentially all the environment variables we need to run the tests.
"""

Expand Down
35 changes: 32 additions & 3 deletions behaviour/features/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ def i_delete_the_job_file_transfer(context) -> None:
context.status_code = resp.status_code


@when("I run {job_name} with the following variables") # pylint: disable=not-callable
def i_run_x_with_the_following_variables(context, job_name) -> None:
@when( # pylint: disable=not-callable
'I run "{job_name}" from the "{collection_name}" collection with the following variables'
)
def i_run_x_with_the_following_variables(context, job_name, collection_name) -> None:
"""Run a given Job replacing each occurrence of {SUB_PATH} in the Job specification
with the sub-path used by the file transfer logic. It relies on context members: -
- stack_name
Expand Down Expand Up @@ -383,7 +385,7 @@ def i_run_x_with_the_following_variables(context, job_name) -> None:
assert context.text is not None
variables: Dict[str, Any] = ast.literal_eval(context.text)
spec = {
"collection": "fragmenstein",
"collection": collection_name,
"job": job_name,
"version": "1.0.0",
"variables": variables,
Expand Down Expand Up @@ -427,6 +429,33 @@ def the_landing_page_response_should_be_x(context, status_code_name) -> None:
assert resp.status_code == expected_code


@when("remember the count") # pylint: disable=not-callable
def remember_the_count(context) -> None:
"""Relies on context members: -
- response_count
Sets the following context members: -
- remembered_response_count
"""
assert context.failed is False
assert hasattr(context, "response_count")

context.remembered_response_count = context.response_count


@then(
"the count must be one larger than the remembered count"
) # pylint: disable=not-callable
def the_count_must_be_one_larger_than_the_remembered_count(context) -> None:
"""Relies on the context members: -
- response_count
- remembered_response_count"""
assert context.failed is False
assert hasattr(context, "response_count")
assert hasattr(context, "remembered_response_count")

assert context.response_count == context.remembered_response_count + 1


@then( # pylint: disable=not-callable
"the length of the list in the response should be {count:d}"
)
Expand Down

0 comments on commit e29b03e

Please sign in to comment.