Skip to content

Commit da55254

Browse files
committed
testcase changes
1 parent 4a28e18 commit da55254

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

tests.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,61 @@
11
import unittest
22
from v2_utils import remove_unmatched_tags
33
from app import app
4-
import json,random
4+
import json, random
55

66

77
class CustomTestResult(unittest.TextTestResult):
88
def addSuccess(self, test):
99
super().addSuccess(test)
1010
print(f"{test._testMethodName} - passed")
1111

12-
1312
class CustomTestRunner(unittest.TextTestRunner):
1413
resultclass = CustomTestResult
1514

15+
def run(self, test):
16+
result = super().run(test)
17+
if result.wasSuccessful():
18+
print("All Testcases Passed")
19+
return result
20+
1621

1722
class TestRemoveUnmatchedTags(unittest.TestCase):
1823
"""
1924
Static test case input & output for check markdown handler function
2025
"""
2126
def test_remove_unmatched_tags_basic(self):
2227
input_text = "<div>Test content</p></div>"
23-
expected_output = "<div>Test content</div>"
28+
expected_output = "<ul><div>Test content</div></ul>"
2429
self.assertEqual(remove_unmatched_tags(input_text), expected_output)
2530

2631
def test_remove_unmatched_tags_unmatched_opening(self):
2732
input_text = "<div>Test content"
28-
expected_output = "<div>Test content</div>"
33+
expected_output = "<ul><div>Test content</div></ul>"
2934
self.assertEqual(remove_unmatched_tags(input_text), expected_output)
3035

3136
def test_remove_unmatched_tags_unmatched_closing(self):
3237
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>"
3439
self.assertEqual(remove_unmatched_tags(input_text), expected_output)
3540

3641
def test_remove_unmatched_tags_nested_tags(self):
3742
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>"
3944
self.assertEqual(remove_unmatched_tags(input_text), expected_output)
4045

4146
def test_remove_unmatched_tags_unmatched_nested_opening(self):
4247
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>"
4449
self.assertEqual(remove_unmatched_tags(input_text), expected_output)
4550

4651
def test_remove_unmatched_tags_unmatched_nested_closing(self):
4752
input_text = "<div>Test content</p></div>"
48-
expected_output = "<div>Test content</div>"
53+
expected_output = "<ul><div>Test content</div></ul>"
4954
self.assertEqual(remove_unmatched_tags(input_text), expected_output)
5055

5156
def test_remove_unmatched_tags_multiple_unmatched_tags(self):
5257
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>"
5459
self.assertEqual(remove_unmatched_tags(input_text), expected_output)
5560

5661
def test_remove_unmatched_tags_text_with_no_tags(self):
@@ -61,7 +66,7 @@ def test_remove_unmatched_tags_text_with_no_tags(self):
6166
def test_remove_unmatched_tags_empty_string(self):
6267
input_text = ""
6368
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))
6570

6671

6772
class TestIssuesEndpoints(unittest.TestCase):
@@ -70,13 +75,16 @@ def setUp(self):
7075
self.app = app.test_client()
7176
self.app.testing = True
7277
self.issues_data = None # To store issues data for use in subsequent tests
78+
self.headers = {
79+
'x-secret-key': 'QrfmzUjsKzPzUXEleSztEv8g'
80+
}
7381

7482
# Fetch issues data during setup
7583
self._fetch_issues_data()
7684

7785
def _fetch_issues_data(self):
7886
# Validate the /issues endpoint and store the issues data
79-
response = self.app.get('/issues')
87+
response = self.app.get('/issues',headers=self.headers)
8088
self.assertEqual(response.status_code, 200)
8189

8290
data = json.loads(response.data)
@@ -94,14 +102,14 @@ def test_get_issues_detail_success(self):
94102

95103
# Use first data from /issues response to form the endpoint URL
96104

97-
index = random.randrange(1,len(self.issues_data)-1)
105+
index = random.randrange(1, len(self.issues_data) - 1)
98106
sample_issue = self.issues_data[index]['issues'][0]
99107
issue_id = sample_issue['id']
100108
orgname = self.issues_data[index]['org_name']
101109

102110
endpoint = f'/v2/issues/{orgname}/{issue_id}'
103111

104-
response = self.app.get(endpoint)
112+
response = self.app.get(endpoint,headers=self.headers)
105113
self.assertEqual(response.status_code, 200)
106114

107115
def test_get_repo_detail_success(self):
@@ -110,13 +118,12 @@ def test_get_repo_detail_success(self):
110118
self.skipTest("Skipping detail test as /issues endpoint did not return data")
111119

112120
# 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)
114122
orgname = self.issues_data[index]['org_name']
115123
endpoint = f'/issues/{orgname}'
116-
response = self.app.get(endpoint)
124+
response = self.app.get(endpoint,headers=self.headers)
117125
self.assertEqual(response.status_code, 200)
118126

119-
120127

121128
if __name__ == '__main__':
122129
unittest.main(testRunner=CustomTestRunner())

0 commit comments

Comments
 (0)