diff --git a/tests/acceptance_test.sh b/tests/acceptance_test.sh new file mode 100755 index 0000000..3d408d5 --- /dev/null +++ b/tests/acceptance_test.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +declare -a arr PACK=( + "prettytable" + "delorean" + "snowballstemmer" + "wget" + "sh" + "fuzzywuzzy" + "progressbar" + "uuid" + "bashplotlib" +) + +echo Start tests +installed=0 +failed=0 +correct=0 + +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' + +for i in "${PACK[@]}" +do + echo "Check: $i" + python -c "import $i" &> /dev/null + if [ $? -eq 0 ]; then + echo "$i already installed" + ((installed++)) + else + python -c "import $i" &> /dev/null + if [ $? -eq 0 ]; then + printf "${GREEN}$i installed correctly${NC}\n" + ((correct++)) + else + printf "${RED}$i FAILED${NC}\n" + ((failed++)) + fi + fi +done + +printf "installed: $installed, ${GREEN}correct: $correct${NC}, ${RED}failed: $failed${NC}\n" + +if [ $failed -eq 0 ] +then + exit 0 +else + exit 1 +fi diff --git a/tests/readme.md b/tests/readme.md new file mode 100644 index 0000000..9bc98f9 --- /dev/null +++ b/tests/readme.md @@ -0,0 +1,6 @@ +The acceptance test runs several python scripts that simply import some uninstalled libraries. +The Data Powered Crash Solver is supposed to install those missing libraries. After the DPCS has installed the library, the test runs the python script again to find out if the library was installed correctly. + +Note that the tests assume that the DPCS works automatically. + +Test_api is a temporary file that perhaps will be used to create complete unit tests of the API. diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..455778d --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,31 @@ +import requests, json, collections + +# api adress +api_url = "http://private-a6e53-dpcs.apiary-mock.com" + + +class MyClient: + service_url = api_url + def do_get(self, suffix): + return requests.get(self.service_url + suffix).json() + + +client = MyClient() +# print(client.do_get("/vd1/crash-reports/1")) +service_url = api_url + +def do_get(self, suffix): + return requests.get(self.service_url + suffix).json() + +data = {} +data['crash-reports'] = 'vd1/crash-reports/' +data['crash-groups'] = 'vd1/crash-groups/' +data['solutions'] = 'vd1/solutions/' +json_test = json.dumps(data) + +client = MyClient() +json_from_api = client.do_get("/vd1/paths/") + +json_test_object = json.loads(json_test) + +assert json_test_object == json_from_api