This repository has been archived by the owner on Sep 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_captcha.py
207 lines (115 loc) · 4.53 KB
/
test_captcha.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import unittest
from app import app
from mycaptcha import Captcha
from myoperator import Operator
from myoperand import StringOperand
from myoperand import IntOperand
from myrandomizer import Randomizer
from CaptchaController import CaptchaController
class TestFirstPatternLeftOperand(unittest.TestCase):
DUMMY_PATTERN = 1
DUMMY_OPERATOR = 1
DUMMY_LEFT = 1
DUMMY_RIGHT = 1
def test_1_should_be_1(self):
captcha = Captcha(self.DUMMY_PATTERN, 1, self.DUMMY_OPERATOR, self.DUMMY_RIGHT)
self.assertEqual('1', captcha.left_operand())
return False;
def test_2_should_be_2(self):
captcha = Captcha(self.DUMMY_PATTERN, 2, self.DUMMY_OPERATOR, self.DUMMY_RIGHT)
self.assertEqual('2', captcha.left_operand())
return False;
class TestSecondPatternLeftOperand(unittest.TestCase):
DUMMY_PATTERN = 2
DUMMY_OPERATOR = 1
DUMMY_LEFT = 1
DUMMY_RIGHT = 1
def test_1_should_be_one(self):
captcha = Captcha(self.DUMMY_PATTERN, 1, self.DUMMY_OPERATOR, self.DUMMY_RIGHT)
self.assertEqual('one', captcha.left_operand())
class TestFirstPatternRightOperand(unittest.TestCase):
DUMMY_PATTERN = 1
DUMMY_OPERATOR = 1
DUMMY_LEFT = 1
DUMMY_RIGHT = 1
def test_1_should_be_1(self):
captcha = Captcha(self.DUMMY_PATTERN, self.DUMMY_LEFT, self.DUMMY_OPERATOR, 1)
self.assertEqual('1', captcha.right_operand())
class TestSecondPatternRightOperand(unittest.TestCase):
DUMMY_PATTERN = 2
DUMMY_OPERATOR = 1
DUMMY_LEFT = 1
DUMMY_RIGHT = 1
def test_1_should_be_1(self):
captcha = Captcha(self.DUMMY_PATTERN, self.DUMMY_LEFT, self.DUMMY_OPERATOR, 1)
self.assertEqual('one', captcha.right_operand())
class TestOperator(unittest.TestCase):
DUMMY_PATTERN = 1
DUMMY_OPERATOR = 1
DUMMY_LEFT = 1
DUMMY_RIGHT = 1
def test_1_should_be_plus(self):
captcha = Captcha(self.DUMMY_PATTERN, self.DUMMY_LEFT, 1, self.DUMMY_RIGHT)
self.assertEqual('+', captcha.operator())
def test_2_should_be_multiply(self):
captcha = Captcha(self.DUMMY_PATTERN, self.DUMMY_LEFT, 2, self.DUMMY_RIGHT)
self.assertEqual('*', captcha.operator())
def test_3_should_be_minus(self):
captcha = Captcha(self.DUMMY_PATTERN, self.DUMMY_LEFT, 3, self.DUMMY_RIGHT)
self.assertEqual('-', captcha.operator())
class TestOperatorClass(unittest.TestCase):
def test_1_should_be_plus(self):
operator = Operator(1)
self.assertEqual('+', operator.to_string())
def test_2_should_be_multiply(self):
operator = Operator(2)
self.assertEqual('*', operator.to_string())
def test_3_should_be_minus(self):
operator = Operator(3)
self.assertEqual('-', operator.to_string())
class TestStringOperandClass(unittest.TestCase):
def test_input_1_should_be_one(self):
stringOperand = StringOperand(1)
self.assertEqual('one', stringOperand.to_string())
def test_input_2_should_be_two(self):
stringOperand = StringOperand(2)
self.assertEqual('two', stringOperand.to_string())
class TestIntOperandClass(unittest.TestCase):
def test_input_1_should_be_1(self):
intOperand = IntOperand(1)
self.assertEqual('1', intOperand.to_string())
def test_input_2_should_be_2(self):
intOperand = IntOperand(2)
self.assertEqual('2', intOperand.to_string())
class TestRandomizerClass(unittest.TestCase):
def test_pattern_should_return_between_1_and_2(self):
self.assertTrue(1 <= Randomizer().random_pattern() <= 2)
def test_operator_shoud_return_between_1_and_3(self):
self.assertTrue(1 <= Randomizer().random_operator() <= 3)
def test_operand_shoud_return_between_0_and_9(self):
self.assertTrue(0 <= Randomizer().random_operand() <= 9)
class TestCaptchaAPI(unittest.TestCase):
def test_it_should_return_200(self):
self.app = app.test_client()
response = self.app.get('/captcha')
self.assertEqual(response.status_code, 200)
class TestCapchaController(unittest.TestCase):
def test_should_be_return_valid_json(self):
captcha_controller = CaptchaController()
captcha_controller.captcha = Captcha(1,1,1,1)
self.assertEqual('{"left": "1", "operator": "1", "right": "1"}', captcha_controller.to_json())
# class TestCaptchaControllerRandomizer(unittest.TestCase):
# def test_get(self):
# stubRandomizer = Randomizer()
# def stub_pattern():
# return 1
# def stub_operand():
# return 1
# def stub_operator():
# return 1
# stubRandomizer.pattern = stub_pattern
# stubRandomizer.operand = stub_operator
# stubRandomizer.operator = stub_operand
# captchaController = CaptchaController()
# captchaController.Randomizer = stubRandomizer
# assertEqual('{"left": "1", "operator": "1", "right": "1"}', captchaController.get())