is_success(desc, res)

desc = "### create 3 to 4 reservation ###"
res = r.create_reservation([free_id, resource_id1], get_time(3), get_time(4), "t", "d")
is_success(desc, res)
reservation1 = get_id(res)

desc = "### confirm first resource ###"
res = r.confirm_resource_reservation(resource_id1, reservation_id1)
is_success(desc, res)

desc = "### confirm second resource -- reservations should be deleted"
res = r.confirm_resource_reservation(resource_id1, reservation_id2)
is_success(desc, res)

desc = "### Test that cannot change resource to free and reduce sharing_level when only confirmed overbooked ###"
res = r.update_resource(resource_id1, resource_state="free", sharing_level=1)
is_failure(desc, res)

desc = "### Test that can change resource to free when only confirmed resources ###"
res = r.update_resource(resource_id1, resource_state="free")
is_success(desc, res)

desc = "### Check that three reservations remain (two confirmed, one not overlapping)"
res = r.get_reservations_by_resources([resource_id1])
is_success(desc, res)
test_print(desc, len(r.json.loads(res.content)["results"]) == 3)


r.finish_test("basic resource sharing test")
r.test_print(desc, r.json.loads(res.content)['resources'][0]['resource_id'] == resource3)

desc = "### Check behavior with empty included tags ###"
res = r.filter_tags([], ["a resource"], 0, 999999999)
is_success(desc, res)
r.test_print(desc, len(r.json.loads(res.content)['resources']) == 2)
r.test_print(desc, r.json.loads(res.content)['resources'][1]['resource_id'] == resource3)

desc = "### Add permission to root folder & one resource to non_admin user ###"
res = r.get_groups()
is_success(desc, res)
group_id = r.json.loads(res.content)['results'][1]['group_id']
res = r.add_group_permission_to_resource(1, [group_id], ['view'])
res = r.add_group_permission_to_resource(resource1, [group_id], ['view'])
is_success(desc, res)

"""" ---login as non_admin user with permissions to resource1--- """
r.session = non_admin_session

desc = "### ensure that tag filter can only see one resource and the root folder ###"
res = r.filter_tags([],[], 0, 99999999)
is_success(desc, res)
r.test_print(desc, len(r.json.loads(res.content)['resources']) == 2)
r.test_print(desc, r.json.loads(res.content)['resources'][0]['name'] == 'root')
r.test_print(desc, r.json.loads(res.content)['resources'][1]['name'] == 'r1')




r.finish_test("tag filter test")
is_failure(desc, res)

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

desc = '### confirm restricted1 on reservation w/ two restricted resources ###'
res = r.confirm_resource_reservation(restricted_id2, r2r1_id)
is_success(desc, res)
desc = '### make sure overlapping reservation was not deleted yet ###'
res = r.get_reservations_by_resources([restricted_id1])
is_success(desc, res)
test_print(desc, len(r.json.loads(res.content)['results']) == 3)

desc = '### confirm other resource on same resource ###'
res = r.confirm_resource_reservation(restricted_id1, r2r1_id)
is_success(desc, res)

desc = '### make sure overlapping reservations were deleted ###'
res = r.get_reservations_by_resources([restricted_id1, restricted_id2])
test_print(desc, len(r.json.loads(res.content)['results']) == 2)

desc = "### make sure you can't deny an already confirmed reservation ###"
res = r.deny_resource_reservation(restricted_id1, r2r1_id)
is_failure(desc, res)

desc = "### test that resource can be changed once conflicts are resolved ###"
res = r.update_resource(restricted_id1, "s", "s", "free")
is_success(desc, res)

r.finish_test("Confirm Deny Test")
desc =  '#### get all reservations on resources, make sure there are only 9 rows after update to view - rahuls reservations on res1 should be gone, ashwins shouldnt ####'
res = r.get_reservations_by_resources([resource_id1, resource_id2, resource_id3, resource_id4])
test_print(desc, len(r.json.loads(res.content)['results']) == 9)

desc =  '#### remove permission for group2 on resource1 ####'
res = r.remove_group_permission_to_resource(resource_id1, [group_id2])
test_print(desc, res.status_code < 300)

desc =  '#### get all reservations on resources, make sure there are only 6 rows remove permission - ashwins reservations on res1 should now be gone too ####'
res = r.get_reservations_by_resources([resource_id1, resource_id2, resource_id3, resource_id4])
test_print(desc, len(r.json.loads(res.content)['results']) == 6)

desc =  '#### remove rahul and ashwin from group1 ####'
res = r.remove_users_from_group([rahul_user_id, ashwin_user_id], group_id1)
test_print(desc, res.status_code < 300)

