20 |
20 |
from wcs.qommon.http_request import HTTPRequest
|
21 |
21 |
from wcs.qommon.humantime import humanduration2seconds, seconds2humanduration
|
22 |
22 |
from wcs.qommon.misc import (
|
|
23 |
_http_request,
|
23 |
24 |
date_format,
|
24 |
25 |
ellipsize,
|
25 |
26 |
format_time,
|
... | ... | |
533 |
534 |
def test_uwsgi_spooler_import():
|
534 |
535 |
with pytest.raises(ImportError):
|
535 |
536 |
import wcs.qommon.spooler # noqa pylint: disable=unused-import
|
|
537 |
|
|
538 |
|
|
539 |
@mock.patch('requests.Session.request')
|
|
540 |
def test_http_request_global_settings(mock_request):
|
|
541 |
response = {'err': 0, 'data': []}
|
|
542 |
mock_json = mock.Mock(status_code=200)
|
|
543 |
mock_json.json.return_value = response
|
|
544 |
mock_request.return_value = mock_json
|
|
545 |
from django.conf import settings
|
|
546 |
|
|
547 |
response, status, data, auth_header = _http_request('https://example.com/')
|
|
548 |
mock_request.assert_called_once_with(
|
|
549 |
'GET', 'https://example.com/', cert=None, data=None, headers={}, proxies=None, timeout=28
|
|
550 |
)
|
|
551 |
assert status == 200
|
|
552 |
|
|
553 |
settings.REQUESTS_TIMEOUT = 42
|
|
554 |
mock_request.reset_mock()
|
|
555 |
response, status, data, auth_header = _http_request('https://example.com/')
|
|
556 |
mock_request.assert_called_once_with(
|
|
557 |
'GET', 'https://example.com/', cert=None, data=None, headers={}, proxies=None, timeout=42
|
|
558 |
)
|
|
559 |
assert status == 200
|
|
560 |
|
|
561 |
settings.REQUESTS_PROXIES = {
|
|
562 |
'http': 'http://10.10.1.10:3128',
|
|
563 |
'https': 'http://10.10.1.10:1080',
|
|
564 |
}
|
|
565 |
mock_request.reset_mock()
|
|
566 |
response, status, data, auth_header = _http_request('https://example.com/')
|
|
567 |
mock_request.assert_called_once_with(
|
|
568 |
'GET',
|
|
569 |
'https://example.com/',
|
|
570 |
cert=None,
|
|
571 |
data=None,
|
|
572 |
headers={},
|
|
573 |
proxies=settings.REQUESTS_PROXIES,
|
|
574 |
timeout=42,
|
|
575 |
)
|
|
576 |
assert status == 200
|
|
577 |
settings.REQUESTS_PROXIES = None
|
|
578 |
|
|
579 |
settings.REQUESTS_CERT = {
|
|
580 |
'https://example.com/ssl': '/path/client.pem',
|
|
581 |
}
|
|
582 |
mock_request.reset_mock()
|
|
583 |
response, status, data, auth_header = _http_request('https://example.com/ssl/')
|
|
584 |
mock_request.assert_called_once_with(
|
|
585 |
'GET',
|
|
586 |
'https://example.com/ssl/',
|
|
587 |
cert='/path/client.pem',
|
|
588 |
data=None,
|
|
589 |
headers={},
|
|
590 |
proxies=None,
|
|
591 |
timeout=42,
|
|
592 |
)
|
|
593 |
mock_request.reset_mock()
|
|
594 |
response, status, data, auth_header = _http_request('https://example.com/')
|
|
595 |
mock_request.assert_called_once_with(
|
|
596 |
'GET', 'https://example.com/', cert=None, data=None, headers={}, proxies=None, timeout=42
|
|
597 |
)
|