Repository navigation
Expand file tree
/
Copy pathtest_unit_put_get.py
More file actions
71 lines (62 loc) · 1.92 KB
/
Copy pathtest_unit_put_get.py
File metadata and controls
71 lines (62 loc) · 1.92 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
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2019 Snowflake Computing Inc. All right reserved.
import pytest
from os import path, chmod
from snowflake.connector.compat import PY2
from snowflake.connector.errors import Error
from snowflake.connector.file_transfer_agent import SnowflakeFileTransferAgent
from snowflake.connector.compat import IS_WINDOWS
if PY2:
from mock import MagicMock
else:
from unittest.mock import MagicMock
@pytest.mark.skipif(IS_WINDOWS, reason='permission model is different')
def test_put_error(tmpdir):
"""
Test for raise_put_get_error flag in SnowflakeFileTransferAgent
"""
tmp_dir = str(tmpdir.mkdir('putfiledir'))
file1 = path.join(tmp_dir, 'file1')
remote_location = path.join(tmp_dir, 'remote_loc')
with open(file1, 'w') as f:
f.write('test1')
# nobody can read now.
chmod(file1, 0o000)
con = MagicMock()
cursor = con.cursor()
cursor.errorhandler = Error.default_errorhandler
query = 'PUT something'
ret = {
'data': {
'command': 'UPLOAD',
'autoCompress': False,
'src_locations': [file1],
'sourceCompression': 'none',
'stageInfo': {
'location': remote_location,
'locationType': 'LOCAL_FS',
'path': 'remote_loc',
}
},
'success': True,
}
# no error is raised
sf_file_transfer_agent = SnowflakeFileTransferAgent(
cursor,
query,
ret,
raise_put_get_error=False)
sf_file_transfer_agent.execute()
sf_file_transfer_agent.result()
# Permission error should be raised
sf_file_transfer_agent = SnowflakeFileTransferAgent(
cursor,
query,
ret,
raise_put_get_error=True)
sf_file_transfer_agent.execute()
with pytest.raises(Exception):
sf_file_transfer_agent.result()
chmod(file1, 0o700)