Skip to content

Commit

Permalink
fix(test): test case fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric05 committed May 23, 2022
1 parent 2d01127 commit a3d2042
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
35 changes: 24 additions & 11 deletions test/core/test_script_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ def test_python(self):
req, result = self.load_comp("python_class")
self.assertEqual(ScriptType.PYTHON, req.httpdef.test_script_lang)
self.assertEqual({"stdout": "working\n", "error": "", "properties": {}, "tests": [
{"name": "test_hai (test_script.SampleTest)", "success": True}], "compiled": True}, result)
{"name": "test_hai (test_script.SampleTest)", "success": True,"result": None,"error": None}], "compiled": True}, result)

def test_python_func(self):
req, result = self.load_comp("python_function")
self.assertEqual(ScriptType.PYTHON, req.httpdef.test_script_lang)
self.assertEqual({"stdout": "working\n", "error": "", "properties": {}, "tests": [
{"name": "test_hai", "success": True, "result": None}], "compiled": True}, result)
{"name": "test_hai", "success": True, "result": None,"error": None}], "compiled": True}, result)

def test_javascript(self):
req, result = self.load_comp("javascript")
self.assertEqual(ScriptType.JAVA_SCRIPT, req.httpdef.test_script_lang)
self.assertEqual({"stdout": "", "error": "", "properties": {}, "tests": [
{"name": "check status", "success": True, "result": None}], "compiled": True}, result)
{"name": "check status", "success": True, "result": None,"error": None}], "compiled": True}, result)

def test_javascript_default(self):
req, result = self.load_comp("default_javascript")
self.assertEqual(ScriptType.JAVA_SCRIPT, req.httpdef.test_script_lang)
self.assertEqual({"stdout": "", "error": "", "properties": {}, "tests": [
{"name": "check status", "success": True, "result": None}], "compiled": True}, result)
{"name": "check status", "success": True, "result": None,"error": None}], "compiled": True}, result)

def load_comp(self, target):
req = self.get_req_comp(file_name, target=target)
req.load_def()
execution_cls = js3py.ScriptExecutionJs if req.httpdef.test_script_lang == ScriptType.JAVA_SCRIPT else js3py.ScriptExecutionPython
execution_cls = js3py.ScriptExecutionJs if req.httpdef.test_script_lang == ScriptType.JAVA_SCRIPT else js3py.ScriptExecutionPython
script_execution = execution_cls(req.httpdef, req.property_util)
resp = req.get_response()
return req, script_execution.execute_test_script(resp).as_json()
Expand All @@ -62,7 +62,9 @@ def test_status_code(self):
'properties': {},
'stdout': '',
'tests': [{'name': 'test_status_code (test_script.SampleTestCase)',
'success': True}]}, resp.as_json())
'success': True,
'result': None,
'error': None}]}, resp.as_json())

def get_script_exe(self, script):
resp = Response()
Expand All @@ -86,7 +88,8 @@ def pre_request():
script_exe = ScriptExecutionPython(httpdef, props)
script_exe.pre_request_script()
self.assertEquals({"ram": "ranga"}, httpdef.headers)
self.assertEquals({"new": "value", "ram": "raju"}, script_exe.client.properties)
self.assertEquals({"new": "value", "ram": "raju"},
script_exe.client.properties)

def test_math_n_headers(self):
resp = self.get_script_exe("""
Expand Down Expand Up @@ -114,19 +117,27 @@ def test_hash(self):
'tests': [
{
'name': 'test_date (test_script.SampleTestCase)',
'success': True
'success': True,
'result': None,
'error': None
},
{
'name': 'test_hash (test_script.SampleTestCase)',
'success': True
'success': True,
'result': None,
'error': None
},
{
'name': 'test_headers (test_script.SampleTestCase)',
'success': True
'success': True,
'result': None,
'error': None
},
{
'name': 'test_math (test_script.SampleTestCase)',
'success': True
'success': True,
'result': None,
'error': None
}
]
}, resp.as_json())
Expand All @@ -142,6 +153,7 @@ def test_status_code(self):
'properties': {},
'tests': [{'name': 'test_status_code (test_script.SampleTestCase)',
'success': False,
'result': None,
'error': 'Traceback (most recent call last):\n File "test_script.py", line 4, in test_status_code\nAssertionError: 401 != 200\n'}],
'compiled': True}, resp.as_json())

Expand All @@ -159,4 +171,5 @@ def test_raise(self):
' File "test_script.py", line 4, in test_raise\n'
'Exception\n',
'name': 'test_raise (test_script.SampleTestCase)',
'result': None,
'success': False}]}, resp.as_json())
1 change: 1 addition & 0 deletions test/extensions/test_script_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_execute_is_equals_script3(self):
'stdout': '',
'tests': [{'name': 'checks payload output recursive',
'result': None,
'error':None,
'success': True}]},
result.result['script_result'])

Expand Down

0 comments on commit a3d2042

Please sign in to comment.