-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_javascript_handler.py
49 lines (39 loc) · 1.88 KB
/
test_javascript_handler.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
import unittest
from unittest.mock import patch
# pylint: disable="import-error"
from javascript_handler import JavascriptHandler
test_js = ""
class JavaScriptHandlerTests(unittest.TestCase):
def setUp(self):
global test_js
with open('test.js') as js_file:
js = js_file.read()
test_js += js + ' \n'
def test_extract_javascript_a(self):
self.js_handler = JavascriptHandler(test_js, "a")
current_value = self.js_handler.js_code
self.js_handler.extract_javascript_a()
new_value = self.js_handler.js_code
# Expect handler.js_code to have changed after extract_javascript method called
self.assertNotEqual(current_value, new_value, "extract javascript a test failed")
def test_extract_javascript_b(self):
self.js_handler = JavascriptHandler(test_js, "b")
current_value = self.js_handler.js_code
self.js_handler.extract_javascript_b()
new_value = self.js_handler.js_code
# Expect js_handler.js_code to have changed after extract_javascript method called
self.assertNotEqual(current_value, new_value, "extract javascript a test failed")
@patch('dot_formatter.DotFormatter.convert_to_dot_a')
def test_create_puml_a(self, MockMethod):
# Create mock for my_dot_formatter.convert_to_dot_a and expect it to have been called
self.js_handler = JavascriptHandler(test_js, "a")
self.js_handler.create_puml()
self.assertTrue(MockMethod.called)
@patch('dot_formatter.DotFormatter.convert_to_dot_b')
def test_create_puml_b(self, MockMethod):
# Create mock for my_dot_formatter.convert_to_dot_b and expect it to have been called
self.js_handler = JavascriptHandler(test_js, "b")
self.js_handler.create_puml()
self.assertTrue(MockMethod.called)
if __name__ == '__main__':
unittest.main(verbosity=2)