1
1
import unittest
2
2
from v2_utils import remove_unmatched_tags
3
3
from app import app
4
- import json ,random
4
+ import json , random
5
5
6
6
7
7
class CustomTestResult (unittest .TextTestResult ):
8
8
def addSuccess (self , test ):
9
9
super ().addSuccess (test )
10
10
print (f"{ test ._testMethodName } - passed" )
11
11
12
-
13
12
class CustomTestRunner (unittest .TextTestRunner ):
14
13
resultclass = CustomTestResult
15
14
15
+ def run (self , test ):
16
+ result = super ().run (test )
17
+ if result .wasSuccessful ():
18
+ print ("All Testcases Passed" )
19
+ return result
20
+
16
21
17
22
class TestRemoveUnmatchedTags (unittest .TestCase ):
18
23
"""
19
24
Static test case input & output for check markdown handler function
20
25
"""
21
26
def test_remove_unmatched_tags_basic (self ):
22
27
input_text = "<div>Test content</p></div>"
23
- expected_output = "<div>Test content</div>"
28
+ expected_output = "<ul>< div>Test content</div></ul >"
24
29
self .assertEqual (remove_unmatched_tags (input_text ), expected_output )
25
30
26
31
def test_remove_unmatched_tags_unmatched_opening (self ):
27
32
input_text = "<div>Test content"
28
- expected_output = "<div>Test content</div>"
33
+ expected_output = "<ul>< div>Test content</div></ul >"
29
34
self .assertEqual (remove_unmatched_tags (input_text ), expected_output )
30
35
31
36
def test_remove_unmatched_tags_unmatched_closing (self ):
32
37
input_text = "<div><span><p>Test content</div>"
33
- expected_output = "<div><span><p>Test content</p></span></div>"
38
+ expected_output = "<ul>< div><span><p>Test content</p></span></div></ul >"
34
39
self .assertEqual (remove_unmatched_tags (input_text ), expected_output )
35
40
36
41
def test_remove_unmatched_tags_nested_tags (self ):
37
42
input_text = "<div><p>Test content</p></p></div>"
38
- expected_output = "<div><p>Test content</p></div>"
43
+ expected_output = "<ul>< div><p>Test content</p></div></ul >"
39
44
self .assertEqual (remove_unmatched_tags (input_text ), expected_output )
40
45
41
46
def test_remove_unmatched_tags_unmatched_nested_opening (self ):
42
47
input_text = "<div><p>Test content</div>"
43
- expected_output = "<div><p>Test content</p></div>"
48
+ expected_output = "<ul>< div><p>Test content</p></div></ul >"
44
49
self .assertEqual (remove_unmatched_tags (input_text ), expected_output )
45
50
46
51
def test_remove_unmatched_tags_unmatched_nested_closing (self ):
47
52
input_text = "<div>Test content</p></div>"
48
- expected_output = "<div>Test content</div>"
53
+ expected_output = "<ul>< div>Test content</div></ul >"
49
54
self .assertEqual (remove_unmatched_tags (input_text ), expected_output )
50
55
51
56
def test_remove_unmatched_tags_multiple_unmatched_tags (self ):
52
57
input_text = "<div>Test</div><p>Content</p><span>Here"
53
- expected_output = "<div>Test</div><p>Content</p><span>Here</span>"
58
+ expected_output = "<ul>< div>Test</div><p>Content</p><span>Here</span></ul >"
54
59
self .assertEqual (remove_unmatched_tags (input_text ), expected_output )
55
60
56
61
def test_remove_unmatched_tags_text_with_no_tags (self ):
@@ -61,7 +66,7 @@ def test_remove_unmatched_tags_text_with_no_tags(self):
61
66
def test_remove_unmatched_tags_empty_string (self ):
62
67
input_text = ""
63
68
expected_output = ""
64
- self .assertEqual (len (remove_unmatched_tags (input_text )),len (expected_output ))
69
+ self .assertEqual (len (remove_unmatched_tags (input_text )), len (expected_output ))
65
70
66
71
67
72
class TestIssuesEndpoints (unittest .TestCase ):
@@ -70,13 +75,16 @@ def setUp(self):
70
75
self .app = app .test_client ()
71
76
self .app .testing = True
72
77
self .issues_data = None # To store issues data for use in subsequent tests
78
+ self .headers = {
79
+ 'x-secret-key' : 'QrfmzUjsKzPzUXEleSztEv8g'
80
+ }
73
81
74
82
# Fetch issues data during setup
75
83
self ._fetch_issues_data ()
76
84
77
85
def _fetch_issues_data (self ):
78
86
# Validate the /issues endpoint and store the issues data
79
- response = self .app .get ('/issues' )
87
+ response = self .app .get ('/issues' , headers = self . headers )
80
88
self .assertEqual (response .status_code , 200 )
81
89
82
90
data = json .loads (response .data )
@@ -94,14 +102,14 @@ def test_get_issues_detail_success(self):
94
102
95
103
# Use first data from /issues response to form the endpoint URL
96
104
97
- index = random .randrange (1 ,len (self .issues_data )- 1 )
105
+ index = random .randrange (1 , len (self .issues_data ) - 1 )
98
106
sample_issue = self .issues_data [index ]['issues' ][0 ]
99
107
issue_id = sample_issue ['id' ]
100
108
orgname = self .issues_data [index ]['org_name' ]
101
109
102
110
endpoint = f'/v2/issues/{ orgname } /{ issue_id } '
103
111
104
- response = self .app .get (endpoint )
112
+ response = self .app .get (endpoint , headers = self . headers )
105
113
self .assertEqual (response .status_code , 200 )
106
114
107
115
def test_get_repo_detail_success (self ):
@@ -110,13 +118,12 @@ def test_get_repo_detail_success(self):
110
118
self .skipTest ("Skipping detail test as /issues endpoint did not return data" )
111
119
112
120
# Use first data from /issues response to form the endpoint URL
113
- index = random .randrange (1 ,len (self .issues_data )- 1 )
121
+ index = random .randrange (1 , len (self .issues_data ) - 1 )
114
122
orgname = self .issues_data [index ]['org_name' ]
115
123
endpoint = f'/issues/{ orgname } '
116
- response = self .app .get (endpoint )
124
+ response = self .app .get (endpoint , headers = self . headers )
117
125
self .assertEqual (response .status_code , 200 )
118
126
119
-
120
127
121
128
if __name__ == '__main__' :
122
129
unittest .main (testRunner = CustomTestRunner ())
0 commit comments