SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 86 in 18 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import requests_mock
  3.  
  4.  
  5. def real(url):
  6.     return requests.get(url).status_code
  7.  
  8.  
  9. def mock(url, mock_code):
  10.     with requests_mock.Mocker() as m:
  11.         m.register_uri('GET', url, status_code=mock_code)
  12.         response_mock = requests.get(url).status_code
  13.         return response_mock
  14.  
  15.  
  16. def test_real_and_mock():
  17.     url = 'http://test.com/'
  18.     mock_code = '500'
  19.  
  20.     response_real = real(url)
  21.     response_mock = mock(url, mock_code)
  22.  
  23.     assert response_mock != response_real
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top