desc =  '#### get all reservations on resources, make sure there are only 3 rows after removal of rahul - rahuls reservations should be gone ####'
res = r.get_reservations_by_resources([resource_id1, resource_id2, resource_id3, resource_id4])
test_print(desc, len(r.json.loads(res.content)['results']) == 3)

desc =  '#### delete group2 ####'
res = r.delete_group(group_id2)
test_print(desc, res.status_code < 300)

desc =  '#### get all reservations on resources, make sure there are only no rows left ####'
res = r.get_reservations_by_resources([resource_id1, resource_id2, resource_id3, resource_id4])
test_print(desc, len(r.json.loads(res.content)['results']) == 0)

r.finish_test("remove permissions test")
Beispiel #5
0
session_response = r.login_to_session('rahul', 'rahul123')
test_print(desc, session_response.status_code < 300)
rahul_session = session_response.cookies

desc = "### fail to remove resource from someone else's reservation ###"
r.session = rahul_session
res = r.remove_resource_from_reservation(reservation_id, [resource_id])
test_print(desc, res.status_code > 300)
r.session = admin_session

desc = "### remove resource from reservation as reservation owner"
res = r.remove_resource_from_reservation(reservation_id2, [resource_id])
test_print(desc, res.status_code < 300)

desc =  '#### create a restricted resource ####'
res = r.create_resource("restrictedRes", "restrictedDesc", 'restricted', 1, 0, 1)
test_print(desc, res.status_code < 300)
restricted_resource_id = r.json.loads(res.content)['insertId']

desc =  '#### create reservation on restricted resource ####'
res = r.create_reservation([restricted_resource_id], millis, millis2, 'title', 'description')
test_print(desc, res.status_code < 300)
restricted_reservation_id = r.json.loads(res.content)['results']['insertId']

desc =  '#### delete reservation on restricted resource ####'
res = r.delete_reservation(restricted_reservation_id)
test_print(desc, res.status_code < 300)


r.finish_test("temp main test")
test_print(desc, len(r.json.loads(res.content)['results']) == 0)

desc = '#### update parent for folder2 ####'
res = r.update_parent_of_resource(folder_id2, folder_id1)
test_print(desc, res.status_code < 300)

desc = '#### get subtree starting at folder1 ####'
res = r.get_subtree(folder_id1)
test_print(desc, res.status_code < 300)
test_print(desc, len(r.json.loads(res.content)['results']) == 6)

desc = '#### update parent for resource1 ####'
res = r.update_parent_of_resource(resource_id1, 1)
test_print(desc, res.status_code < 300)

desc = '#### get subtree starting at folder1 ####'
res = r.get_subtree(folder_id1)
test_print(desc, res.status_code < 300)
test_print(desc, len(r.json.loads(res.content)['results']) == 5)

desc = '#### try to update parent for resource1 to resource2 ####'
res = r.update_parent_of_resource(resource_id1, resource_id2)
test_print(desc, res.status_code > 300)

desc = '#### get subtree starting at folder1 ####'
res = r.get_subtree(folder_id1)
test_print(desc, res.status_code < 300)
test_print(desc, len(r.json.loads(res.content)['results']) == 5)

r.finish_test("create resources test")
desc =  '#### add rahul to the first group ####'
res = r.add_users_to_group([rahul_user_id], group_id1)
test_print(desc, res.status_code < 300)

desc = '#### Give group 1 view access to root resource ####'
res = r.add_group_permission_to_resource(root_resource_id, [group_id1], ['view'])
test_print(desc, res.status_code < 300)

desc = '#### Give rahul view access to root ####'
res = r.add_group_permission_to_resource(root_resource_id, [rahul_group_id], ['view'])
test_print(desc, res.status_code < 300)

desc = '#### add view permission to folder1 ####'
res = r.add_group_permission_to_resource(folder_id1, [group_id1], ['view'])
test_print(desc, res.status_code < 300)

desc = '#### try to update parent for folder1 ####'
res = r.update_parent_of_resource(folder_id1, folder_id2)
test_print(desc, res.status_code > 300)
test_print(desc, r.json.loads(res.content)['parentResourcePermissionMismatchError'] == 1)

desc = '#### add view permission to folder2 ####'
res = r.add_group_permission_to_resource(folder_id2, [group_id1], ['view'])
test_print(desc, res.status_code < 300)

desc = '#### successfully update parent for folder1 ####'
res = r.update_parent_of_resource(folder_id1, folder_id2)
test_print(desc, res.status_code < 300)

r.finish_test("update resources test")