def test_get_product(): #Get the expected response from petstore api expected = "eef74ecc-38b9-493f-a854-a65c64846b32" body = files = [('image', ('Capture.PNG', open('../Capture.PNG', 'rb'), 'application/octet-stream'))] #Create pact file given=Description, uponReceiving=the state the provider is in, Request=Expected Request, Response=The expected response (pact.given('the image upload service is available').upon_receiving( 'a successful insert into the problem db').with_request( 'POST', '/image/v1/Problem/1', body).will_respond_with(200, body=expected)) #In the pact context with pact: #create Petstore consumer object and set endpoint to pact VM (defaults to actual if uri not specified) consumer = PetstoreConsumer(uri=pact.uri) print(pact.uri) #call get pet by id 1 pet = consumer.get_pet(1) verifier = Verifier(provider="Petstore Provider Spring", provider_base_url="http://localhost:8080") #pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pacts/petstore_consumer_python-petstore_provider_spring.json output, log = verifier.verify_pacts( "./pacts/petstore_consumer_python-petstore_provider_spring.json") print(log) assert output == 0
def test_get_user_non_admin(server): verifier = Verifier(provider='UserService', provider_base_url=PACT_URL) output, _ = verifier.verify_pacts('./userserviceclient-userservice.json', verbose=False, provider_states_setup_url="{}/_pact/provider_states".format(PACT_URL)) assert (output == 0)
def test_get_location(): verifier = Verifier(provider='LocationService', provider_base_url=PACT_URL) output, logs = verifier.verify_pacts( os.path.join(PACT_DIR, PACT_FILE), verbose=False, provider_states_setup_url="{}/_pact/provider_states".format(PACT_URL)) assert (output == 0)
def test_user_service_provider_against_pact(server): verifier = Verifier(provider="UserService", provider_base_url=PROVIDER_URL) # Rather than requesting the Pact interactions from the Pact Broker, this # will perform the verification based on the Pact file locally. # # Because there is no way of knowing the previous state of an interaction, # if it has been successful in the past (since this is what the Pact Broker # is for), if the verification of an interaction fails then the success # result will be != 0, and so the test will FAIL. output, _ = verifier.verify_pacts( "../pacts/userserviceclient-userservice.json", verbose=False, provider_states_setup_url="{}/_pact/provider_states".format(PROVIDER_URL), ) assert output == 0
def test_get_user_non_admin(provider): print('verify our test') # pact_broker_username = "******", # pact_broker_password = "******" # # publish_verification_result = True # # providerVersion = "1.0.0" # pactBrokerUrl = "http://localhost" verifier = Verifier(provider='UserService', provider_base_url='http://localhost:1234') output, logs = verifier.verify_pacts( './userserviceclient-userservice.json') print(output) print(logs) assert (output == 0)