diff options
author | BonfaceKilz | 2021-03-01 16:51:57 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-03-08 21:09:58 +0300 |
commit | d0347cecce5655caba96d330536a83279df28f0b (patch) | |
tree | 5d1420b10e2631b5891614011e3de1588ea3ad90 /tests/unit | |
parent | ff29ce04a1f10af819770ccafd347daaba6b2bf7 (diff) | |
download | genenetwork3-d0347cecce5655caba96d330536a83279df28f0b.tar.gz |
Extract files to "/TMPDIR/TOKEN"
TOKEN is the user token
* gn3/file_utils.py (extract_uploaded_file): Add extra param "token". If a
token is empty, create a new directory based off that token.
* tests/unit/test_file_utils.py: Update failing tests.
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/test_file_utils.py | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/tests/unit/test_file_utils.py b/tests/unit/test_file_utils.py index 166e576..7f4d83d 100644 --- a/tests/unit/test_file_utils.py +++ b/tests/unit/test_file_utils.py @@ -1,6 +1,5 @@ """Test cases for procedures defined in file_utils.py""" import os -import shutil import unittest from dataclasses import dataclass @@ -75,33 +74,30 @@ non-existent""" jsonfile_to_dict, "/non-existent-dir") + @mock.patch("gn3.file_utils.tarfile") @mock.patch("gn3.file_utils.secure_filename") - def test_extract_uploaded_file(self, mock_file): + def test_extract_uploaded_file(self, mock_file, mock_tarfile): """Test that the gzip file is extracted to the right location""" - file_loc = os.path.join( - os.path.dirname(__file__), - "upload-data.tar.gz") - mock_file.return_value = file_loc + mock_file.return_value = "upload-data.tar.gz" mock_fileobj = MockFile(save=mock.MagicMock(), filename="upload-data.tar.gz") - result = extract_uploaded_file(mock_fileobj, "/tmp") - mock_fileobj.save.assert_called_once_with(file_loc) + mock_tarfile.return_value = mock.Mock() + result = extract_uploaded_file(mock_fileobj, "/tmp", + token="abcdef-abcdef") + mock_fileobj.save.assert_called_once_with("/tmp/abcdef-abcdef/" + "upload-data.tar.gz") mock_file.assert_called_once_with("upload-data.tar.gz") - # Clean up! - shutil.rmtree(os.path.join("/tmp", - "d41d8cd98f00b204e9800998ecf8427e")) self.assertEqual(result, {"status": 0, - "token": "d41d8cd98f00b204e9800998ecf8427e"}) + "token": "abcdef-abcdef"}) @mock.patch("gn3.file_utils.secure_filename") def test_extract_uploaded_file_non_existent_gzip(self, mock_file): """Test that the right error message is returned when there is a problem extracting the file""" - file_loc = os.path.join( + mock_file.return_value = os.path.join( os.path.dirname(__file__), "CTtyodSTh5") # Does not exist! - mock_file.return_value = file_loc mock_fileobj = MockFile(save=mock.MagicMock(), filename="") result = extract_uploaded_file(mock_fileobj, "/tmp") |