add: more tests

This commit is contained in:
Tobias Reisinger 2020-08-29 09:10:50 +02:00
parent 6728ef9264
commit 4dd8329484
5 changed files with 166 additions and 42 deletions

View file

@ -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
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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"