This repository has been archived by the owner on Jul 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtests.py
78 lines (59 loc) · 2.85 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# coding: utf-8
import unittest
from flask import url_for
from app import app
from config import Test
class SimpleTest(unittest.TestCase):
def setUp(self):
self.app = app
app.config.from_object(Test)
self.app_ctx = self.app.app_context()
self.app_ctx.push()
self.test_client = self.app.test_client(use_cookies=True)
def tearDown(self):
self.app_ctx.pop()
def get_resp_text_content(self, resp):
return resp.get_data(as_text=True)
def test_index(self):
resp = self.test_client.get(url_for('index'))
self.assertTrue(u'功夫网列表转换' in self.get_resp_text_content(resp))
def test_ipset(self):
resp = self.test_client.get(url_for('ipset', args='ipsetname,127.0.0.1:1024'))
self.assertTrue('rules for dnsmasq' in self.get_resp_text_content(resp))
self.assertTrue('# end' in self.get_resp_text_content(resp))
def test_ipset_missing_setname(self):
resp = self.test_client.get(url_for('ipset', args='127.0.0.1:1024'))
self.assertEqual(404, resp.status_code)
def test_ipset_missing_port(self):
resp = self.test_client.get(url_for('ipset', args='setname,127.0.0.1:'))
self.assertEqual(404, resp.status_code)
def test_ipset_invalid_port(self):
resp = self.test_client.get(url_for('ipset', args='setname,127.0.0.1:65536'))
self.assertEqual(404, resp.status_code)
def test_dnsmasq(self):
resp = self.test_client.get(url_for('dnsq', args='127.0.0.1:1024'))
self.assertTrue('rules for dnsmasq' in self.get_resp_text_content(resp))
self.assertTrue('# end' in self.get_resp_text_content(resp))
def test_dnsmasq_missing_port(self):
resp = self.test_client.get(url_for('ipset', args='127.0.0.1:'))
self.assertEqual(404, resp.status_code)
def test_dnsmasq_invalid_port(self):
resp = self.test_client.get(url_for('ipset', args='127.0.0.1:999999'))
self.assertEqual(404, resp.status_code)
def test_pac_socks_proxy(self):
resp = self.test_client.get('/pac/s,127.0.0.1:1024')
self.assertTrue('SOCKS5 127.0.0.1:1024; SOCKS 127.0.0.1:1024' in self.get_resp_text_content(resp))
def test_pac_http_proxy(self):
resp = self.test_client.get('/pac/h,127.0.0.1:1024')
self.assertTrue('PROXY 127.0.0.1:1024' in self.get_resp_text_content(resp))
def test_pac_missing_proxy_type(self):
resp = self.test_client.get('/pac/,127.0.0.1:1024')
self.assertEqual(404, resp.status_code)
def test_pac_invalid_proxy_type(self):
resp = self.test_client.get('/pac/heyhey,127.0.0.1:1024')
self.assertEqual(404, resp.status_code)
def test_pac_missing_port(self):
resp = self.test_client.get('/pac/s,127.0.0.1:')
self.assertEqual(404, resp.status_code)
if __name__ == '__main__':
unittest.main()