-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_test.py
More file actions
executable file
·67 lines (54 loc) · 3.01 KB
/
backup_test.py
File metadata and controls
executable file
·67 lines (54 loc) · 3.01 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
# noqa: E111
import unittest
import backup
import json
from unittest.mock import patch
from datetime import date
class Test(unittest.TestCase):
def test_validate_json_without_bucket_name(self):
with self.assertRaises(SystemExit) as cm:
backup.validate_json({"bucket_name": ""})
self.assertEqual(cm.exception.code, 1)
def test_validate_json_with_bucket_name(self):
actual = backup.validate_json({"bucket_name": "test_bucket_name"})
expected = {"bucket_name": "test_bucket_name"}
self.assertEqual(actual, expected)
def test_get_curl_str(self):
actual = backup.get_curl_str("| curl_str", "www.google.com", "bucket_name", "file_name.txt")
expected = "curl www.google.com | curl_str | aws s3 cp - \"s3://bucket_name/file_name.txt\" --storage-class DEEP_ARCHIVE"
self.assertEqual(actual, expected)
def test_get_encrypt_str(self):
actual = backup.get_encrypt_str("test@gmail.com", "file_name.txt")
expected = "| gpg --encrypt -r test@gmail.com --trust-model always --output file_name.txt"
self.assertEqual(actual, expected)
@patch('backup.get_encrypt_str')
@patch('backup.get_curl_str')
@patch('os.system')
def test_save_files(self, mock_sys, mock_get_curl_str, mock_get_encrypt_str):
mock_sys.return_value = ""
mock_get_encrypt_str.return_value = ""
mock_get_curl_str.return_value = "curl_str"
actual = backup.save_files("google", "tgz", ["1", "2"], "test@gmail.com", "bucket_name")
expected = "curl_str && curl_str"
self.assertEqual(actual, expected)
@patch("json.load")
@patch("builtins.open")
@patch('os.system')
def test_integration_test(self, mock_sys, mock_open, mock_json_load):
data = """{
"bucket_name": "bucket_name",
"gpg_email": "gpg@gmail.com",
"facebook_fmt": "zip",
"facebook_links": ["www.facebook.com/0", "www.facebook.com/1"],
"google_links": ["www.google.com/0", "www.google.com/1"],
"google_fmt": "tgz"
}"""
mock_sys.return_value = ""
mock_open.return_value = ""
mock_json_load.return_value = json.loads(data)
actual = backup.main()
expected = {
"google": f'curl www.google.com/0 | gpg --encrypt -r gpg@gmail.com --trust-model always --output google_{date.today()}_0.tgz | aws s3 cp - "s3://bucket_name/google_{date.today()}_0.tgz" --storage-class DEEP_ARCHIVE && curl www.google.com/1 | gpg --encrypt -r gpg@gmail.com --trust-model always --output google_{date.today()}_1.tgz | aws s3 cp - "s3://bucket_name/google_{date.today()}_1.tgz" --storage-class DEEP_ARCHIVE', # noqa: E501
"facebook": f'curl www.facebook.com/0 | gpg --encrypt -r gpg@gmail.com --trust-model always --output facebook_{date.today()}_0.zip | aws s3 cp - "s3://bucket_name/facebook_{date.today()}_0.zip" --storage-class DEEP_ARCHIVE && curl www.facebook.com/1 | gpg --encrypt -r gpg@gmail.com --trust-model always --output facebook_{date.today()}_1.zip | aws s3 cp - "s3://bucket_name/facebook_{date.today()}_1.zip" --storage-class DEEP_ARCHIVE' # noqa: E501
}
self.assertEqual(actual, expected)