-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_analyse_text.py
More file actions
60 lines (44 loc) · 2.03 KB
/
test_analyse_text.py
File metadata and controls
60 lines (44 loc) · 2.03 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
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 analyse_text
from main import Text
from testing.unit.util.mock_db_util import getRow
from testing.unit.util.mock_db_util import setupMocks
class TestAnalyseText(unittest.TestCase):
@patch('main.getDb')
def test_multiple_items_with_flagged_string(self, getDbMock):
firstRow = getRow("bad_string", "the_category", "the_info")
secondRow = getRow("bad_string_2", "the_category", "the_info")
setupMocks(getDbMock, [firstRow, secondRow])
data = {'content': 'bad_string, bad_string_2'}
text = Text(**data)
output = analyse_text(text)
expected = {"biased":
[{"flag": "bad_string", "category": "the_category", "info": "the_info"},
{"flag": "bad_string_2", "category": "the_category", "info": "the_info"}]}
assert output == expected, "Actual: " + str(output) + " Expected: " + str(expected)
@patch('main.getDb')
def test_single_item_with_flagged_string(self, getDbMock):
firstRow = getRow("bad_string", "the_category", "the_info")
setupMocks(getDbMock, [firstRow])
data = {'content': 'bad_string'}
text = Text(**data)
output = analyse_text(text)
expected = {"biased":
[{"flag": "bad_string", "category": "the_category", "info": "the_info"}]}
assert output == expected, "Actual: " + str(output) + " Expected: " + str(expected)
@patch('main.getDb')
def test_no_text_provided(self, getDbMock):
firstRow = getRow("bad_string", "the_category", "the_info")
setupMocks(getDbMock, [firstRow])
data = {'content': ''}
text = Text(**data)
output = analyse_text(text)
expected = {"biased": []}
assert output == expected, "Actual: " + str(output) + " Expected: " + str(expected)
if __name__ == '__main__':
unittest.main()