Skip to content

Commit 22248d3

Browse files
author
Victor Machado
committed
test_basic_features workflow
1 parent 6e7557a commit 22248d3

File tree

6 files changed

+128
-36
lines changed

6 files changed

+128
-36
lines changed

Diff for: .github/workflows/test-basic-features.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test basic features
2+
3+
run-name: Test basic features
4+
5+
on: [push, pull_request]
6+
7+
jobs:
8+
test-credentials:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
13+
14+
steps:
15+
16+
- uses: actions/checkout@v4
17+
with:
18+
ref: ${{ github.ref }}
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Display Python version
26+
run: python3 -c "import sys; print(sys.version)"
27+
28+
- name: Create and activate virtual environment
29+
run: |
30+
python3 -m venv .venv
31+
source .venv/bin/activate
32+
33+
- name: Install froster locally
34+
env:
35+
LOCAL_INSTALL: true
36+
run: ./install.sh
37+
38+
- name: Run test_credentials tests
39+
env:
40+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
41+
AWS_SECRET: ${{ secrets.AWS_SECRET }}
42+
run: python3 tests/test_basic_features.py

Diff for: froster/froster.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -6940,16 +6940,14 @@ def tearDown(bucket_name, folder_path):
69406940
cfg.bucket_name = new_bucket_name
69416941

69426942
# Create a dummy file
6943+
log(f'\nCreating dummy file {file_path}...')
6944+
69436945
folder_path = tempfile.mkdtemp(prefix='froster_test_')
69446946
file_path = os.path.join(folder_path, 'dummy_file')
69456947

6946-
log(f'\nCreating dummy file {file_path}...')
6947-
69486948
with open(file_path, 'wb') as f:
69496949
f.truncate(1)
69506950

6951-
subprocess.run(['touch', file_path])
6952-
69536951
log(f' ....dummy file create')
69546952

69556953
# Create a new bucket

Diff for: tests/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def random_string(length=4):
4747
S3_ARCHIVE_DIR_2 = 'froster-alice'
4848

4949
S3_STORAGE_CLASS_1 = 'DEEP_ARCHIVE'
50-
S3_STORAGE_CLASS_2 = 'GLACIER'
50+
S3_STORAGE_CLASS_2 = 'STANDARD'
5151

5252
SLURM_WALLTIME_DAYS = 8
5353
SLURM_WALLTIME_HOURS = 1

Diff for: tests/test_basic_features.py

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import subprocess
2+
import sys
3+
from time import sleep
4+
import unittest
5+
from unittest.mock import patch
6+
from froster import *
7+
from tests.config import *
8+
9+
10+
class TestBasicFeatures(unittest.TestCase):
11+
'''Test the froster basic features.'''
12+
13+
# Method executed once before all tests
14+
@classmethod
15+
def setUpClass(cls):
16+
'''- Set up class.'''
17+
18+
# Setup the froster configuration by mocking user input
19+
with \
20+
patch('sys.argv', ['froster', 'config']), \
21+
patch('inquirer.text', side_effect=[NAME_1, EMAIL_1, PROFILE_1, AWS_CREDENTIALS_PROFILE_1, AWS_ACCESS_KEY_ID, AWS_SECRET, S3_BUCKET_NAME_CREDENTIALS_1, S3_ARCHIVE_DIR_1]), \
22+
patch('inquirer.confirm', side_effect=[False, False, True, False]), \
23+
patch('inquirer.list_input', side_effect=['+ Create new profile', PROVIDER_1, '+ Create new credentials', AWS_REGION_1, '+ Create new bucket', S3_STORAGE_CLASS_1]):
24+
main()
25+
26+
# Method executed once after all tests
27+
@classmethod
28+
def tearDownClass(cls):
29+
'''- Tear down class.'''
30+
31+
# Delete the created S3 bucket
32+
with \
33+
patch('sys.argv', ['froster', '--debug', 'delete', '--bucket', S3_BUCKET_NAME_CREDENTIALS_1]):
34+
main()
35+
36+
def test_basic_features(self):
37+
'''- Test the froster basic features.'''
38+
39+
try:
40+
# Create a dummy file
41+
folder_path = tempfile.mkdtemp(prefix='froster_')
42+
print(f"\nTemporary directory created at: {folder_path}")
43+
44+
file_path = os.path.join(folder_path, 'dummy_file')
45+
with open(file_path, 'wb') as f:
46+
f.truncate(1)
47+
print(f"Dummy file created at: {file_path}")
48+
49+
# Run the basic features commands and check if return value is 0, which means no issues detected while executing the command
50+
51+
# NOTE: config command is tested into the setUpClass method
52+
53+
with \
54+
patch('sys.argv', ['froster', 'index', folder_path]):
55+
self.assertFalse(main())
56+
57+
with \
58+
patch('sys.argv', ['froster', 'archive', folder_path]):
59+
self.assertFalse(main())
60+
61+
with \
62+
patch('sys.argv', ['froster', 'delete', folder_path]):
63+
self.assertFalse(main())
64+
65+
except Exception as e:
66+
print(f"Error: {e}")
67+
68+
69+
70+
if __name__ == '__main__':
71+
72+
try:
73+
74+
unittest.main(verbosity=2, failfast=True)
75+
76+
except KeyboardInterrupt:
77+
print("\nTests interrupted by the user. Exiting...")
78+
sys.exit(1)
79+
except Exception as e:
80+
print("\nAn error occurred during the tests execution: %s" % e)
81+
sys.exit(1)
File renamed without changes.

Diff for: tests/test_credentials.py

+2-31
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ def tearDownClass(cls):
2828

2929
# Delete the S3 buckets
3030
with \
31-
patch('sys.argv', ['froster', '--debug', 'delete', '--bucket', S3_BUCKET_NAME_CREDENTIALS_1]), \
32-
patch('builtins.print') as mock_print:
33-
main()
34-
35-
with \
36-
patch('sys.argv', ['froster', '--debug', 'delete', '--bucket', S3_BUCKET_NAME_CREDENTIALS_2]), \
37-
patch('builtins.print') as mock_print:
31+
patch('sys.argv', ['froster', '--debug', 'delete', '--bucket', S3_BUCKET_NAME_CREDENTIALS_1]):
3832
main()
3933

4034
def test_subcmd_credentials(self):
@@ -49,31 +43,8 @@ def test_subcmd_credentials(self):
4943
if __name__ == '__main__':
5044

5145
try:
52-
if True:
53-
unittest.main(verbosity=2)
54-
else:
55-
suite = unittest.TestSuite()
56-
# FULL CONFIGURATION
57-
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestConfig))
58-
59-
# PARTIAL CONFIGURATION
60-
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestConfigUser))
61-
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestConfigAWS))
62-
# suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestConfigShared))
63-
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestConfigNIH))
64-
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestConfigS3))
65-
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestConfigSlurm))
66-
67-
# BASIC TEST CASE FOR EVERY TEST
68-
# suite.addTest(TestConfig('test_subcmd_config'))
69-
# suite.addTest(TestConfigUser('test_set_user'))
70-
# suite.addTest(TestConfigAWS('test_set_aws'))
71-
# suite.addTest(TestConfigShared('test_set_shared'))
72-
# suite.addTest(TestConfigNIH('test_set_nih'))
73-
suite.addTest(TestConfigS3('test_set_s3'))
7446

75-
runner = unittest.TextTestRunner(verbosity=2)
76-
runner.run(suite)
47+
unittest.main(verbosity=2)
7748

7849
except KeyboardInterrupt:
7950
print("\nTests interrupted by the user. Exiting...")

0 commit comments

Comments
 (0)