{"id":526,"date":"2024-02-05T14:43:10","date_gmt":"2024-02-05T14:43:10","guid":{"rendered":"https:\/\/fip.r-a-w.org\/?p=526"},"modified":"2024-02-05T14:43:10","modified_gmt":"2024-02-05T14:43:10","slug":"kup-assessments-bash-scripts-to-test-endpoints","status":"publish","type":"post","link":"https:\/\/fip.r-a-w.org\/?p=526","title":{"rendered":"KUP Assessments &#8211; Bash scripts to test endpoints"},"content":{"rendered":"\n<p>For integration testing and the testing of endpoints I have previously indicated I am going to use a bash script of curl commands to achieve this. The first iteration of the script is given below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\n\n#URI's\nbaseURI=\"http:\/\/localhost:8080\/kupassessments\/\"\ncreate=\"account\/create\/\"\n\n#test the index url\nresponseIndexPage=$(curl --write-out \"%{http_code}\\n\" --silent --output \/dev\/null $baseURI) 2>\/dev\/null\n#test the creation of an account\nresponseAccountCreation=$(curl --write-out \"%{http_code}\\n\" --silent --data \"username=Boot&amp;email=boot@r-a-w.org\" --output \/dev\/null $baseURI$create) 2>\/dev\/null\necho Bash Script Test of KUPassessments\n#result of testing the index page\necho Index Page response: $responseIndexPage\necho Create AccountResponse: $responseAccountCreation\n<\/code><\/pre>\n\n\n\n<p>The resulting output is:<\/p>\n\n\n\n<p>Bash Script Test of KUPassessments<br> Index Page response: 200<br> Create AccountResponse: 404<\/p>\n\n\n\n<p>The 404 is because the query does not contain any data. I also will have run  a an SQL script to reset the database. <\/p>\n\n\n\n<p>The database is cleared using the following script ClearAccountTestingData.sql<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>delete from accounts where username='boot';\n<\/code><\/pre>\n\n\n\n<p>This needs to be run each time the bash script starts to ensure that the database is in a state that is expected for the tests. However this needs the location of the script to be included. So it may be best to execute the the SQL from the testing bash script.<\/p>\n\n\n\n<p>Now I have noticed that the second error is not, in fact due to the data already existing but the fact that the request is incorrect. From searching round the request needs to be rewritten so it sends the request in json. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">resources:<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.shellhacks.com\/mysql-run-query-bash-script-linux-command-line\/\">https:\/\/www.shellhacks.com\/mysql-run-query-bash-script-linux-command-line\/<\/a><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For integration testing and the testing of endpoints I have previously indicated I am going to use a bash script of curl commands to achieve this. The first iteration of the script is given below: The resulting output is: Bash Script Test of KUPassessments Index Page response: 200 Create AccountResponse: 404 The 404 is because &hellip; <a href=\"https:\/\/fip.r-a-w.org\/?p=526\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">KUP Assessments &#8211; Bash scripts to test endpoints<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-526","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9NvWe-8u","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=\/wp\/v2\/posts\/526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=526"}],"version-history":[{"count":11,"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions"}],"predecessor-version":[{"id":556,"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions\/556"}],"wp:attachment":[{"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fip.r-a-w.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}