Skip to content

Commit 30e51e5

Browse files
Merge pull request geekcomputers#527 from mytechnotalent/test-XORcipher
Created test automation software for the XORCipher created by Christi…
2 parents fd9d646 + 2722f92 commit 30e51e5

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

XORcipher/test_XOR_cipher.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#
2+
# Test XORCipher
3+
# **************
4+
#
5+
# Test automation software created by Kevin M. Thomas 09/29/19.
6+
# Test automation software Modified by Kevin M. Thomas 09/29/19.
7+
# CC BY 4.0
8+
#
9+
# Test XORCipher is the test automation suite for the XORCipher created by
10+
# Christian Bender.
11+
# Usage: python test_XOR_cipher.py
12+
#
13+
14+
15+
import unittest
16+
from unittest import TestCase
17+
import mock
18+
from XOR_cipher import XORCipher
19+
20+
21+
class TestXORCipher(TestCase):
22+
"""
23+
Test XORCipher class.
24+
"""
25+
26+
def setUp(self):
27+
"""
28+
The SetUp call with commented values in the event one needs
29+
to instantiate mocked objects regarding the XORCipher class.
30+
"""
31+
32+
# key = mock.MagicMock()
33+
# self.XORCipher_1 = XORCipher(key)
34+
pass
35+
36+
@mock.patch('XOR_cipher.XORCipher.__init__')
37+
def test__init__(self, mock__init__):
38+
"""
39+
Test the __init__ method with commented values in the event
40+
one needs to instantiate mocked objects on the method.
41+
"""
42+
43+
# self.XORCipher_1.__init__ = mock.MagicMock()
44+
XORCipher.__init__ = mock.MagicMock()
45+
46+
# self.XORCipher_1.__init__(1)
47+
XORCipher.__init__()
48+
49+
# self.XORCipher_1.__init__.assert_called_with(1)
50+
XORCipher.__init__.assert_called()
51+
52+
@mock.patch('XOR_cipher.XORCipher.encrypt')
53+
def test_encrypt(self, mock_encrypt):
54+
"""
55+
Test the encrypt method with mocked values.
56+
"""
57+
58+
ans = mock.MagicMock()
59+
content = mock.MagicMock()
60+
key = mock.MagicMock()
61+
XORCipher.encrypt = mock.MagicMock(return_value=ans)
62+
XORCipher.encrypt(content, key)
63+
64+
XORCipher.encrypt.assert_called_with(content, key)
65+
66+
@mock.patch('XOR_cipher.XORCipher.decrypt')
67+
def test_decrypt(self, mock_decrypt):
68+
"""
69+
Test the decrypt method with mocked values.
70+
"""
71+
72+
ans = mock.MagicMock()
73+
content = mock.MagicMock()
74+
key = mock.MagicMock()
75+
XORCipher.decrypt = mock.MagicMock(return_value=ans)
76+
XORCipher.decrypt(content, key)
77+
78+
XORCipher.decrypt.assert_called_with(content, key)
79+
80+
@mock.patch('XOR_cipher.XORCipher.encrypt_string')
81+
def test_encrypt_string(self, mock_encrypt_string):
82+
"""
83+
Test the encrypt_string method with mocked values.
84+
"""
85+
86+
ans = mock.MagicMock()
87+
content = mock.MagicMock()
88+
key = mock.MagicMock()
89+
XORCipher.encrypt_string = mock.MagicMock(return_value=ans)
90+
XORCipher.encrypt_string(content, key)
91+
92+
XORCipher.encrypt_string.assert_called_with(content, key)
93+
94+
@mock.patch('XOR_cipher.XORCipher.decrypt_string')
95+
def test_decrypt_string(self, mock_decrypt_string):
96+
"""
97+
Test the decrypt_string method with mocked values.
98+
"""
99+
100+
ans = mock.MagicMock()
101+
content = mock.MagicMock()
102+
key = mock.MagicMock()
103+
XORCipher.decrypt_string = mock.MagicMock(return_value=ans)
104+
XORCipher.decrypt_string(content, key)
105+
106+
XORCipher.decrypt_string.assert_called_with(content, key)
107+
108+
@mock.patch('XOR_cipher.XORCipher.encrypt_file')
109+
def test_encrypt_file(self, mock_encrypt_file):
110+
"""
111+
Test the encrypt_file method with mocked values.
112+
"""
113+
114+
file = mock.MagicMock()
115+
key = mock.MagicMock()
116+
XORCipher.encrypt_file = mock.MagicMock(return_value=True)
117+
XORCipher.encrypt_file(file, key)
118+
119+
XORCipher.encrypt_file.assert_called_with(file, key)
120+
121+
@mock.patch('XOR_cipher.XORCipher.decrypt_file')
122+
def test_decrypt_file(self, mock_decrypt_file):
123+
"""
124+
Test the decrypt_file method with mocked values.
125+
"""
126+
127+
file = mock.MagicMock()
128+
key = mock.MagicMock()
129+
XORCipher.decrypt_string = mock.MagicMock(return_value=True)
130+
XORCipher.decrypt_string(file, key)
131+
132+
XORCipher.decrypt_string.assert_called_with(file, key)
133+
134+
135+
if __name__ == '__main__':
136+
unittest.main()
137+

0 commit comments

Comments
 (0)