How to set up an external host for a provider using pact python?

24 Views Asked by At

I need some help

I am trying to build a contract test for 2 backend services

Here's a high level overview of how it works

Main backend interacts with a specific_data service

So my backend is the consumer and the specific_data_service is the provider

When I send a PUT request to the endpoint /api/sepecific_data/{specific_uuid}/data then the backend calls the update_specific_data() function

The update_specific_data() function then sends a PUT request to the external specific_data service which is hosted externally, the base url being something like https://specific-data-service.run.app/

My question is, how do I set up my provider url within the consumer test?


If I set it like

pact = Consumer('specific-data-consumer-python').has_pact_with(Provider('specific-data-provider-python'), host_name='http://127.0.0.1', port=1234, pact_dir="./pacts", log_dir="./logs")

Then when I run

(pact
         .given('Data exists')
         .upon_receiving('a request for updating data')
         .with_request(method='put', path=f'/api/sepecific_data/{specific_uuid}/data', body=DATA_CHANGED)
         .will_respond_with(200, body=UPDATED_DATA))
    
    with pact:
            result = update_specific_data(args)
            assert result == expected

The request isn't actualy being intercepted and tries to call the actual external API


Is there a way to set my provider like?

pact = Consumer('specific-data-consumer-python').has_pact_with(Provider('specfic-data-provider-python'), host_name='https://specific-data-service.run.app', pact_dir="./pacts", log_dir="./logs")

Sorry for the super long text

I really hope someone can help me

I tried reading the documentation, checking stack overflow but no answer found

0

There are 0 best solutions below