Showing
3 changed files
with
109 additions
and
0 deletions
tests/added.diff
0 → 100644
tests/fixed.diff
0 → 100644
tests/test_suite.py
0 → 100644
1 | +# Copyright 2020-present Tae Hwan Jung | ||
2 | +# | ||
3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | +# you may not use this file except in compliance with the License. | ||
5 | +# You may obtain a copy of the License at | ||
6 | +# | ||
7 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | +# | ||
9 | +# Unless required by applicable law or agreed to in writing, software | ||
10 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | +# See the License for the specific language governing permissions and | ||
13 | +# limitations under the License. | ||
14 | + | ||
15 | +import json | ||
16 | +import requests | ||
17 | +import unittest | ||
18 | + | ||
19 | +class CitiesTestCase(unittest.TestCase): | ||
20 | + endpoint='http://127.0.0.1:5000' | ||
21 | + headers = {'Content-Type': 'application/json; charset=utf-8'} | ||
22 | + | ||
23 | + def test_index(self): | ||
24 | + response = requests.get(f"{self.endpoint}/", headers=self.headers) | ||
25 | + self.assertEqual(response.status_code, 200) | ||
26 | + self.assertEqual( | ||
27 | + json.loads(response.text), | ||
28 | + { | ||
29 | + "hello": "world", | ||
30 | + } | ||
31 | + ) | ||
32 | + | ||
33 | + def test_tokenizer(self): | ||
34 | + response = requests.post( | ||
35 | + f"{self.endpoint}/tokenizer", | ||
36 | + headers=self.headers, | ||
37 | + data=json.dumps( | ||
38 | + dict( | ||
39 | + code="hello world!" | ||
40 | + ) | ||
41 | + ) | ||
42 | + ) | ||
43 | + self.assertEqual(response.status_code, 200) | ||
44 | + self.assertEqual( | ||
45 | + json.loads(response.text), | ||
46 | + { | ||
47 | + "tokens": [ | ||
48 | + "hello", | ||
49 | + "Ġworld", | ||
50 | + "!" | ||
51 | + ] | ||
52 | + } | ||
53 | + ) | ||
54 | + | ||
55 | + def test_added(self): | ||
56 | + response = requests.post( | ||
57 | + f"{self.endpoint}/added", | ||
58 | + headers=self.headers, | ||
59 | + data=json.dumps( | ||
60 | + dict( | ||
61 | + idx=0, | ||
62 | + added=['test'], | ||
63 | + deleted=[], | ||
64 | + ) | ||
65 | + ) | ||
66 | + ) | ||
67 | + self.assertEqual(response.status_code, 200) | ||
68 | + self.assertEqual( | ||
69 | + json.loads(response.text), | ||
70 | + {'idx': 0, 'message': ['Test method .']} | ||
71 | + ) | ||
72 | + | ||
73 | + def test_added(self): | ||
74 | + response = requests.post( | ||
75 | + f"{self.endpoint}/diff", | ||
76 | + headers=self.headers, | ||
77 | + data=json.dumps( | ||
78 | + dict( | ||
79 | + idx=0, | ||
80 | + added=['tes'], | ||
81 | + deleted=['test'], | ||
82 | + ) | ||
83 | + ) | ||
84 | + ) | ||
85 | + self.assertEqual(response.status_code, 200) | ||
86 | + self.assertEqual( | ||
87 | + json.loads(response.text), | ||
88 | + {'idx': 0, 'message': ['Fix typo']} | ||
89 | + ) | ||
90 | + | ||
91 | + | ||
92 | +def suite(): | ||
93 | + suties = unittest.TestSuite() | ||
94 | + suties.addTests(unittest.makeSuite(CitiesTestCase)) | ||
95 | + return suties | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment