-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrbitra_tests.py
115 lines (100 loc) · 3.79 KB
/
rbitra_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from rbitra import create_app, db, configure
from rbitra.models import Configuration, Server, Organization, Member, MemberDigest
from rbitra.configure import set_config
from rbitra.schema import MemberSchema, OrganizationSchema
from werkzeug.security import check_password_hash
import unittest
import json
import base64
import tempfile
from flask_testing import TestCase
class BasicIntegrationTest(TestCase):
def create_app(self):
return create_app(test=True)
def setUp(self):
self.member_data = {
'member_name': "testuser",
'email': "[email protected]",
'password': "test123"
}
self.valid_credentials = base64.b64encode(b'[email protected]:test123').decode('utf-8')
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
def test_install(self):
self.client.get('/install')
current_config = Configuration.query.filter_by(name='current_config').first()
self.assertEqual(current_config.any_member_may_create_orgs, True)
def test_create_org(self):
set_config()
m_result = self.client.post(
'/create/member',
data=self.member_data
)
self.assert200(m_result)
response = self.client.post(
'/create/org',
data={'org_name': "test org"},
headers={'Authorization': 'Basic ' + self.valid_credentials}
)
result = Organization.query.filter_by(name="test org").first()
self.assert200(response)
self.assertNotEqual(result, None)
def test_create_member(self):
set_config()
response = self.client.post(
'/create/member',
data=self.member_data
)
member = Member.query.filter_by(name="testuser").first()
digest = MemberDigest.query.filter_by(member=member.uuid).first()
self.assert200(response)
self.assertNotEqual(member, None)
self.assertTrue(check_password_hash(digest.digest, "test123"))
def test_create_decision_add_member_to_org(self):
set_config()
member_resp = self.client.post(
'/create/member',
data=self.member_data
)
member = json.loads(member_resp.json)
self.assert200(member_resp)
org_resp = self.client.post(
'/create/org',
data={'org_name': "test org"},
headers={'Authorization': 'Basic ' + self.valid_credentials}
)
org = json.loads(org_resp.json)
self.assert200(org_resp)
plugin_resp = self.client.post(
'/install/plugin',
data={'git_url': 'https://www.github.com/spencerharmon/meta_plugin'}
)
plugin = json.loads(plugin_resp.json)
self.assert200(plugin_resp)
valid_actions_resp = self.client.get(
'/plugin/{}/valid_actions'.format(plugin["title"])
)
actions = {}
valid_actions = json.loads(valid_actions_resp.json)
for k, v in valid_actions.items():
# {'add_member_to_org': {'member': <str:uuid>, 'org': <str:uuid>}}
actions[k] = {v['argument_keys_list'][0]: member['uuid'], v['argument_keys_list'][1]: org['uuid']}
response = self.client.post(
'/create/decision',
headers={'Authorization': 'Basic ' + self.valid_credentials},
data={
"title": "test decision",
"plugin": plugin["uuid"],
"member": member["uuid"],
"org": org["uuid"],
"directory": "testdecision",
"actions": json.dumps(actions)
}
)
print(self.valid_credentials)
print(response.__dict__)
self.assert200(response)
if __name__ == '__main__':
unittest.main()