Пример #1
0
 def test_verify_is_true_if_env_not_set(self, api_token):
     with patch("pythonanywhere.api.requests") as mock_requests:
         call_api("url", "post", foo="bar")
     args, kwargs = mock_requests.request.call_args
     assert kwargs["verify"] is True
Пример #2
0
 def test_passes_verify_from_environment(self, api_token, monkeypatch):
     monkeypatch.setenv("PYTHONANYWHERE_INSECURE_API", "true")
     with patch("pythonanywhere.api.requests") as mock_requests:
         call_api("url", "post", foo="bar")
     args, kwargs = mock_requests.request.call_args
     assert kwargs["verify"] is False
Пример #3
0
 def test_verify_is_true_if_env_not_set(self, api_token):
     with patch('pythonanywhere.api.requests') as mock_requests:
         call_api('url', 'post', foo='bar')
     args, kwargs = mock_requests.request.call_args
     assert kwargs["verify"] is True
Пример #4
0
 def test_raises_on_401(self, api_token, api_responses):
     url = "https://foo.com/"
     api_responses.add(responses.POST, url, status=401, body="nope")
     with pytest.raises(AuthenticationError) as e:
         call_api(url, "post")
     assert str(e.value) == "Authentication error 401 calling API: nope"
Пример #5
0
 def test_passes_verify_from_environment(self, api_token, monkeypatch):
     monkeypatch.setenv('PYTHONANYWHERE_INSECURE_API', 'true')
     with patch('pythonanywhere.api.requests') as mock_requests:
         call_api('url', 'post', foo='bar')
     args, kwargs = mock_requests.request.call_args
     assert kwargs["verify"] is False