|
12 | 12 |
|
13 | 13 | from __future__ import absolute_import |
14 | 14 |
|
| 15 | +from time import sleep |
15 | 16 | import unittest |
| 17 | +from leetcode.models.interpretation import Interpretation |
| 18 | +from leetcode.models.submission_id import SubmissionId |
| 19 | +import test.base |
16 | 20 |
|
17 | 21 | import leetcode |
18 | 22 | from leetcode.api.default_api import DefaultApi # noqa: E501 |
19 | 23 | from leetcode.rest import ApiException |
20 | 24 |
|
21 | 25 |
|
22 | | -class TestDefaultApi(unittest.TestCase): |
23 | | - """DefaultApi unit test stubs""" |
24 | | - |
25 | | - def setUp(self): |
26 | | - self.api = DefaultApi() # noqa: E501 |
| 26 | +class TestDefaultApi(test.base.BaseTest): |
| 27 | + def test_api_problems_topic_get(self): |
| 28 | + result = self._api_instance.api_problems_topic_get(topic="algorithms") |
| 29 | + test.base.validate_problems(result, "algorithms") |
27 | 30 |
|
28 | | - def tearDown(self): |
29 | | - pass |
| 31 | + result = self._api_instance.api_problems_topic_get(topic="nonexistent") |
| 32 | + test.base.validate_problems(result, "nonexistent") |
30 | 33 |
|
31 | | - def test_api_problems_topic_get(self): |
32 | | - """Test case for api_problems_topic_get""" |
33 | | - pass |
| 34 | + try: |
| 35 | + self._api_instance.api_problems_topic_get(topic="") |
| 36 | + assert False |
| 37 | + except ApiException as e: |
| 38 | + assert e.status == 404 |
34 | 39 |
|
35 | 40 | def test_graphql_post(self): |
36 | | - """Test case for graphql_post""" |
37 | 41 | pass |
38 | 42 |
|
39 | 43 | def test_problems_problem_interpret_solution_post(self): |
40 | | - """Test case for problems_problem_interpret_solution_post""" |
41 | | - pass |
| 44 | + code = """ |
| 45 | + class Solution: |
| 46 | + def twoSum(self, nums, target): |
| 47 | + print("stdout") |
| 48 | + return [1] |
| 49 | + """ |
| 50 | + test_submission = leetcode.TestSubmission( |
| 51 | + data_input="[2,7,11,15]\n9", |
| 52 | + typed_code=code, |
| 53 | + question_id=1, |
| 54 | + test_mode=False, |
| 55 | + lang="python", |
| 56 | + ) |
| 57 | + |
| 58 | + result = self._api_instance.problems_problem_interpret_solution_post( |
| 59 | + problem="two-sum", |
| 60 | + body=test_submission, |
| 61 | + ) |
| 62 | + |
| 63 | + assert isinstance(result, Interpretation) |
42 | 64 |
|
43 | | - def test_problems_problem_submit_post(self): |
44 | | - """Test case for problems_problem_submit_post""" |
45 | | - pass |
46 | 65 |
|
47 | | - def test_submissions_detail_id_check_get(self): |
48 | | - """Test case for submissions_detail_id_check_get""" |
49 | | - pass |
| 66 | + def test_problems_problem_submit_post(self): |
| 67 | + code = """ |
| 68 | + class Solution: |
| 69 | + def twoSum(self, nums, target): |
| 70 | + print("stdout") |
| 71 | + return [1] |
| 72 | + """ |
| 73 | + |
| 74 | + submission = leetcode.Submission( |
| 75 | + judge_type="large", |
| 76 | + typed_code=code, |
| 77 | + question_id=1, |
| 78 | + test_mode=False, |
| 79 | + lang="python", |
| 80 | + ) |
| 81 | + submission_id = self._api_instance.problems_problem_submit_post( |
| 82 | + problem="two-sum", body=submission |
| 83 | + ) |
| 84 | + assert isinstance(submission_id, SubmissionId) |
| 85 | + |
| 86 | + |
| 87 | + sleep(5) # FIXME: should probably be a busy-waiting loop |
| 88 | + |
| 89 | + submission_result = self._api_instance.submissions_detail_id_check_get( |
| 90 | + id=submission_id.submission_id |
| 91 | + ) |
| 92 | + # assert isinstance( |
| 93 | + # submission_result, |
| 94 | + # leetcode.SubmissionResult, |
| 95 | + # ) or isinstance( |
| 96 | + # submission_result, |
| 97 | + # leetcode.TestSubmissionResult, |
| 98 | + # ) |
| 99 | + |
| 100 | + # if isinstance(submission_result, leetcode.SubmissionResult): |
| 101 | + # assert isinstance(submission_result.compare_result, str) |
| 102 | + # assert isinstance(submission_result.std_output, str) |
| 103 | + # assert isinstance(submission_result.last_testcase, str) |
| 104 | + # assert isinstance(submission_result.expected_output, str) |
| 105 | + # assert isinstance(submission_result.input_formatted, str) |
| 106 | + # assert isinstance(submission_result.input, str) |
| 107 | + # # Missing or incorrect fields |
| 108 | + # # task_name: str |
| 109 | + # # finished: bool |
| 110 | + # elif isinstance(submission_result, leetcode.TestSubmissionResult): |
| 111 | + # assert isinstance(submission_result.code_answer, list) |
| 112 | + # assert isinstance(submission_result.correct_answer, bool) |
| 113 | + # assert isinstance(submission_result.expected_status_code, int) |
| 114 | + # assert isinstance(submission_result.expected_lang, str) |
| 115 | + # assert isinstance(submission_result.expected_run_success, bool) |
| 116 | + # assert isinstance(submission_result.expected_status_runtime, str) |
| 117 | + # assert isinstance(submission_result.expected_memory, int) |
| 118 | + # assert isinstance(submission_result.expected_code_answer, list) |
| 119 | + # assert isinstance(submission_result.expected_code_output, list) |
| 120 | + # assert isinstance(submission_result.expected_elapsed_time, int) |
| 121 | + # assert isinstance(submission_result.expected_task_finish_time, int) |
| 122 | + |
| 123 | + # def test_submissions_detail_id_check_get(self): |
| 124 | + # try: |
| 125 | + # self._api_instance.submissions_detail_id_check_get(id="nonexistent") |
| 126 | + # assert False |
| 127 | + # except ApiException as e: |
| 128 | + # assert e.status == 404 |
50 | 129 |
|
51 | 130 |
|
52 | 131 | if __name__ == "__main__": |
|
0 commit comments