pact -python for QA Team

580 views Asked by At

i am trying to setup pact python project locally and facing issues. it would be great if you help me on these issues

It seems we have to use localhost:1234 from consumer side ? . Can we use real service in place of mocking service ? If I use localhost:1234 , pact was generated but if i use real service ,then error is coming up So my question is do we need to always use Mock service ((localhost:1234) when we creating pacts from consumer side

2nd issue : i am from QA Team and thinking that pacts should be written by DEV team not QA team . is my assumption correct ? if yes, how these pacts will help QA Team ?

consumer.py

    import requests
    def callAPI(self,inputString,Url):
    respone = requests.get(url+inputString).status_code

test_consumer.py:

 pact = Consumer ( 'consumer' ).has_pact_with ( Provider ( 'provider' ) )
      pact.start_service ()
      atexit.register ( pact.stop_service )


      def test_callAPI (self):
      url = 'http://localhost:1234'

      pact.given ( 'sending user name to Url'
                 ).upon_receiving (
        'once i get the respone from service'
      ).with_request (
        'get', '/' ).will_respond_with ( 200)

     with pact:
        result = callAPI (url)
        self.assertEqual ( result['status_code'], 200 )

Thank you in Advance,

1

There are 1 answers

0
Matthew Fellows On BEST ANSWER

Yes, your code must hit the mock server else we can't be sure what you're expecting is actually true. Contract testing uses this to guarantee it's requirements on a provider.

You can also tell Pact to use any port, that's just the default.

should devs write them ... how will it help the QA team?

Well the short answer is yes, they really should be written by those writing the code. Is that a bad thing? As a QA I would imagine this makes your job easier as quality is automatically higher and you can focus on more important activities instead of writing automation tests.