forked from tableau/server-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_regression_tests.py
More file actions
63 lines (46 loc) · 1.87 KB
/
test_regression_tests.py
File metadata and controls
63 lines (46 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import unittest
try:
from unittest import mock
except ImportError:
import mock
import tableauserverclient.server.request_factory as factory
from tableauserverclient.server.endpoint import Endpoint
from tableauserverclient.filesys_helpers import to_filename, make_download_path
class BugFix257(unittest.TestCase):
def test_empty_request_works(self):
result = factory.EmptyRequest().empty_req()
self.assertEqual(b'<tsRequest />', result)
class BugFix273(unittest.TestCase):
def test_binary_log_truncated(self):
class FakeResponse(object):
headers = {'Content-Type': 'application/octet-stream'}
content = b'\x1337' * 1000
status_code = 200
server_response = FakeResponse()
self.assertEqual(Endpoint._safe_to_log(server_response), '[Truncated File Contents]')
class FileSysHelpers(unittest.TestCase):
def test_to_filename(self):
invalid = [
"23brhafbjrjhkbbea.txt",
'a_b_C.txt',
'windows space.txt',
'abc#def.txt',
't@bL3A()',
]
valid = [
"23brhafbjrjhkbbea.txt",
'a_b_C.txt',
'windows space.txt',
'abcdef.txt',
'tbL3A',
]
self.assertTrue(all([(to_filename(i) == v) for i, v in zip(invalid, valid)]))
def test_make_download_path(self):
no_file_path = (None, 'file.ext')
has_file_path_folder = ('/root/folder/', 'file.ext')
has_file_path_file = ('out', 'file.ext')
self.assertEqual('file.ext', make_download_path(*no_file_path))
self.assertEqual('out.ext', make_download_path(*has_file_path_file))
with mock.patch('os.path.isdir') as mocked_isdir:
mocked_isdir.return_value = True
self.assertEqual('/root/folder/file.ext', make_download_path(*has_file_path_folder))