First time write unittest. Production code:
def get_session_token(organization_id):
endpoint = get_endpoint(organization_id)
response = requests.post(
endpoint + "/some/url/part",
data=json.dumps({
"Login": CONFIG[organization_id]["username"],
"Password": CONFIG[organization_id]["password"],
}),
headers={"Accept": "application/json"}
)
if response.status_code != 201:
log.error("filename.get_session_token(%r): couldn't auth: %r %r",
organization_id, response, response.text)
raise ValueError()
return response.json()
def member(organization_id):
session_key = get_session_token(organization_id)
(some other code...)
I need to test member. And I have test code:
@patch('requests.post')
def test_member(self, mock_post):
mock_post().status_code = 201
mock_response = mock_post("some/url", data=ANY,
headers={"Accept": "application/json"})
mock_response.status_code = 201
(some other code...)
Every time I run test, it always raises ValueError()(which is a 403 error)
How can I bypass that requests.post and just get a 201?
Thank you!