1
1
import os
2
2
3
3
from RequestsLibrary import RequestsLibrary
4
- from utests import mock
5
-
6
4
from utests import SCRIPT_DIR
5
+ from utests import mock
7
6
8
7
9
8
def build_mocked_session_common_request (alias = 'alias' , url = 'http://mocking.rules' ,
@@ -23,6 +22,16 @@ def test_common_request_file_descriptor_closing():
23
22
assert f .closed is True
24
23
25
24
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
+
26
35
def test_common_request_verify_override_true ():
27
36
session , m_common_request = build_mocked_session_common_request (verify = False )
28
37
m_common_request ('get' , session , '/' , verify = True )
@@ -68,22 +77,26 @@ def test_common_request_with_cookies_default_only():
68
77
m_common_request ('get' , session , '/' )
69
78
session .get .assert_called_with ('http://mocking.rules/' , timeout = None , cookies = {'a' : 1 , 'b' : 2 })
70
79
80
+
71
81
def test_common_request_with_float_timeout ():
72
82
session , m_common_request = build_mocked_session_common_request (timeout = 123.4 )
73
83
m_common_request ('get' , session , '/' )
74
84
session .get .assert_called_with ('http://mocking.rules/' , timeout = 123.4 , cookies = {})
75
85
86
+
76
87
def test_common_request_with_float_timeout_override ():
77
88
session , m_common_request = build_mocked_session_common_request (timeout = None )
78
89
m_common_request ('get' , session , '/' , timeout = 123.4 )
79
90
session .get .assert_called_with ('http://mocking.rules/' , timeout = 123.4 , cookies = {})
80
91
92
+
81
93
def test_common_request_with_touple_timeout ():
82
94
session , m_common_request = build_mocked_session_common_request (timeout = (123.4 , 432.1 ))
83
95
m_common_request ('get' , session , '/' )
84
96
session .get .assert_called_with ('http://mocking.rules/' , timeout = (123.4 , 432.1 ), cookies = {})
85
97
98
+
86
99
def test_common_request_with_touple_timeout_override ():
87
100
session , m_common_request = build_mocked_session_common_request (timeout = None )
88
101
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