Exemplo n.º 1
0
def test_user_service_provider_against_broker(server, broker_opts):
    verifier = Verifier(provider="UserService", provider_base_url=PROVIDER_URL)

    # Request all Pact(s) from the Pact Broker to verify this Provider against.
    # In the Pact Broker logs, this corresponds to the following entry:
    # PactBroker::Api::Resources::ProviderPactsForVerification -- Fetching pacts for verification by UserService -- {:provider_name=>"UserService", :params=>{}}
    success, logs = verifier.verify_with_broker(
        **broker_opts,
        verbose=True,
        provider_states_setup_url=f"{PROVIDER_URL}/_pact/provider_states",
        enable_pending=False,
    )
    # If publish_verification_results is set to True, the results will be
    # published to the Pact Broker.
    # In the Pact Broker logs, this corresponds to the following entry:
    #   PactBroker::Verifications::Service -- Creating verification 200 for \
    #   pact_version_sha=c8568cbb30d2e3933b2df4d6e1248b3d37f3be34 -- \
    #   {"success"=>true, "providerApplicationVersion"=>"3", "wip"=>false, \
    #   "pending"=>"true"}

    # Note:
    #  If "successful", then the return code here will be 0
    #  This can still be 0 and so PASS if a Pact verification FAILS, as long as
    #  it has not resulted in a REGRESSION of an already verified interaction.
    #  See https://docs.pact.io/pact_broker/advanced_topics/pending_pacts/ for
    #  more details.
    assert success == 0
Exemplo n.º 2
0
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
Exemplo n.º 3
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)
Exemplo n.º 4
0
def test_get_user_non_admin(default_opts):
    verifier = Verifier(provider='UserService', provider_base_url=PACT_URL)

    output, logs = verifier.verify_with_broker(
        **default_opts,
        verbose=True,
        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)
Exemplo n.º 6
0
    def setUpClass(cls):
        super().setUpClass()

        cls.verifier = Verifier(
            provider='lms',
            provider_base_url=cls.live_server_url,
        )
Exemplo n.º 7
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
Exemplo n.º 8
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)