https://pact.io logo
Join Slack
Powered by
# pact-python
  • j

    Jayesh Guru

    02/08/2022, 3:47 PM
    Hello Pact team, I am getting error for hardcoded token value in
    Authorization: Bearer <hardcode token>
    in verification step in Buildkite pipeline before publishing pact to the pact-broker, below are the steps in our BK pipeline 1. Run consumer Contract Test and upload pact.json file to the artifacts 2. Download pact.json file 3. Verify pact with Provider 4. Publish pacts to the pact-broker Getting below error for invalid authorization as hardcoded token was passed
    Copy code
    Verifying a pact between cmedia-distribute-api and vmedia-mats-app
      Given get schema tag enums
        return schema tags
          with GET /metadata/schema-tag-enums
            returns a response which
              has status code 200 (FAILED - 1)
              has a matching body (FAILED - 2)
    Copy code
    Failure/Error: expect(response_status).to eql expected_response_status
           expected: 200
                got: 401
           (compared using eql?)
         # /pact/bin/pact:15:in `<top (required)>'
    Copy code
    Failure/Error: expect(response_body).to match_term expected_response_body, diff_options, example
           Actual: {"title":"Unauthorized","message":"401 Unauthorized: Invalid token: Cannot extract header,payload and signature","mats_error_code":1001}
           Diff
           --------------------------------------
           Key: - is expected 
                + is actual
    m
    • 2
    • 41
  • a

    Antonio Gámiz Delgado

    02/14/2022, 9:26 AM
    Hi! Does anyone know where the documentation for the body of the POST request of the provider setup url parameter is? I get the following body:
    Copy code
    {
      "consumer": "Consumer",
      "state": "User exists and has resources",
      "states": [
        "User exists and has resources"
      ],
      "params": {}
    }
    m
    u
    • 3
    • 4
  • m

    Matt (pactflow.io / pact-js / pact-go)

    02/16/2022, 12:07 PM
    Positive that
    settings.PACT_CONSUMER_NAME
    (and the provider one) is defined?
    u
    • 2
    • 5
  • j

    Jayesh Guru

    02/16/2022, 1:40 PM
    Hello Pact Team, I am getting connection refused error for
    localhost:1234
    while starting the pact service
    pact.start_service()
    in conftest.py. FYI, it is working fine in my local but failing in Buildkite Pipeline
    m
    m
    • 3
    • 4
  • b

    Beth (pactflow.io/Pact Broker/pact-ruby)

    02/17/2022, 10:50 PM
    Can you read this? https://docs.pact.io/consumer#only-make-assertions-about-things-that-will-affect-the-consumer-if-they-change
    j
    • 2
    • 1
  • c

    Caíque Coelho

    02/20/2022, 6:49 PM
    Hello everyone, I’m trying to use Verifier from pact-python in my Python Provider Api, but I’m getting failed responses in my verification. I think my problem is with Authentication, because I need to pass an Authorization Token in my request header. I’m already doing that passing the arg
    custom_provider_headers
    to my
    verifier.verify_with_broker
    but I still getting failures verifications. Someone can help me? I was wandering if there is any way to see the current response from the verification, because I only received a generic return like
    has status code 200 (FAILED - 1)
    there is any wait to see the actual status code return and the body response. I think if I can see the actual return will be more easy to understand what I’m doing wrong. I’m putting all my code in this thread, thank you all!
    m
    • 2
    • 10
  • y

    Yumi

    03/01/2022, 8:20 AM
    Hi, when using pact-verifier command with --custom-provider-header, I want to check the real header when request is replayed. I got a pact.log file after replay, however there is no custom header in it. It's like:
    Copy code
    I, [2022-03-01T16:05:12.110368 #6736]  INFO -- : Sending PUT request to path: "/api/cartItems" with headers: {"CONTENT_TYPE"=>"application/json", "HTTP_X_PACT_ORIGINAL_HEADER_NAMES"=>"Content-Type"}, see debug logs for body
    D, [2022-03-01T16:05:12.113360 #6736] DEBUG -- : body :[{"duration":0,"id":"c3c46c8ccd254b32bfa52ba84aafa371","number":1}]
    I, [2022-03-01T16:05:15.427349 #6736]  INFO -- : Received response with status: 200, headers: {"P3p"=>"CP=CAO PSA OUR", "Bluewareguid"=>"7b0774ea1ea787f7", "X-Blueware-App-Data"=>"Olx7QXtkY0UQancBBFEGGAsAJhgCCisNIA51JUI0PDgGcD0EHhw6FQ0bMD5hMyofbmkjZz0cMQsYGhwNBBMxPmFyciZnEnx0TRFiRFpMeVtRUHZVfGVqRwd+d3oPRj4GRkxiG1FJdVYrM2sTU3FtYQcEcDc=", "Content-Type"=>"application/json", "Date"=>"Tue, 01 Mar 2022 08:05:12 GMT", "Cache-Control"=>"no-cache, no-store, max-age=0, must-revalidate", "Pragma"=>"no-cache", "Expires"=>"0", "X-Xss-Protection"=>"1 ; mode=block", "Referrer-Policy"=>"no-referrer", "Vary"=>"Origin\nAccess-Control-Request-Method\nAccess-Control-Request-Headers", "Strict-Transport-Security"=>"max-age=16000000; includeSubDomains; preload;", "Content-Length"=>"79"}, see debug logs for body
    D, [2022-03-01T16:05:15.430341 #6736] DEBUG -- : body: {"state":"OK","body":null,"requestId":"reqId-171d3c0265906198b4f02-b83abbaa-1"}
    What I use to verify is like:
    Copy code
    pact-verifier --log-dir=F:\code\pact-python-master-1227\consumer\mop\pact_logs --provider-base-url=<https://baseurl.cn> --pact-ur
    l=F:\code\pact-python-master-1227\consumer\mop\contract_files\ECS\ECS-OP_EditCaterProduct.json --custom-provider-header=Cookie:CMECLOUDTOKEN=3a8c6ccb407e48bb8857535bc23cba37
    I'm wondering if there is a log that I can check when the request is replayed, it does request with what I provide in the custom-provider-header?
    y
    • 2
    • 2
  • a

    Agustina BOSSO

    03/01/2022, 3:03 PM
    Copy code
    agustina.bosso@Agustinas-MBP in ~/Repos/pact-python/examples/consumer (master) > pytest --run-broker True --publish-pact 1
    
    ImportError while loading conftest '/Users/agustina.bosso/Repos/pact-python/examples/consumer/conftest.py'.
    conftest.py:2: in <module>
        from testcontainers.compose import DockerCompose
    E   ImportError: No module named testcontainers.compose
    m
    • 2
    • 7
  • m

    Mike Geeves

    03/02/2022, 1:55 PM
    Tiny addition to examples README, missing pip install for the consumer, which is there for the provider examples
    🙌 1
    y
    • 2
    • 9
  • s

    Sandeep

    03/03/2022, 11:21 AM
    Hi, Had a basic query. How can I capture the comparison result when verifying a pact.
    Copy code
    verifier = Verifier(provider='UserService', provider_base_url=PACT_URL)
    output, logs = verifier.verify_pacts('./userserviceclient-userservice.json', log_dir='/tmp/logs/, log_level='DEBUG')
    For example: if the status code comparison fails, I would like to append it result to my test report
    m
    • 2
    • 3
  • e

    Elliott Murray

    03/06/2022, 3:01 PM
    Had had the same idea! More I'm sure we can do with this
    👍 1
    m
    • 2
    • 3
  • j

    json

    03/07/2022, 3:26 PM
    Hey folks! I've been sort of just dipping my toe into the pact-python examples and was wondering why the pact fixture is registering stop_service with atexit and using a fixture to call stop_service after the test session is done? Isn't this redundant?
    m
    • 2
    • 18
  • j

    json

    03/07/2022, 9:38 PM
    I'm sure I'm not the first person who's had trouble getting pydantic models to work with pact, but I'm having a hard time googling for answers to this, so I appreciate any tips 🙂
    m
    • 2
    • 1
  • j

    Joachim David

    03/14/2022, 12:31 PM
    Hello guys, I’m new at using pact-python and I’m trying to write a test for an application which is both a provider and a consumer. How do I write the tests? Will I try to use the pact server as a mocking server for the consumer part or do I use another library which can server as the mocking server (In that case I will have to write two tests, one which tests the providing part of the application and one which tests the consuming part of the application). In which of the two ways should I write the tests?
    m
    • 2
    • 1
  • u

    Uzumaki

    03/19/2022, 3:01 PM
    anyone here ever set up a graphql django mock provider to verify graphql consumer pacts with before? (actually I don’t think it even matters if it’s graphql. It’s really just about having some local test server spin up for the provider during the test) django is pretty annoying with this stuff
    • 1
    • 1
  • a

    Abhi Nandan

    03/28/2022, 5:26 AM
    Hi, we have a polyglot scenario, where the consumer service is written in scala and the provider is written in python. We are able to publish the contract to the Pact Broker, however, on the provider side when we are trying to run the provider tests, it is throwing a
    403
    error. We are using the following command on the provider side
    Copy code
    pipenv run pact-verifier --provider-base-url=<http://localhost:8000> \
      --pact-url="<server_base_url>/pacts/provider/<provider>/consumer/<consumer>/latest" \
      --provider-app-version $VERSION \
      --pact-broker-username <pact_broker_user_name> \
      --pact-broker-password <pact_broker_pwd> \
      --publish-verification-results
    Provider application is running in docker container on
    port 8000
    . The above command is working fine from the local dev system, however it fails from our CI (GitLab), with the following error -
    Copy code
    HTTP request failed: status=403 /usr/local/lib/python3.9/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-support-1.17.0/lib/pact/consumer_contract/pact_file.rb:73:in `block in get_remote_with_retry'
    on Pact Broker log found this -
    Copy code
    WARN -- : attack prevented by Rack::protection::IPSpoofing
    nginx log shows the following -
    Copy code
    "GET /pacts/provider/<provider_name>/consumer/<consumer_name>/latest HTTP/1.1" 403 9 "-" "Ruby" "<http://xx.xxx.xx.xxx|xx.xxx.xx.xxx>"
    can anyone please help us with what is wrong here?
    b
    • 2
    • 24
  • u

    Uzumaki

    03/30/2022, 2:12 PM
    Hey guys, how do I stop log files from being created during verification tests? I would have assumed not having any logging arguments passed in would not create it by default
    m
    • 2
    • 7
  • y

    Yumi

    04/01/2022, 8:21 AM
    Hi, we have a API with GET method, and the params contains Chinese character.I'm using pact-python to write consumer test like the following:
    Copy code
    def test_get_metadata(self):
           
            expected = {
                "body": [
                    {
                        
                        "name": "可用区1",      
                        "status": "ONLINE",
                        "visible": True
                    }
                ],
                "requestId": Like("abc"),
                "state": "OK"
            }
    
            # 定义响应头
            headers = {
                "Content-Type": "application/json"
            }
            query = {"name":"可用区1","signature":"asdf"}
            
            (self.pact
             .upon_receiving('查询有效可用区信息')
             .with_request(
                method='GET',
                path=self.PATH,
                query=query,
                headers=headers
            ).will_respond_with(200, headers, expected))
    
            with self.pact:
                resp = requests.get("<http://localhost>:{}{}".format(MOCK_SERVER_PORT,self.PATH),
                                    params=query,headers = headers)
                print('*******************************')
                print(resp.json())
            self.assertEqual(resp.json(), get_generated_values(expected))
    when using pact-verifier command to verify the json file. It shows that the value of "name" in query parameters is urlencoded as "%E5%8F%AF%E7%94%A8%E5%8C%BA1". however when I change the query from list to string like this :
    Copy code
    query = "name=可用区1&signature=asdf"
    when using pact-varifier command,it shows:
    Copy code
    URI::InvalidURIError:
           URI must be ascii only "/api/change?name=\u{53ef}\u{7528}\u{533a}1&signature=asdf"
         # D:/python/Lib/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/uri/rfc3986_parser.rb:20:in `split'
         # D:/python/Lib/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/uri/rfc3986_parser.rb:72:in `parse'
         # D:/python/Lib/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/uri/common.rb:226:in `parse'
    Is there a way to deal with this kind of situation?I've found a issue https://github.com/pact-foundation/pact-provider-proxy/issues/6 but it seems different from @Beth (pactflow.io/Pact Broker/pact-ruby) said.I thought hash form will not be encoded🥲
    b
    • 2
    • 2
  • m

    Matt (pactflow.io / pact-js / pact-go)

    04/05/2022, 3:23 AM
    See also the CI/CD workshop in howtolearn
    ✅ 1
    🙌 1
    c
    • 2
    • 2
  • a

    Ashish

    04/07/2022, 6:48 PM
    Hello There, I am planning to use pact-python library for our APIs which are written in python. There has not been any update in changelog for the last one year.. So, i am assuming there is no active work happening on this. I am interested in knowing if Pending/WIP pacts features are supported by pact-python.
    y
    • 2
    • 3
  • g

    GitHub

    04/10/2022, 11:17 AM
    #296 ci: added poetry lock file Pull request opened by elliottmurray pact-foundation/pact-python GitHub Actions: build (3.9) GitHub Actions: build (3.8) GitHub Actions: build (3.7) GitHub Actions: build (3.9) GitHub Actions: build (3.8) GitHub Actions: build (3.7) ✅ 1 other check has passed 1/7 successful checks
    🤔 1
    e
    • 2
    • 1
  • c

    Caíque Coelho

    04/14/2022, 5:37 PM
    Hello everyone, how are you? I’ve a problem using Like match in my mock response. I’ve a mock body response in my consumer with an array with 3 elements inside, like this
    Like({array: [1, 2, 3]})
    , but when I’m running this contract in my provider verification the provider return an array with 6 elements and the validation fail. Is there any way to ignore the array length and just verify if the response in my provider contains an array with length greater than 0 in the body?
    m
    • 2
    • 6
  • j

    James Fraser

    04/18/2022, 9:22 AM
    Hey folks 👋 our provider framework uses the Pact-Python library, we've started seeing some builds passing with the Pending Pact feature - we'd currently like these to fail so the build fails As far as I can tell the Pact Pending feature is meant to be off by default and I can't see anywhere that I'm enabling it, can anyone confirm if that's the case please? Or if not, how I can disable it
    m
    • 2
    • 8
  • h

    Himanshu Pandey

    04/25/2022, 5:35 AM
    Hello folks, I wanted to have provider setup for pact-python? any refrences to that and what default port it uses? wanted to understand and setup that? Not sure how to setup pact provider? Can you please help me with refrence how we can setup this?
    m
    y
    • 3
    • 19
  • a

    Ashish

    04/26/2022, 9:07 PM
    Hi There- I am trying to follow the steps listed here - https://github.com/pact-foundation/pact-python/tree/master/examples . I was able to do successful publishing for pacts to the broker from the consumer end. However while running provider tests, i am seeing the below errors-
    Copy code
    Creating /Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/pact-python.egg-link (link to .)
        Adding pact-python 1.5.2 to easy-install.pth file
        Installing pact-verifier script to /Users/ashishgoyal/gitrepos/pact-python/venv_pact/bin
        
        Installed /Users/ashishgoyal/gitrepos/pact-python
        Traceback (most recent call last):
          File "<string>", line 2, in <module>
          File "<pip-setuptools-caller>", line 34, in <module>
          File "/Users/ashishgoyal/gitrepos/pact-python/setup.py", line 212, in <module>
            setup(
          File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/__init__.py", line 87, in setup
            return distutils.core.setup(**attrs)
          File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 148, in setup
            return run_commands(dist)
          File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 163, in run_commands
            dist.run_commands()
          File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
            self.run_command(cmd)
          File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/dist.py", line 1214, in run_command
            super().run_command(command)
          File "/Users/ashishgoyal/gitrepos/pact-python/venv_pact/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
            cmd_obj.run()
          File "/Users/ashishgoyal/gitrepos/pact-python/setup.py", line 64, in run
            install_ruby_app(package_bin_path, download_bin_path=None)
          File "/Users/ashishgoyal/gitrepos/pact-python/setup.py", line 118, in install_ruby_app
            raise RuntimeError('Could not find {} binary.'.format(path))
        RuntimeError: Could not find /Users/ashishgoyal/gitrepos/pact-python/pact/bin/pact-1.88.83-osx.tar.gz binary.
    y
    m
    • 3
    • 5
  • g

    GitHub

    04/27/2022, 5:00 PM
    #227 Docs: Update docs to reflect usage for native Python Pull request merged by YOU54F pact-foundation/pact-python
    y
    • 2
    • 1
  • j

    json

    05/19/2022, 8:49 PM
    Hey there! I was just looking at the pact-python examples for provider verification and just realized that it doesn't look like there's any way to specify what version of the consumer I want to pull the pact for to test. Am I missing it somewhere? Thank you for the help 🙂
    m
    • 2
    • 3
  • j

    json

    05/19/2022, 9:02 PM
    Is maybe the only way to do it to use the pact-verify CLI like in this example and specify the specific URL of the pact you want to verify?
    m
    s
    • 3
    • 8
  • p

    Pooja Kunder

    06/01/2022, 2:53 AM
    Hi Team, I am completely new to PACT and started working on already available framework in my current company but I am getting error below when we import ,as its saying that cant find reference verifier in spite of having PACTMAN installed from pactman.verifier.broker_pact import BrokerPacts, pact_id, BrokerPact Could you please help me to get rid of this error ?
    m
    • 2
    • 25
  • j

    json

    06/16/2022, 3:01 PM
    Hey all! I've been prototyping a process for the pact provider verification for my team's FastAPI service, and my team is pretty excited about it, but our architect is worried that it's a little complicated and introduces too much new stuff and the average developer will have a hard time understanding how it works and how to implement it (which is valid and I pretty much agree with him), so I thought I'd hop on here and see if anyone had any tips or thoughts about best practices for implementing the pact provider verifier in FastAPI. So first of all, the way I have it designed now is that inside the project repository's
    ./tests
    directory I added a
    pact_provider
    directory to projects which are pact providers and a
    pact_consumer
    directory to projects that are pact consumers, with the idea being that the pytest tests which generate the contract live inside the
    pact_consumer
    directory and the start-up logic for running the server in pact-verification mode lives in
    pact_provider
    . (As best as I can tell, FastAPI needs a separate starting point to run the provider server in "pact-mode" because it has to add an extra router to define the
    "/_pact/provider_states"
    endpoint, via this example). We use poetry to manage dependencies and run the code, so in our
    pyproject.toml
    alongside the
    start = "<app_name>.run:start"
    script, I'm defining
    start_pact_verifier = "tests.pact_provider.setup:run"
    . So in order to implement this solution, a developer has to add: • the
    start_pact_verifier
    script line to their
    pyproject.toml
    • the
    ./tests/pact_provider/setup.py
    file with a run method which imports the main application's
    FastAPI
    instance and adds the pact states router to it • the new pact states router itself, including the mapping of state strings to setup functions • plus the setup functions themselves It just seems like a lot to ask a developer to understand, and I was wondering if anyone had any tips to simplify it. Is there a way I could maybe utilize an internal poetry library to hide a lot of this boiler-plate away from the developer trying to implement this? Or maybe just a better design pattern I could be taking advantage of? My architect recommended moving the
    run
    function to the
    <app_name>/run.py
    module, but that seems like a pretty small step.
    m
    • 2
    • 12
1234567Latest