-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_check_words.py
More file actions
74 lines (53 loc) · 2.55 KB
/
test_check_words.py
File metadata and controls
74 lines (53 loc) · 2.55 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
68
69
70
71
72
73
74
from json import load
import sys
sys.path.append('../../taketwo-webapi')
sys.path.append('../util')
import unittest
from unittest.mock import patch
from main import check_words
from main import Text
from testing.unit.util.mock_db_util import getRow
from testing.unit.util.mock_db_util import setupMocks
class TestCheckWords(unittest.TestCase):
@patch('main.getDb')
def test_no_text_provided(self, getDbMock):
firstRow = getRow("bad_string", "racial-slur", "the_info")
setupMocks(getDbMock, [firstRow])
data = {'content': ''}
text = Text(**data)
output = check_words(text)
expected = []
assert output == expected, "Actual: " + str(output) + " Expected: " + str(expected)
@patch('main.getDb')
def test_single_flagged_string_in_content(self,getDbMock):
firstRow = getRow("bad_string", "racial-slur", "the_info")
setupMocks(getDbMock, [firstRow])
data = {'content': 'bad_string'}
text = Text(**data)
output = check_words(text)
expected = [{"line":1, "word":"bad_string", "additional_info":"the_info"}]
assert output == expected, "Actual: " + str(output) + " Expected: " + str(expected)
@patch('main.getDb')
def test_single_flagged_string_and_valid_string_in_content(self,getDbMock):
firstRow = getRow("bad_string", "racial-slur", "the_info")
setupMocks(getDbMock, [firstRow])
data = {'content': 'bad_string\nokay_string'}
text = Text(**data)
output = check_words(text)
expected = [{"line":1, "word":"bad_string", "additional_info":"the_info"}]
assert output == expected, "Actual: " + str(output) + " Expected: " + str(expected)
@patch('main.getDb')
def test_multiple_flagged_strings_existing_records(self,getDbMock):
firstRow = getRow("bad_string", "racial-slur", "the_info")
secondRow = getRow("bad_string_2", "racial-slur", "the_info_2")
thirdRow = getRow("biased_thing", "other", "the_info_3")
setupMocks(getDbMock, [firstRow, secondRow, thirdRow])
data = {'content': 'bad_string\nbad_string_2'}
text = Text(**data)
output = check_words(text)
expected = [{"line":1, "word":"bad_string", "additional_info":"the_info"},
{"line":2, "word":"bad_string", "additional_info":"the_info"},
{"line":2, "word":"bad_string_2", "additional_info":"the_info_2"}]
assert output == expected, "Actual: " + str(output) + " Expected: " + str(expected)
if __name__ == '__main__':
unittest.main()