nsigustavo / ludibrio

Platform for test doubles in Python (mocks, stubs, Spy, and dummies)
113 stars 15 forks source link

Weird "Stub Object received unexpected call" exception #2

Closed ulrichb closed 13 years ago

ulrichb commented 14 years ago
def create_faked_https_connection(status):
    with ludibrio.Stub() as HTTPSConnection:
        server = HTTPSConnection(ludibrio.any)
        server.request(ludibrio.any, ludibrio.any, ludibrio.any, ludibrio.any) >> None
        resp = server.getresponse()
        resp.status >> status
        resp.reason >> '<reason>'
        resp.getheader('Location', None) >> '<file_url>'
        server.close()
    return HTTPSConnection

httplib.HTTPSConnection = create_faked_https_connection(201)

server = httplib.HTTPSConnection('')
server.request('POST', '', '', '')
resp = server.getresponse()
server.close()

if resp.status == 201:
    location = resp.getheader('Location', None)
else:
    location = None
aaa = (resp.status, resp.reason, location)

## when I set __last_property_called__ to Non the execption dissapears
#httplib.HTTPSConnection.__last_property_called__ = None

server = httplib.HTTPSConnection('')

In the last line I get: "AttributeError: Stub Object received unexpected call. reason('')"

As I said in the code, the exception disappears, when I use httplib.HTTPSConnection.last_property_called = None before creating the second instance

nsigustavo commented 13 years ago
with Stub() as resp_stub:
    resp.status >> status
    resp.reason >> '<reason>'
    resp.getheader('Location', None) >> '<file_url>'

with Stub() as HTTPSConnection:
    server = HTTPSConnection(any)
    server.request(any, any, any, any) >> None
    server.getresponse() >> resp_stub
    server.close()