Skip to content

Conversation

@jamesbrunet
Copy link
Owner

@jamesbrunet jamesbrunet commented Jun 11, 2020

Status

READY

Description

In order to add __repr__ to CallHub, we need to get the admin username in the __init__ method, which we can do by a GET to /agents/ and then looking for the "owner" of the first agent. However, this seemingly minor change breaks the entire test infrastructure, because MagicMock can only be applied to a session AFTER it has been created, and if a web request is made in __init__ it cannot be mocked.

We can solve this by using requests_mock to mock web requests instead of MagicMock.

In order to add __repr__ to objects, we need to get the admin username
in the __init__ method, which we can do by a call to /agents/ and then
looking for the "owner" of the first agent. However, this seemingly minor
change breaks the entire test infrastructure, because MagicMock can
only be applied to a session AFTER it has been created, and if a web
request is made in __init__ it cannot be mocked.

We can solve this by using requests_mock to mock web requests!
@jamesbrunet
Copy link
Owner Author

jamesbrunet commented Jun 11, 2020

What an excellent idea. Approved.

Gives award to myself

@jamesbrunet jamesbrunet merged commit 4303a40 into master Jun 11, 2020
@jamesbrunet jamesbrunet deleted the requests_mock branch June 11, 2020 04:18
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

Successfully merging this pull request may close these issues.

2 participants