Test_Code
stringlengths
154
1.38k
Query
stringlengths
215
648
def test_license_check_when_day_is_negative(run_api): """ license check when day is negative """ r = run_api.license_check(days=-1) rjson = r.json() test_assert.status(r, 400) assert rjson['error'] == "Value of `days` cannot be negative", "The error %s" % rjson
Generate Test Code for the endpoint -'license/rest/licenses_check ' to test the scenario of when day params is negative , where the API yeilds output as - '''{"status:200, "result": "FAILURE", "error": "Value of `days` cannot be negative" }'''.
def test_deploy_change_ownership(skip_if_non_admin, non_admin_exec_api, run_api): """ To change ownership of deployed machine from non-admin user to manager by admin """ params, r = non_admin_exec_api.library_add_new_vm() lib_id = r.json()["UUID"] r = non_admin_exec_api.deploy_image(lib_id=lib_id, deploy_on=list(run_api.clm_my_servers.keys())) UUID = r.json()['UUID'] params = { "deployment_UUIDs": [UUID], "owner": non_admin_exec_api.user, "dest_user": "manager" } res = run_api.deploy_change_ownership(params=params) test_assert.status(res, 200) new_owner = run_api.deploy_details(deploy_id=UUID).json()['owner'] assert new_owner == "manager" run_api.deploy_image_delete(deploy_id=UUID) run_api.library_delete(UUID=lib_id)
Generate Test Code for the endpoint -'ideploy/rest/change_ownership' to test the scenario of Successful change of ownership from one user to another where both users exist and the requester has the necessary permissions. , where the input to API is -'''{"deployment_UUIDs": ["UUID1", "UUID2"], "owner": "currentowner", "dest_user": "newowner"}''' and yeilds output as- '''{"status": 200, "message": "Operation performed successfully without any error"}'''.
def test_config_delete_with_invalid_token(invalid_exec_api): """ deleting the non deletable config values with invalid token """ config_value = { "name": "primary_server", } r = invalid_exec_api.config_delete(config_value) test_assert.status(r, 401) result = r.json() assert result['detail'] == "Invalid token."
Generate Test Code for the endpoint -'/config/rest/delete/' to test the scenario of requesting to delete the config values when provided valid config name but with invalid token , where the input to API is -'''config_value = { "name": "primary_server" }''' and yeilds output as- '''{ "status": 401, "message": "Invalid token" } '''.
def test_add_vm_to_library_multiple_bootable_disk_with_same_boot_order(run_api): """ If multiple bootable cds with same boot order is passed """ disks = [{ "size": 20, "port": "sdb", "type": "sata", "format": "qcow2", "is_boot": True, "boot_order": 1 }, { "size": 20, "port": "sda", "type": "sata", "format": "qcow2", "is_boot": True, "boot_order": 1 }] params, response = run_api.library_add_new_vm(disks=disks, noraise=True) test_assert.status(response, 400)
Generate Test Code for the endpoint -'/library/rest/add' to test the scenario of adding vm to library when multiple boot disks and same order is passed , where the input to API is -'''disks = [{ "size": 20, "port": "sdb", "type": "sata", "format": "qcow2", "is_boot": True, "boot_order": 1 }, { "size": 20, "port": "sda", "type": "sata", "format": "qcow2", "is_boot": True, "boot_order": 1 }]''' and yeilds output as- '''{ "status" : 400, "response" : Bad request }'''.
def test_version_config_with_invalid_token(invalid_exec_api): """ Fetching the information of Version and Build Number with invalid token """ r = invalid_exec_api.config_version() result = r.json() test_assert.status(r, 401) assert result['detail'] == "Invalid token."
Generate Test Code for the endpoint -'/config/rest/version/' to test the scenario of Fetching the information when invalid token is provided , where the API yeilds output as - '''{ "status":401, "message":"invalid token" }'''.
endpoint = "deploy_delete" PARAMETERS = [{"dest_obj": OBJ_DEPL}] PARAMETERS_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "deploy_with": SRV_MANAGER_RIGHTS}] PARAMETERS_NO_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "deploy_with": SRV_NO_MANAGER_RIGHTS}] @pytest.mark.parametrize("custom_lib_non_admin_operations", PARAMETERS_SRV_RIGHT, indirect=True) @pytest.mark.parametrize("custom_lib_admin_operations", PARAMETERS_SRV_RIGHT, indirect=True) def test_deploy_delete_manager_server_right(skip_if_not_manager, custom_lib_admin_operations, custom_lib_non_admin_operations, run_api): """ Deleting the VM by Manager """ # When the user is not part of the group that the manager manages and deployment is on manager rights to server deploy_id = custom_lib_admin_operations r = run_api.deploy_image_delete(deploy_id, {}) test_assert.status(r, manager_rights_response(endpoint, manages_user=False, manages_server=True)) # When the user is part of the group that the manager manages and deployment is on manager rights to server deploy_id = custom_lib_non_admin_operations r = run_api.deploy_image_delete(deploy_id, {}) test_assert.status(r, manager_rights_response(endpoint, manages_user=True, manages_server=True))
Generate Test Code for the endpoint -'/deploy/rest/delete/{UUID}/ ' to test the scenario of the manager deletes the image when the manager has rights over the user and the server , where the API yeilds output as - '''{ "status":204 }'''.
def test_lib_add_disk_with_invalid_UUID(run_api): lib_UUID = "doesnotexist" r = run_api.library_add_disk(lib_UUID) test_assert.status(r, 404)
Generate Test Code for the endpoint -'/library/rest/adddisk/{{UUID}}/ ' to test the scenario of adding disk to library when provided lib_UUID that does not exist , where the input to API is -'''lib_UUID = "doesnotexist"''' and yeilds output as- '''{ "status" : 404 }'''.
PARAMETERS = [{"dest_obj": OBJ_LIB}] @pytest.mark.parametrize("custom_lib_admin_operations", PARAMETERS, indirect=True) def test_lib_delete_non_admin(skip_if_not_non_admin, custom_lib_admin_operations, run_api): """ Deleting the Library by non-Admin """ # Non-admin check for deleting the Library created by different user. lib_id = custom_lib_admin_operations r = run_api.library_delete(lib_id, {}) test_assert.status(r, 403)
Generate Test Code for the endpoint -'/library/rest/delete/{UUID}/' to test the scenario of deleting a library by non-admin when provided with valid UUID , where the API yeilds output as - '''{ "status" : 403 }'''.
def test_library_ctypes(run_api): """ Getting the list of console type """ r = run_api.library_console_types() result = r.json() test_assert.status(result, LIBRARY_CONSOLE_TYPE, "library_ctypes") test_assert.status(r, 200)
Generate Test Code for the endpoint -'/library/rest/ctypes/' to test the scenario of getting the console type when requested , where the API yeilds output as - '''{ "status" : 200, "response" : console type details displayed }'''.
def test_library_edit_delete_invalid_disk_UUID(library_add_new_vm, run_api): """ delete disk with invalid UUID """ p, r = library_add_new_vm lib_id = r['UUID'] disk_UUID = str(UUID.UUID4()) # disk_UUID = 'invalid' #it gives {'hw': {'disks': {'update': [{'UUID': ['Must be a valid UUID.']}]}}} disks = {"delete": [ { "UUID": disk_UUID, "port": "sdz", "type": r['hw']['disks'][0]['type'] } ] } params = {"hw": {"disks": disks}} res = run_api.library_edit(lib_id, params) test_assert.status(res, 404) rjson = res.json() assert rjson['error'] == f"Disk with UUID {disk_UUID} does not exist", "|> json %s" % rjson
Generate Test Code for the endpoint -'/library/rest/edit/{UUID}/' to test the scenario of deletion of disk when invalid UUID provided , where the API yeilds output as - '''{ "status" : 404, "message" : "Disk with UUID does not exist" }'''.
def test_library_edit_update_is_public_flag(skip_if_not_non_admin, library_add_new_vm, run_api): """ Update is_public flag """ p, res = library_add_new_vm UUID = res['UUID'] params = { "is_public": True, "hw": {} } r = run_api.library_edit(UUID, params) test_assert.status(r, 400) rjson = r.json() assert rjson['error'] == "Failed to create task to sync public layers on primary", "Json |> %s" % rjson
Generate Test Code for the endpoint -'/library/rest/edit/{UUID}/' to test the scenario of updation of library when is_public flag set to True , where the input to API is -'''params = { "is_public": True, "hw": {} }''' and yeilds output as- '''{ "status" : 400, "message" : "Failed to create task to sync public layers on primary" }'''.
def test_library_edit_network_with_valid_data(run_api): """ edit network with valid data """ networks = [{ "type": "bridge", "model": "virtio", "segment": "Default Public Segment", } ] params, r = run_api.library_add_new_vm(networks=networks) update_netork = [{ "type": "host", "model": "virtio", "segment": "HostOnly Segment", }] params = {'hw': {'networks': update_netork}} lib_id = r.json()["UUID"] res = run_api.library_edit(lib_id, params) test_assert.status(res, 201) rjson = res.json() new_network = rjson['hw']['networks'][0] assert new_network['type'] == 'host', "|> Error %s" % rjson assert new_network['segment'] == 'HostOnly Segment', "|> Error %s" % rjson run_api.library_delete(lib_id, {})
Generate Test Code for the endpoint -'/library/rest/edit/{UUID}/' to test the scenario of updation of network in a library with valid data , where the input to API is -'''networks = [{ "type": "bridge", "model": "virtio", "segment": "Default Public Segment", } ] update_network = [{ "type": "host", "model": "virtio", "segment": "HostOnly Segment", }] ''' and yeilds output as- '''{ "status" : 201 }'''.
def test_library_hvmtypes(run_api): """ Getting the list of Hypervisor type """ r = run_api.library_hvmtypes() result = r.json() test_assert.status(result, LIBRARY_HVM_TYPE, "library_hvmtypes") test_assert.status(r, 200)
Generate Test Code for the endpoint -'​/library​/rest​/hvmtypes​/' to test the scenario of fetching the hypervisor type when requested , where the API yeilds output as - '''{ "status" : 200, "response" : list of hypervisor type }'''.
def test_library_revisions_without_UUID(run_api): """ Without UUID """ res = run_api.library_revisions("") test_assert.status(res, 400) rjson = res.json() assert rjson['detail'] == "Machine UUID should be provided", "|> The error %s" % rjson
Generate Test Code for the endpoint -'/library/rest/revisions/' to test the scenario of requesting the revision list of library when machine_UUID is empty , where the input to API is -'''{ machine_UUID : '' }''' and yeilds output as- '''{ "status" : 400, "message" : "Machine UUID should be provided"}'''.
endpoint = "deploy_stop" PARAMETERS = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"]}] PARAMETERS_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"], "deploy_with": SRV_MANAGER_RIGHTS}] PARAMETERS_NO_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"], "deploy_with": SRV_NO_MANAGER_RIGHTS}] @pytest.mark.parametrize("custom_lib_non_admin_operations", PARAMETERS, indirect=True) def test_deploy_stop_admin(skip_if_not_admin, custom_lib_non_admin_operations, run_api): """ Rebooting the VM by Admin """ # Admin check of Starting a deployment created by different user deploy_id = custom_lib_non_admin_operations r = run_api.deploy_stop(deploy_id) test_assert.status(r, 201)
Generate Test Code for the endpoint -'/deploy/rest/stop/{{UUID}}/' to test the scenario of stopping a machine by an admin when valid UUID is provided and machine is in running state , where the API yeilds output as - '''{ "status" : 201, "response" : stopping deployment }'''.
endpoint = "deploy_stop" PARAMETERS = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"]}] PARAMETERS_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"], "deploy_with": SRV_MANAGER_RIGHTS}] PARAMETERS_NO_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"], "deploy_with": SRV_NO_MANAGER_RIGHTS}] @pytest.mark.parametrize("custom_lib_admin_operations", PARAMETERS, indirect=True) def test_deploy_stop_non_admin(skip_if_not_non_admin, custom_lib_admin_operations, run_api): """ stopping the VM by non-admin """ # Non-admin check of Starting a deployment created by different user deploy_id = custom_lib_admin_operations r = run_api.deploy_stop(deploy_id) test_assert.status(r, 403)
Generate Test Code for the endpoint -'/deploy/rest/stop/{{UUID}}/' to test the scenario of stopping a machine by non-admin user when valid UUID is provided and machine is in running state , where the API yeilds output as - '''{ "status" : 403 }'''.
endpoint = "deploy_stop" PARAMETERS = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"]}] PARAMETERS_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"], "deploy_with": SRV_MANAGER_RIGHTS}] PARAMETERS_NO_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"], "deploy_with": SRV_NO_MANAGER_RIGHTS}] @pytest.mark.parametrize("custom_lib_non_admin_operations", PARAMETERS_SRV_RIGHT, indirect=True) @pytest.mark.parametrize("custom_lib_admin_operations", PARAMETERS_SRV_RIGHT, indirect=True) def test_deploy_stop_manager_server_right(skip_if_not_manager, custom_lib_admin_operations, custom_lib_non_admin_operations, run_api): """ stopping the VM by manager when have right on server """ # When the user is not part of the group that the manager manages deploy_id = custom_lib_admin_operations r = run_api.deploy_stop(deploy_id) test_assert.status(r, manager_rights_response(endpoint, manages_user=False, manages_server=True)) # When the user is part of the group that the manager manages and deployment is on manager rights to server deploy_id = custom_lib_non_admin_operations r = run_api.deploy_stop(deploy_id) test_assert.status(r, manager_rights_response(endpoint, manages_user=True, manages_server=True)) run_api.deploy_stop(deploy_id)
Generate Test Code for the endpoint -'/deploy/rest/stop/{{UUID}}/' to test the scenario of stopping a machine deployment by a manager when valid UUID is provided and machine is in running state , and manager has rights over servers'''.
endpoint = "deploy_stop" PARAMETERS = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"]}] PARAMETERS_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"], "deploy_with": SRV_MANAGER_RIGHTS}] PARAMETERS_NO_SRV_RIGHT = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"], "deploy_with": SRV_NO_MANAGER_RIGHTS}] @pytest.mark.parametrize("custom_lib_non_admin_operations", PARAMETERS_NO_SRV_RIGHT, indirect=True) @pytest.mark.parametrize("custom_lib_admin_operations", PARAMETERS_NO_SRV_RIGHT, indirect=True) def test_deploy_stop_manager_no_server_right(skip_if_not_manager, custom_lib_admin_operations, custom_lib_non_admin_operations, run_api): """ stopping the VM by manager when have no right on server """ # When the user is not part of the group that the manager manages and the deployment is not on manager rightful server deploy_id = custom_lib_admin_operations r = run_api.deploy_stop(deploy_id) test_assert.status(r, manager_rights_response(endpoint, manages_user=False, manages_server=False)) # When the user is part of the group that the manager manages but the deployment is not on manager rightful server deploy_id = custom_lib_non_admin_operations r = run_api.deploy_stop(deploy_id) test_assert.status(r, manager_rights_response(endpoint, manages_user=True, manages_server=False))
Generate Test Code for the endpoint -'/deploy/rest/stop/{{UUID}}/' to test the scenario of stopping a machine deployment by a manager when valid UUID is provided and machine is in running state , but manager do not have rights over servers'''.
PARAMETERS = [{"dest_obj": OBJ_DEPL, "final_state": DEPL_STATE["running"]}] @pytest.mark.parametrize("custom_lib_non_admin_operations", PARAMETERS, indirect=True) def test_deploy_shutdown_admin(skip_if_not_admin, custom_lib_non_admin_operations, run_api): """ shutdown the VM by Admin """ # Admin check of Shutdown a deployment created by different user deploy_id = custom_lib_non_admin_operations r = run_api.deploy_shutdown(deploy_id) test_assert.status(r, 201)
Generate Test Code for the endpoint -'/deploy/rest/shutdown/{{UUID}}/' to test the scenario of shutting down the deployment of machine by an admin using valid UUID and machine is in running state , where the API yeilds output as - '''{ "status" : 201, "response" : Machine shutdown }'''.
def test_rtask_rlist_without_authorization(anonymous_exec_api): """ Fetching the List of Jobs without authorization """ r = anonymous_exec_api.rtask_rlist() res = r.json() test_assert.status(r, 401) assert res['detail'] == "Authentication credentials were not provided."
Generate Test Code for the endpoint -'​/rtask​/rest​/rlist​/' to test the scenario of fetching the list of remote tasks without authorization , where the API yeilds output as - '''{ "status" : 401, "message" : "Authentication credentials were not provided" }'''.
def test_ilibrary_add_invalid_ips(run_api): """ Creating an Island Library with invalid bridge ip, start ip, end ip """ params = { "name": "test_ilibrary_add_invalid_ips", "is_public": True, "network_segments": { "add": [ { "name": "network_segment", "bridge_ip": "1921681000", "start_ip": "1921681001", "end_ip": "192168100150" } ] } } params, r = run_api.ilibrary_add_new_island(params=params) test_assert.status(r, 400) rjson = r.json() errors = rjson['network_segments']['add'][0] assert errors['start_ip'] == ['Enter a valid IPv4 address.'] assert errors['end_ip'] == ['Enter a valid IPv4 address.'] assert errors['bridge_ip'] == ['Enter a valid IPv4 address.']
Generate Test Code for the endpoint -'/ilibrary/rest/add/' to test the scenario of creating an island library and adding it using invalid IPs , where the input to API is -'''{ "name": "test_ilibrary_add_invalid_ips", "is_public": True, "network_segments": { "add": [ { "name": "network_segment", "bridge_ip": "1921681000", "start_ip": "1921681001", "end_ip": "192168100150" } ] } }''' and yeilds output as- '''{ "status" : 400, "message" : "Enter valid IPv4 addresses" }'''.
def test_ilibrary_details_with_edit_private_island_to_public_island(skip_if_not_admin, run_api): """ To check machine type with public island """ params1, r1 = run_api.library_add_new_vm(networks=networks) machine1 = { "uuid": r1.json()["uuid"], "nics": { "add": [ { "mac": "auto", "type": "bridge", "model": networks[0].get("model", "virtio"), "segment": "Default Public Segment" }, ], } } params = { "name": "Machine1", "is_public": False, "machines": { "add": [machine1], }, } params, r = run_api.ilibrary_add_new_island(params=params) island_id = r.json()["uuid"] params, r = run_api.ilibrary_edit_island(uuid=island_id, params={"is_public": True}) res = r.json()["machines"] run_api.ilibrary_delete(uuid=island_id) run_api.library_delete(r1.json()["uuid"]) for machine in res: if not machine["is_public"]: assert False, "The json is %s" % r.json()
Generate Test Code for the endpoint -'/ilibrary/rest/details/{UUID}/' to test the scenario of fetching details of public island library from private island , where the input to API is -'''{ "name": "Machine1", "is_public": False, "machines": { "add": [machine1], }, }''' and yeilds output as- '''{ "response" : success }'''.
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
0
Edit dataset card