Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

received but no interaction registered #73

Open
DannyCork opened this issue Oct 3, 2019 · 8 comments
Open

received but no interaction registered #73

DannyCork opened this issue Oct 3, 2019 · 8 comments

Comments

@DannyCork
Copy link

DannyCork commented Oct 3, 2019

I'm having an issue when attempting to make a request to the mock server. The mock server returns a 500 status code and a message 'received but no interaction registered'

My code looks like this:

import atexit
from pactman import Consumer, Provider
import requests

pact = Consumer('Consumer').has_pact_with(Provider('Provider'), use_mocking_server=True)
pact.start_mocking()
print('server on {}'.format(pact.uri))
atexit.register(pact.stop_mocking)


def testabc():
    path = '/test/123'
    pact.given(
        'blah'
    ).upon_receiving(
        'a GET request'
    ).with_request(
        method='GET',
        path='/test/123'
    ).will_respond_with(200, body={'status': 'FAILED'})

    response = requests.get(pact.uri+path)
    print(response.status_code)
    print(response.text)
    assert (response.status_code == 200)

I then run it using

$pytest test2.py

and get

Loading pacts from None
rootdir: /home/xxxx/xxx/xxxx-xxxx-xxxx/tests/contract_tests
plugins: pactman-2.25.0
collecting ... server on http://localhost:8155
collected 1 item                                                                                                                                                                                                  

test2.py::testabc 500
Request at /test/123 received but no interaction registered
FAILED

==================================================================================================== FAILURES =====================================================================================================
_____________________________________________________________________________________________________ testabc _____________________________________________________________________________________________________

    def testabc():
        path = '/test/123'
        pact.given(
            'blah'
        ).upon_receiving(
            'a GET request'
        ).with_request(
            method='GET',
            path='/test/123'
        ).will_respond_with(200, body={'status': 'FAILED'})
        response = requests.get(pact.uri+path)
        print(response.status_code)
        print(response.text)
>       assert (response.status_code == 200)
E       assert 500 == 200
E         -500
E         +200

test2.py:24: AssertionError

I have no additional code. My understanding is that pact provides the mocking, is this correct?

Any help appreciated. Thanks.

@r1chardj0n3s
Copy link
Collaborator

Sorry for the delay, Danny. Is this still an issue?

@Mukheem
Copy link

Mukheem commented Mar 25, 2020

Hello @r1chardj0n3s ,

This is still an issue which is observed for my code.
`import atexit
import unittest
import requests
from pactman import Consumer, Provider, Term, Like
from pactman.verifier.pytest_plugin import pact_verifier
pact = Consumer('ConsumerPOC').has_pact_with(Provider('Provider'),
use_mocking_server=True, pact_dir="C:\Users\*****\PycharmProjects\pact-python-master")
pact.start_mocking()
atexit.register(pact.stop_mocking)

class GetUserInfoContract(unittest.TestCase):

def test_generate_pact_from_consumer_end(self):
    # Setting up Expected Response
    expected = {'skip': 0, 'limit': 150}
    # Simulating an Real HTTP Server
    pact.given(
        'User ML exists and is not an administrator'
    ).upon_receiving(
        'a request for ML'
    ).with_request(
        method='GET',
        path='/api',
    ).will_respond_with(200, body=expected)

    
    with pact:
        result = requests.get(pact.uri + '/api')

    self.assertEqual(result.json(), expected)`

When the above code is run in debug mode, I found the error 'Received but no interaction registered'. I executed requests.get(pact.uri + '/api') explicitly during debugging and then I got to see this issue

When it is run in a single shot I am seeing below error.
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8155): Max retries exceeded with url: /api (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x04595310>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))

Any help is appreciated !!!

Thanks.

@reecetech reecetech deleted a comment Apr 10, 2020
@r1chardj0n3s
Copy link
Collaborator

"No connection could be made because the target machine actively refused it" looks like some sort of firewall configuration issue?

@Mukheem
Copy link

Mukheem commented Apr 10, 2020

But @r1chardj0n3s , If I use the below code also I am able to generate PACT.

pact = Consumer('ConsumerPOC').has_pact_with(Provider('Provider'),
use_mocking_server=False, pact_dir="C:\Users\*****\PycharmProjects\pact-python-master")

# pact.start_mocking()
# atexit.register(pact.stop_mocking)

Observe, I have commented the lines Start server and Stop server also by giving the flag value use_mocking_server=False

Then what is the actual need of previous code where in we are starting and stopping the mock server ??

@reecetech reecetech deleted a comment Apr 10, 2020
@r1chardj0n3s
Copy link
Collaborator

Yep! You don't need to run a mocking server to get the benefits of pact mocking - it's included mostly for legacy and edge case needs.

@Mukheem
Copy link

Mukheem commented Apr 10, 2020

Can you help me in understanding what do you mean by edge case needs... !!!

Any Example which can help me understand the concept more clear.

@reecetech reecetech deleted a comment Apr 10, 2020
@r1chardj0n3s
Copy link
Collaborator

Sorry, I can't actually think of one right now. If you don't need it, then don't use it.

@Mukheem
Copy link

Mukheem commented Apr 10, 2020

Okay @r1chardj0n3s .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants