Commit 5d812cb4 authored by adam's avatar adam

Basic endpoint testing

parent f11fca4f
......@@ -2,7 +2,7 @@ import requests
import json
import os
SCENARIOS_PATH = "./scenarios/";
SCENARIOS_PATH = "scenarios/";
class Test:
......@@ -14,7 +14,7 @@ class Test:
if scenario.get("method") == "GET":
self.send_get_request(scenario)
elif scenario.get("method") == "POST":
self.send_post_request
self.send_post_request(scenario)
else:
print "Skipping ", scenario["name"], " please specify request method."
......@@ -37,12 +37,16 @@ class Test:
return
if res.status_code == 200:
if scenario.get("expected_output"):
if scenario.get("expected_output") != None:
if scenario.get("expected_output") == res.json():
print "Test {0} OK!".format(scenario["name"])
return
else:
print "Test {0}, expected {1} but got {2}!".format(scenario["name"],
scenario["expected_output"], res.json())
else:
print "Test {0} OK!".format(scenario["name"])
else:
print "Test {0} failed!".format(scenario["name"])
def send_post_request(self, scenario):
if scenario.get("user"):
......@@ -50,19 +54,23 @@ class Test:
else:
auth = None
res = requests.path(scenario["url"], auth=auth, data=scenario.get("payload"))
res = requests.post(scenario["url"], auth=auth, data=scenario.get("payload"))
if res.status_code == 200:
if scenario.get("expected_output"):
if scenario.get("expected_output") != None:
if scenario.get("expected_output") == res.json():
print "Test {0} OK!".format(scenario["name"])
return
else:
print "Test {0}, expected {1} but got {2}!".format(scenario["name"],
scenario["expected_output"], res.json())
else:
print "Test {0} OK!".format(scenario["name"])
else:
print "Test {0} failed!".format(scenario["name"])
test = Test()
file_path = os.path.join(os.path.dirname(__file__), SCENARIOS_PATH)
test.load_test_scenarios(SCENARIOS_PATH)
test = Test()
test.load_test_scenarios(file_path)
test.run()
{
"name": "'Auth api' is up",
"description": "This scenario checks if auth api is up and working",
"url": "http://localhost:8080/api/v1/auth",
"method": "GET",
"user": {
"login":"rosiu1",
"password":"rosiu321"
}
}
{
"name": "Login_page_up",
"name": "'Login' page is up",
"description": "Checks if login page is up",
"method": "GET",
"url": "http://localhost:8080/"
......
{
"name": "'Solutions completed' page is up",
"description": "Checks if solutions completed returns empty list",
"method": "GET",
"url": "http://localhost:8080/api/v1/solutions/completed",
"expected_output": [],
"user": {
"login":"rosiu1",
"password": "rosiu321"
}
}
{
"name": "'My solutions' page is up",
"description": "Checks if my solutions retuns empty object",
"method": "GET",
"url": "http://localhost:8080/api/v1/solutions/my",
"user": {
"login": "rosiu1",
"password": "rosiu321"
}
}
{
"name": "'Submit flag'",
"description": "Submits flag, if test wil be ran 2 times without pruging database it will fail (one flag cannot be submited more that once)",
"url": "http://localhost:8080/api/v1/solutions/1/",
"method": "POST",
"user": {
"login":"rosiu1",
"password":"rosiu321"
},
"payload": "459fffa9c2211f96df77c7d8ff72f2b7"
}
{
"name": "'Tasks' api page is up",
"description": "This scenario checks if tasks endpoint is up and working.",
"url": "http://localhost:8080/api/v1/tasks",
"method": "GET",
"expected_output": [{"name":"Szyfro1","level":1},{"name":"Szyfro2","level":2},{"name":"SQL Injection","level":3},{"name":"Inna dziura","level":4}]
}
{
"name": "'Teams' page is up",
"description": "This is scenario checks if teams resources have been correctly populated.",
"url": "http://localhost:8080/api/v1/teams",
"method": "GET",
"expected_output": [{"name":"misiaczki","description":"misiaczki opis","members":[{"name":"gpietrus1","password":"41b450e73c974fca46911eba84e114f2","email":"gpietrusza@gmail.com","admin":false},{"name":"mehow1","password":"c4d24515428cb3ad50e7840be8718f23","email":"mehow@gmail.com","admin":false},{"name":"rosiu1","password":"188ed9df2dac8e10f5c5fd2e02383765","email":"rosiu@gmail.com","admin":false},{"name":"anteq1","password":"1a7fcdd5a9fd433523268883cfded9d0","email":"antonigrzanka@gmail.com","admin":false}]},{"name":"prosiaczki","description":"prosiaczki opis","members":[{"name":"gpietrus2","password":"41b450e73c974fca46911eba84e114f2","email":"gpietrusza@gmail.com","admin":false},{"name":"mehow2","password":"c4d24515428cb3ad50e7840be8718f23","email":"mehow@gmail.com","admin":false},{"name":"rosiu2","password":"188ed9df2dac8e10f5c5fd2e02383765","email":"rosiu@gmail.com","admin":false},{"name":"anteq2","password":"1a7fcdd5a9fd433523268883cfded9d0","email":"antonigrzanka@gmail.com","admin":false}]},{"name":"dupeczki","description":"dupeczki opis","members":[{"name":"gpietrus3","password":"41b450e73c974fca46911eba84e114f2","email":"gpietrusza@gmail.com","admin":false},{"name":"mehow3","password":"c4d24515428cb3ad50e7840be8718f23","email":"mehow@gmail.com","admin":false},{"name":"rosiu3","password":"188ed9df2dac8e10f5c5fd2e02383765","email":"rosiu@gmail.com","admin":false},{"name":"anteq3","password":"1a7fcdd5a9fd433523268883cfded9d0","email":"antonigrzanka@gmail.com","admin":false}]}]
}
{
"name": "'Who am I' is up",
"description": "This is scenario checks if who_am_i endpoint is up and working",
"url": "http://localhost:8080/api/v1/whoami",
"method": "GET",
"user": {
"login":"rosiu1",
"password": "rosiu321"
},
"expected_output": {"userName":"rosiu1","teamName":"misiaczki"}
}
Markdown is supported
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