import requester as r
import time
from requester import test_print

r.verify = False

r.initialize_and_clear_tables()

admin_session = r.session

desc =  '#### create 2 more users ####' 
res = r.create_user('rahul', 'rahul123')
test_print(desc, res.status_code < 300)
rahul_user_id = r.json.loads(res.content)['insertId']

res = r.create_user('ashwin', 'ashwin123')
test_print(desc, res.status_code < 300)
ashwin_user_id = r.json.loads(res.content)['insertId']

desc =  '#### get all users in DB, make sure there are 3 now and that the second username == rahul ####'
res = r.get_all_users()
test_print(desc, len(r.json.loads(res.content)['results']) == 3)
test_print(desc, r.json.loads(res.content)['results'][1]['username'] == 'rahul')

desc =  '#### create 2 groups ####'
res = r.create_group("group1", "nope", True, True, True, False)
test_print(desc, res.status_code < 300)
test_print(desc, res.content)
group_id1 = r.json.loads(res.content)['results']['insertId']

res = r.create_group("group2", "nope", True, True, True, False)
def is_success(desc, res):
	test_print(desc, res.status_code < 300)

def is_failure(desc, res):
	test_print(desc, res.status_code >= 400 and res.status_code < 500)

def get_id(res):
	json_content = r.json.loads(res.content)
	if 'insertId' in json_content:
	 	return json_content['insertId']
	return json_content['results']['insertId']

admin_session = r.session

desc = '### create non-admin user & session ###'
res = r.create_user("chris", "dee")
is_success(desc, res)
r.session = ''
res = r.login_to_session("chris", "dee")
non_admin_session = res.cookies

"""" ---Signin as admin--- """
r.session = admin_session

desc = "### create 3 resources with tags ###"
res = r.create_resource("r1", "r1", "free", 1000, 0, 1)
resource1 = get_id(res)
is_success(desc, res)
res = r.add_tag(resource1, ["resource1", "a resource"])
is_success(desc, res)
res = r.create_resource("r2", "r2", "free", 1000, 0, 1)
Esempio n. 3
0
res = r.create_resource("notags", "notags", 'free', 1, 0, 1)
test_print(desc, res.status_code < 300)
no_tags_id = r.json.loads(res.content)['insertId']

desc =  '#### get permissions for resource without tags and make that the admin user has permission ####'
res = r.get_group_permission_to_resource(resource_id)
test_print(desc, res.status_code < 300)
test_print(desc, len(r.json.loads(res.content)['results']) == 1)

desc =  '#### get all resources and make sure there are 4 (including root) ####'
res = r.get_all_resources()
test_print(desc, res.status_code < 300)
test_print(desc, len(r.json.loads(res.content)) == 4)

desc =  '#### create another user ####' 
res = r.create_user('rahul', 'rahul123')
test_print(desc, res.status_code < 300)
user_id = r.json.loads(res.content)['insertId']

desc =  '#### get all users in DB, make sure there are 2 now and that the second username == rahul ####'
res = r.get_all_users()
test_print(desc, len(r.json.loads(res.content)['results']) == 2)
test_print(desc, r.json.loads(res.content)['results'][1]['username'] == 'rahul')

desc =  '#### create a group and let it view the root ####'
res = r.create_group("fungroup", "nope", True, True, True, False)
test_print(desc, res.status_code < 300)
test_print(desc, res.content)

group_id = r.json.loads(res.content)['results']['insertId']
res = r.add_group_permission_to_resource(1, [group_id], ['view'])