-
Notifications
You must be signed in to change notification settings - Fork 415
/
Copy pathtest_api.py
85 lines (66 loc) · 2.69 KB
/
test_api.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
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
import json
import pytest
from app.database import model
from . import WEBHOOKDATA, success, load_data
def test_server_new(tester, create_server):
resp = tester.post('/api/server/new', data={})
assert not success(resp)
server = create_server()
assert server['ip'] == '127.0.0.1'
def test_server_delete(tester, create_server, sql):
server = create_server()
resp = tester.post('/api/server/delete', data={'server_id': server['id']})
assert success(resp)
text = 'select count(*) from server where !deleted'
assert sql.execute(text).scalar() == 0
def test_server_list(tester, create_server):
create_server()
create_server()
resp = tester.get('/api/server/list')
assert success(resp)
assert len(load_data(resp)) == 2
def test_webhoot_new(tester, create_server, create_webhook):
server = create_server()
webhook = create_webhook(server_id=server['id'])
assert webhook['branch'] == 'master'
webhook = create_webhook(server_id=server['id'],
webhook_id=webhook['id'], branch='dev')
assert webhook['branch'] == 'dev'
def test_webhoot_delete(tester, create_server, create_webhook, sql):
server = create_server()
webhook = create_webhook(server_id=server['id'])
data = {'webhook_id': webhook['id']}
resp = tester.post('/api/webhook/delete', data=data)
assert success(resp)
text = 'select count(*) from web_hook where !deleted'
assert sql.execute(text).scalar() == 0
def test_webhook_list(tester, create_server, create_webhook):
server = create_server()
create_webhook(server_id=server['id'])
create_webhook(server_id=server['id'])
resp = tester.get('/api/webhook/list')
assert success(resp)
assert len(load_data(resp)) == 2
def test_history(tester, create_server, create_webhook, sql):
server = create_server()
webhook = create_webhook(server_id=server['id'])
query_string = {'webhook_id': webhook['id']}
resp = tester.get('/api/history/list', query_string=query_string)
assert len(load_data(resp)['histories']) == 0
history = model.History(
status='1',
webhook_id=webhook['id'],
data='null'
)
sql.add(history)
sql.commit()
resp = tester.get('/api/history/list', query_string=query_string)
assert len(load_data(resp)['histories']) == 1
@pytest.mark.parametrize("name,data", WEBHOOKDATA.items())
def test_git_webhook(tester, create_server, create_webhook, name, data):
server = create_server()
webhook = create_webhook(server_id=server['id'])
url = '/api/git-webhook/{}'.format(webhook['key'])
resp = tester.post(url, data=json.dumps(data))
assert b'Work put into Queue' in resp.data