From 4dd83294848ee879894560c636b0c65b80346091 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Sat, 29 Aug 2020 09:10:50 +0200 Subject: [PATCH] add: more tests --- CMakeLists.txt | 46 +++++++------ .../tavern_tests/0.1.test_basics.tavern.yaml | 16 +++++ .../1.1.controller_relays_basic.tavern.yaml | 68 ++++++++++++++++++- tests/tavern_tests/3.0.tags.tavern.yaml | 51 ++++++++++++++ tests/tavern_utils/validate_tag.py | 27 ++------ 5 files changed, 166 insertions(+), 42 deletions(-) create mode 100644 tests/tavern_tests/0.1.test_basics.tavern.yaml diff --git a/CMakeLists.txt b/CMakeLists.txt index a763453..5f6f722 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,21 +43,8 @@ add_custom_target(run DEPENDS core WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) -add_custom_target(debug - COMMAND valgrind -s ./core start - DEPENDS core - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) -add_custom_target(debug-leak - COMMAND valgrind --leak-check=full --show-leak-kinds=all ./core start - DEPENDS core - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) -add_custom_target(debug-callgrind - COMMAND valgrind --tool=callgrind ./core start - DEPENDS core - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) + + add_custom_target(docs COMMAND doxygen WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} @@ -73,8 +60,27 @@ add_custom_target(test-callgrind DEPENDS core WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests ) -add_custom_target(coverage - COMMAND gcovr -s --root ${CMAKE_SOURCE_DIR} -e ${CMAKE_SOURCE_DIR}/vendor --html-details ${CMAKE_BINARY_DIR}/coverage.html --html-title "Emgauwa Core Coverage" ${CMAKE_BINARY_DIR}/CMakeFiles/core.dir - DEPENDS test - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) + +IF(CMAKE_BUILD_TYPE MATCHES DEBUG) + message("debug mode") + add_custom_target(debug + COMMAND valgrind -s ./core start + DEPENDS core + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + add_custom_target(debug-leak + COMMAND valgrind --leak-check=full --show-leak-kinds=all ./core start + DEPENDS core + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + add_custom_target(debug-callgrind + COMMAND valgrind --tool=callgrind ./core start + DEPENDS core + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + add_custom_target(coverage + COMMAND gcovr -s --root ${CMAKE_SOURCE_DIR} -e ${CMAKE_SOURCE_DIR}/vendor --html-details ${CMAKE_BINARY_DIR}/coverage.html --html-title "Emgauwa Core Coverage" ${CMAKE_BINARY_DIR}/CMakeFiles/core.dir + DEPENDS test + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) +ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG) diff --git a/tests/tavern_tests/0.1.test_basics.tavern.yaml b/tests/tavern_tests/0.1.test_basics.tavern.yaml new file mode 100644 index 0000000..14ac8b5 --- /dev/null +++ b/tests/tavern_tests/0.1.test_basics.tavern.yaml @@ -0,0 +1,16 @@ +test_name: "[test_basics] Test basic calls" + +stages: +- name: "[test_basics] get index" + request: + url: "http://localhost:5000/" + method: GET + response: + status_code: 200 + +- name: "[test_basics] get 404" + request: + url: "http://localhost:5000/invalid_url_for_testing_do_not_use" + method: GET + response: + status_code: 404 diff --git a/tests/tavern_tests/1.1.controller_relays_basic.tavern.yaml b/tests/tavern_tests/1.1.controller_relays_basic.tavern.yaml index f0d1750..285d2d5 100644 --- a/tests/tavern_tests/1.1.controller_relays_basic.tavern.yaml +++ b/tests/tavern_tests/1.1.controller_relays_basic.tavern.yaml @@ -26,7 +26,7 @@ stages: extra_kwargs: relay_count: !int "{returned_relay_count:d}" -- name: "[controller_relays_basic] get controller relays, check length" +- name: "[controller_relays_basic] get controller relay" request: method: GET url: "http://localhost:5000/api/v1/controllers/{returned_id}/relays/5" @@ -40,3 +40,69 @@ stages: function: validate_relay:check_number extra_kwargs: number: 5 + +- name: "[controller_relays_basic] get controller relay with invalid uid" + request: + method: GET + url: "http://localhost:5000/api/v1/controllers/INVALID-UUID/relays/5" + response: + status_code: 400 + +- name: "[controller_relays_basic] get controller relay with unavailable uid" + request: + method: GET + url: "http://localhost:5000/api/v1/controllers/00000000-0000-0000-0000-000000000000/relays/5" + response: + status_code: 404 + +- name: "[controller_relays_basic] get controller relay with invalid number" + request: + method: GET + url: "http://localhost:5000/api/v1/controllers/{returned_id}/relays/not_a_number" + response: + status_code: 404 + +- name: "[controller_relays_basic] get controller relay with unavailable number" + request: + method: GET + url: "http://localhost:5000/api/v1/controllers/{returned_id}/relays/9001" + response: + status_code: 404 + + + + +- name: "[controller_relays_basic] pulse relay" + request: + method: POST + url: "http://localhost:5000/api/v1/controllers/{returned_id}/relays/6/pulse" + response: + status_code: 200 + +- name: "[controller_relays_basic] pulse relay with invalid uid" + request: + method: POST + url: "http://localhost:5000/api/v1/controllers/INVALID-UUID/relays/6/pulse" + response: + status_code: 400 + +- name: "[controller_relays_basic] pulse relay with unavailable uid" + request: + method: POST + url: "http://localhost:5000/api/v1/controllers/00000000-0000-0000-0000-000000000000/relays/6/pulse" + response: + status_code: 404 + +- name: "[controller_relays_basic] pulse relay with invalid number" + request: + method: POST + url: "http://localhost:5000/api/v1/controllers/{returned_id}/relays/not_a_number/pulse" + response: + status_code: 404 + +- name: "[controller_relays_basic] pulse relay with unavailable number" + request: + method: POST + url: "http://localhost:5000/api/v1/controllers/{returned_id}/relays/9001/pulse" + response: + status_code: 404 diff --git a/tests/tavern_tests/3.0.tags.tavern.yaml b/tests/tavern_tests/3.0.tags.tavern.yaml index d4ef67f..37734f8 100644 --- a/tests/tavern_tests/3.0.tags.tavern.yaml +++ b/tests/tavern_tests/3.0.tags.tavern.yaml @@ -98,6 +98,13 @@ stages: controller_id: "{returned_id}" tag: "{returned_tag}" +- name: "[tags] get returned tag with relays and schedules" + request: + method: GET + url: "http://localhost:5000/api/v1/tags/{returned_tag}" + response: + status_code: 200 + - name: "[tags] get tags" request: method: GET @@ -106,3 +113,47 @@ stages: status_code: 200 verify_response_with: function: validate_tag:multiple + +- name: "[tags] get unavailable tag" + request: + method: GET + url: "http://localhost:5000/api/v1/tags/invalid_unavailable_tag" + response: + status_code: 404 + +- name: "[tags] post tag" + request: + method: POST + url: "http://localhost:5000/api/v1/tags/" + json: + tag: "unused_tag_1" + response: + status_code: 201 + +- name: "[tags] get posted tag" + request: + method: GET + url: "http://localhost:5000/api/v1/tags/unused_tag_1" + response: + status_code: 200 + +- name: "[tags] delete posted tag" + request: + method: DELETE + url: "http://localhost:5000/api/v1/tags/unused_tag_1" + response: + status_code: 200 + +- name: "[tags] get deleted tag" + request: + method: GET + url: "http://localhost:5000/api/v1/tags/unused_tag_1" + response: + status_code: 404 + +- name: "[tags] delete deleted tag again" + request: + method: DELETE + url: "http://localhost:5000/api/v1/tags/unused_tag_1" + response: + status_code: 404 diff --git a/tests/tavern_utils/validate_tag.py b/tests/tavern_utils/validate_tag.py index 1e907e5..6a3004a 100644 --- a/tests/tavern_utils/validate_tag.py +++ b/tests/tavern_utils/validate_tag.py @@ -11,24 +11,9 @@ def multiple(response): for tag in response.json(): _verify_single(tag) -#def find(response, name=None, number=None, controller_id=None, tag=None): -# print(response.json()) -# for tag in response.json(): -# if number != None and number != tag.get("number"): -# continue -# -# if name != None and name != tag.get("name"): -# continue -# -# if controller_id != None and controller_id != tag.get("controller_id"): -# continue -# -# if tag != None: -# found_in_response = False -# for response_tag in tag.get("tags"): -# if response_tag == tag: -# found_in_response = True -# if not found_in_response: -# continue -# return -# assert False, "tag not found in list" +def find(response, tag): + print(response.json()) + for response_tag in response.json(): + if response_tag == tag: + return + assert False, "tag not found in list"