Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

test: add capability to specify service in client scenarios step #422

Merged
merged 11 commits into from
Jul 25, 2022

Conversation

Trinaa
Copy link
Collaborator

@Trinaa Trinaa commented Jul 20, 2022

Description

Add a new step type to the Contile contract tests, allowing for verification of the partner request history during scenario execution.

  • add capacity to specify either 'contile' or 'partner' service as request target in scenario step request
  • add support for Records content in scenario step response
  • add teardown which clears records of contile partner requests between tests
  • update README documentation

Issue(s)

CONSVC-1293

@Trinaa Trinaa requested a review from hackebrot July 20, 2022 17:35
@Trinaa Trinaa requested a review from a team as a code owner July 20, 2022 17:35
Copy link
Member

@hackebrot hackebrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Trinaa! 👋🏻

I've added my comments inline. This is looking really good already! 🚀

test-engineering/contract-tests/client/README.md Outdated Show resolved Hide resolved
test-engineering/contract-tests/client/README.md Outdated Show resolved Hide resolved
test-engineering/contract-tests/client/README.md Outdated Show resolved Hide resolved
@Trinaa Trinaa force-pushed the contract-tests-service-specification branch from 89450e7 to 6e5ad37 Compare July 22, 2022 01:36
@Trinaa Trinaa force-pushed the contract-tests-service-specification branch from 529afcf to ee72ac5 Compare July 22, 2022 17:55
@Trinaa Trinaa requested a review from hackebrot July 22, 2022 18:02
@Trinaa
Copy link
Collaborator Author

Trinaa commented Jul 22, 2022

@hackebrot ready for review again!

Copy link
Member

@hackebrot hackebrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Trinaa! 👋🏻

A few minor corrections and then we can merge this.

url: 'https://www.example.org/desktop_windows'
```

#### partner Service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### partner Service
#### Partner Service

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change applied: 8f3bea8


* To direct requests to the MTS service, set the `service` value of `request` to
`contile`
* The expected content for a '200 OK' response is a collection of Tiles.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The expected content for a '200 OK' response is a collection of Tiles.
* The expected content for a `200 OK` response is a collection of tiles.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change applied: 8f3bea8


* To direct requests to the partner service, set the `service` value of `request` to
`partner`
* The expected content for a '200 OK' response is a collection of Records.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The expected content for a '200 OK' response is a collection of Records.
* The expected content for a `200 OK` response is a collection of records.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change applied: 8f3bea8

url = f"{contile_host}{step.request.path}"
headers = {header.name: header.value for header in step.request.headers}
method: str = step.request.method
url: str = f"{hosts[step.request.service.value]}{step.request.path}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use the enums as keys, this won't need the .value attribute access.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change Applied: 32becfb


from models import Records, Scenario, Service, Tiles

SERVICE_MODEL: Dict[Service, Union[Type[Records], Type[Tiles]]] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use a type alias here for improved readability.

Suggested change
SERVICE_MODEL: Dict[Service, Union[Type[Records], Type[Tiles]]] = {
SERVICE_MODEL = Union[Type[Records], Type[Tiles]]
SERVICE_MODELS: Dict[Service, SERVICE_MODEL] = {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change applied: 433bcc4

# information and FastAPI model instances were created for them.
for scenario in config.contile_scenarios:
for i, step in enumerate(scenario.steps):

if step.response.status_code != 200:
continue

if not isinstance(step.response.content, Tiles):
expected_model: Union[Type[Records], Type[Tiles]] = SERVICE_MODEL.get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected_model: Union[Type[Records], Type[Tiles]] = SERVICE_MODEL.get(
expected_model: SERVICE_MODEL = SERVICE_MODELS.get(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change applied: 433bcc4

partner_host = hosts["partner"]

def clear_partner_records():
r: RequestsResponse = requests.delete(f"{partner_host}/records/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I'd expect flake8 to complain about the use of 1 character variable names. I think it used to do that. 😁

Copy link
Collaborator Author

@Trinaa Trinaa Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change Applied: 32becfb

I used the single character to stay consistent with the existing naming found in the test_contile method, but would actually prefer the full name request response. This comment makes me think I can take the liberty of changing it throughout.

Copy link
Member

@hackebrot hackebrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@Trinaa Trinaa merged commit 9d95f7e into main Jul 25, 2022
@Trinaa Trinaa deleted the contract-tests-service-specification branch July 25, 2022 17:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants