Commit 716d3b83 authored by Siebers, Michael's avatar Siebers, Michael
Browse files

test endpoint explain

parent f82f61d0
......@@ -430,6 +430,11 @@ system_test:endpoint_irrelevant@file:
extends: .system_test:run_with_data_and_db
variables:
TEST_NAME: endpoint_irrelevant@file
system_test:endpoint_explain:
extends: .system_test:run_with_data_and_db
variables:
TEST_NAME: endpoint_explain
system_test:robust against wrong method:
extends: .system_test:run_with_data
......
[
{"path": "dir_1/file_old", "success_expected": true},
{"path": "dir_1/file_new", "success_expected": false},
{"path": "dir_2/file_old", "success_expected": true},
{"path": "dir_2/file_new", "success_expected": false},
{"path": "dir_1/dir_a/file_old", "success_expected": true},
{"path": "dir_1/dir_a/file_new", "success_expected": false},
{"path": "dir_1/dir_b/file_old", "success_expected": true},
{"path": "dir_1/dir_b/file_middle", "success_expected": true},
{"path": "dir_1/dir_b/file_new", "success_expected": false},
{"path": "dir_2/dir_a/dir_i/file_old", "success_expected": true},
{"path": "dir_2/dir_a/dir_i/file_middle", "success_expected": true},
{"path": "dir_2/dir_a/dir_i/file_new", "success_expected": false}
]
{
"info": {
"_postman_id": "91bca452-0705-4fa6-b403-bdbc33fa35fb",
"name": "Endpoint explain",
"description": "This collection tests the direct responses of the API Endpoint `explain` of the [Reasoning WebAPI for Dare2Del](https://gitlab.rz.uni-bamberg.de/cogsys/dare2del/demonstrator) (Version 1.0.0).\n\nThe collection assumes that the server is started with background knowledge from `endpoint_explain-theory_bg.db`.\n\nThe collection is to be run with the data file `endpoint_explain-data.json`. The expected results assume that the server has a simple irrelevance rule: \"If two files are in the same folder then the older one (modification time) is irrelevant.\"",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Querry Explanation",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData;",
"",
"if(pm.variables.get(\"success_expected\"))",
"{",
" pm.test(pm.variables.get(\"test_prefix\") + \"Case: Ok\", function () {",
" pm.expect(pm.response.code).to.eql(200);",
" });",
"",
" pm.test(pm.variables.get(\"test_prefix\") + \"Valid response body\", function() {",
" pm.response.to.be.withBody;",
" pm.response.to.be.json;",
"",
" var Ajv = require('ajv');",
" ajv = new Ajv();",
" ajv.addSchema(JSON.parse(pm.variables.get(\"type-schema:abs_path\")));",
" const validate = ajv.compile(JSON.parse(pm.variables.get(\"response-schema:explain\")));",
"",
" jsonData = pm.response.json();",
" pm.expect(validate(jsonData)).to.be.true;",
" });",
"} else {",
" pm.test(pm.variables.get(\"test_prefix\") + \"Bad Request\", function () {",
" pm.expect(pm.response.code).to.eql(400);",
" });",
"",
"",
" pm.test(pm.variables.get(\"test_prefix\") + \"Valid error response body\", function() {",
" pm.response.to.be.withBody;",
" pm.response.to.be.json;",
"",
" var Ajv = require('ajv');",
" ajv = new Ajv();",
" const validate = ajv.compile(JSON.parse(pm.variables.get(\"response-schema:error\")));",
"",
" const jsonData = pm.response.json();",
" pm.expect(validate(jsonData)).to.be.true;",
" pm.expect(jsonData.code).to.eql(400);",
" });",
"};"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"utils.load_schema(\"response-explain-schema.json\", \"response-schema:explain\", pm);",
"utils.load_schema(\"response-error-schema.json\", \"response-schema:error\", pm);",
"utils.load_schema(\"type-abs_path-schema.json\", \"type-schema:abs_path\", pm);",
"",
"pm.variables.set(\"test_prefix\", pm.info.requestName + \" [\" + (pm.info.iteration + 1).toString() + '/' ",
" + pm.info.iterationCount.toString() + ']: ');",
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disabledSystemHeaders": {
"connection": true
}
},
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\"abs_path\": \"{{path}}\"}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://{{SERVER}}/explain",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"explain"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"utils = {",
" \"load_schema\": function(source, target_variable, pm) {",
" if(! pm.collectionVariables.get(target_variable)) {",
" var code_ok = false;",
" const schema_url = \"http://\" + pm.environment.get(\"SERVER\") + pm.environment.get(\"SCHEMA_PATH\") ",
" + \"/\" + source;",
" pm.sendRequest(schema_url, function(err, response){",
" pm.test(\"Load \" + target_variable + \": Status code is 200\", function () {",
" pm.expect(err).to.not.be.ok;",
" console.log(response);",
" pm.expect(response.code).to.eql(200);",
" code_ok = true;",
" });",
"",
"",
" pm.test(\"Load \" + target_variable + \": Response is JSON object\", function() {",
" const jsonData = response.json();",
" pm.expect(jsonData).is.an(\"object\");",
"",
" if(code_ok)",
" pm.collectionVariables.set(target_variable, JSON.stringify(jsonData));",
" });",
" });",
" }",
" }",
"}"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "path",
"value": ""
},
{
"key": "expected_result",
"value": ""
},
{
"key": "expected-schema",
"value": ""
},
{
"key": "type-schema:abs_path",
"value": ""
},
{
"key": "response-schema:error",
"value": ""
},
{
"key": "response-schema:explain",
"value": ""
}
]
}
\ No newline at end of file
created(1623231475.084739).
assert(item_(dir_1,directory{abs_path:dir_1,creation_time:1604235209})).
assert(item_('dir_1/file_old',file{abs_path:'dir_1/file_old',access_time:1604711922,change_time:1604711922,creation_time:1604571092,file_size:17369,filename_extension:'',media_type:text,modification_time:1604710192})).
assert(item_('dir_1/file_new',file{abs_path:'dir_1/file_new',access_time:1604719380,change_time:1604711938,creation_time:1604252069,file_size:2342754,filename_extension:csv,media_type:other,modification_time:1604710193})).
assert(item_(dir_2,directory{abs_path:dir_2,creation_time:624782347})).
assert(item_('dir_2/file_old',file{abs_path:'dir_2/file_old',access_time:628345783,change_time:624834578,creation_time:624823457,file_size:17369,filename_extension:'',media_type:text,modification_time:624834578})).
assert(item_('dir_2/file_new',file{abs_path:'dir_2/file_new',access_time:724847806,change_time:724847806,creation_time:624783475,file_size:2342754,filename_extension:csv,media_type:other,modification_time:724834780})).
assert(item_('dir_1/dir_a',directory{abs_path:'dir_1/dir_a',creation_time:1604235709})).
assert(item_('dir_1/dir_a/file_new',file{abs_path:'dir_1/dir_a/file_new',access_time:1605870913,change_time:1605870913,creation_time:1604357091,file_size:12038,filename_extension:txt,media_type:text,modification_time:1604587091})).
assert(item_('dir_1/dir_a/file_old',file{abs_path:'dir_1/dir_a/file_old',access_time:1604379922,change_time:1604379192,creation_time:1604370912,file_size:12479123,filename_extension:pdf,media_type:pdf,modification_time:1604379192})).
assert(item_('dir_1/dir_b',directory{abs_path:'dir_1/dir_b',creation_time:1604257037})).
assert(item_('dir_1/dir_b/file_old',file{abs_path:'dir_1/dir_b/file_old',access_time:1614372311,change_time:1614357237,creation_time:1614257037,file_size:2334634,filename_extension:jpg,media_type:image,modification_time:1614357237})).
assert(item_('dir_1/dir_b/file_middle',file{abs_path:'dir_1/dir_b/file_middle',access_time:1614729192,change_time:1614727992,creation_time:1604270317,file_size:7823156,filename_extension:png,media_type:image,modification_time:1614372799})).
assert(item_('dir_1/dir_b/file_new',file{abs_path:'dir_1/dir_b/file_new',access_time:1614378004,change_time:1614378004,creation_time:1604570361,file_size:897234,filename_extension:jpg,media_type:image,modification_time:1614372800})).
assert(item_('dir_2/dir_a/dir_i',directory{abs_path:'dir_2/dir_a/dir_i',creation_time:734623467})).
assert(item_('dir_2/dir_a/dir_i/file_old',file{abs_path:'dir_2/dir_a/dir_i/file_old',access_time:934467403,change_time:734646740,creation_time:734634670,file_size:72346,filename_extension:csv,media_type:other,modification_time:734646740})).
assert(item_('dir_2/dir_a/dir_i/file_middle',file{abs_path:'dir_2/dir_a/dir_i/file_middle',access_time:746474048,change_time:746474048,creation_time:746234617,file_size:234842,filename_extension:pdf,media_type:pdf,modification_time:746474048})).
assert(item_('dir_2/dir_a/dir_i/file_new',file{abs_path:'dir_2/dir_a/dir_i/file_new',access_time:746475489,change_time:746475489,creation_time:734623472,file_size:145678,filename_extension:jpg,media_type:image,modification_time:746474489})).
[
{"endpoint": "bg/add"},
{"endpoint": "bg/remove"},
{"endpoint": "irrelevant/file"}
{"endpoint": "irrelevant/file"},
{"endpoint": "explain"}
]
......@@ -37,5 +37,13 @@
{"endpoint": "irrelevant/file", "forbidden_method": "DELETE"},
{"endpoint": "irrelevant/file", "forbidden_method": "OPTIONS"},
{"endpoint": "irrelevant/file", "forbidden_method": "TRACE"},
{"endpoint": "irrelevant/file", "forbidden_method": "PATCH"}
{"endpoint": "irrelevant/file", "forbidden_method": "PATCH"},
{"endpoint": "explain", "forbidden_method": "GET"},
{"endpoint": "explain", "forbidden_method": "HEAD"},
{"endpoint": "explain", "forbidden_method": "PUT"},
{"endpoint": "explain", "forbidden_method": "DELETE"},
{"endpoint": "explain", "forbidden_method": "OPTIONS"},
{"endpoint": "explain", "forbidden_method": "TRACE"},
{"endpoint": "explain", "forbidden_method": "PATCH"}
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment