11import os
22
33from RequestsLibrary import RequestsLibrary
4- from utests import mock
5-
64from utests import SCRIPT_DIR
5+ from utests import mock
76
87
98def build_mocked_session_common_request (alias = 'alias' , url = 'http://mocking.rules' ,
@@ -23,6 +22,16 @@ def test_common_request_file_descriptor_closing():
2322 assert f .closed is True
2423
2524
25+ def test_common_request_files_descriptor_closing_when_passed_as_files_param ():
26+ session , m_common_request = build_mocked_session_common_request ()
27+ with open (os .path .join (SCRIPT_DIR , '../atests/randombytes.bin' ), 'rb' ) as f1 :
28+ with open (os .path .join (SCRIPT_DIR , '../atests/data.json' ), 'rb' ) as f2 :
29+ m_common_request ('get' , session ,
30+ 'http://mocking.rules' , files = {'randombytes' : f1 , 'data' : f2 })
31+ assert f1 .closed is True
32+ assert f2 .closed is True
33+
34+
2635def test_common_request_verify_override_true ():
2736 session , m_common_request = build_mocked_session_common_request (verify = False )
2837 m_common_request ('get' , session , '/' , verify = True )
@@ -68,22 +77,26 @@ def test_common_request_with_cookies_default_only():
6877 m_common_request ('get' , session , '/' )
6978 session .get .assert_called_with ('http://mocking.rules/' , timeout = None , cookies = {'a' : 1 , 'b' : 2 })
7079
80+
7181def test_common_request_with_float_timeout ():
7282 session , m_common_request = build_mocked_session_common_request (timeout = 123.4 )
7383 m_common_request ('get' , session , '/' )
7484 session .get .assert_called_with ('http://mocking.rules/' , timeout = 123.4 , cookies = {})
7585
86+
7687def test_common_request_with_float_timeout_override ():
7788 session , m_common_request = build_mocked_session_common_request (timeout = None )
7889 m_common_request ('get' , session , '/' , timeout = 123.4 )
7990 session .get .assert_called_with ('http://mocking.rules/' , timeout = 123.4 , cookies = {})
8091
92+
8193def test_common_request_with_touple_timeout ():
8294 session , m_common_request = build_mocked_session_common_request (timeout = (123.4 , 432.1 ))
8395 m_common_request ('get' , session , '/' )
8496 session .get .assert_called_with ('http://mocking.rules/' , timeout = (123.4 , 432.1 ), cookies = {})
8597
98+
8699def test_common_request_with_touple_timeout_override ():
87100 session , m_common_request = build_mocked_session_common_request (timeout = None )
88101 m_common_request ('get' , session , '/' , timeout = (123.4 , 432.1 ))
89- session .get .assert_called_with ('http://mocking.rules/' , timeout = (123.4 , 432.1 ), cookies = {})
102+ session .get .assert_called_with ('http://mocking.rules/' , timeout = (123.4 , 432.1 ), cookies = {})
0 commit comments