Skip to content

Commit

Permalink
Updated test_files
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMcGrath committed May 15, 2024
1 parent 30bf0f1 commit 4f8625e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
35 changes: 26 additions & 9 deletions tests/io/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,41 @@
"""
import os
import pytest
import responses
from io import BytesIO
from responses import matchers


@pytest.mark.vcr()
@responses.activate
def test_files_upload(api):
"""
test to uploads the file object
"""
api.files.upload('ExampleDataGoesHere')
responses.post('https://cloud.tenable.com/file/upload',
match=[
matchers.multipart_matcher({
'Filedata': b'ExampleFileData'
}),
],
json={'fileuploaded': 'test.txt'}
)
fobj = BytesIO(b'ExampleFileData')
assert api.files.upload(fobj) == 'test.txt'


@pytest.mark.vcr()
@responses.activate
def test_files_encryption_success(api, datafiles):
"""
test to upload the file with encryption
"""
file = 'test.txt'
with open(os.path.join(str(datafiles), file), 'w+') as fobj:
fobj.write('test')
fobj.close()
with open(os.path.join(str(datafiles), file), 'rb') as fobj:
api.files.upload(fobj, encrypted=True)
responses.post('https://cloud.tenable.com/file/upload',
match=[
matchers.multipart_matcher({
'Filedata': b'ExampleFileData'
}),
matchers.query_param_matcher({'no_enc': 1})
],
json={'fileuploaded': 'test.txt'}
)
fobj = BytesIO(b'ExampleFileData')
assert api.files.upload(fobj, encrypted=True) == 'test.txt'
2 changes: 1 addition & 1 deletion tests/sc/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_files_upload(tsc):

@responses.activate
def test_files_clear(tsc):
responses.post('https://nourl/rest/file/delete',
responses.post('https://nourl/rest/file/clear',
match=[
json_params_matcher({'filename': 'testfile'})
],
Expand Down

0 comments on commit 4f8625e

Please sign in to comment.