-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from IanCa/develop
Add a basic web services test(using deploy)
- Loading branch information
Showing
4 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Test service routes externally | ||
|
||
# Todo: May want to tweak what branches this runs on | ||
on: | ||
push: | ||
branches: ["*"] | ||
|
||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest] | ||
python-version: [3.9] | ||
|
||
runs-on: ${{ matrix.platform }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Make the script files executable | ||
run: chmod +x deploy_hed_dev/deploy.sh | ||
|
||
- name: Execute a script from the repository | ||
run: | | ||
cd deploy_hed_dev | ||
./deploy.sh | ||
cd .. | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies(using develop hed-python) | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install requests | ||
- name: Run service tests | ||
run: python -m unittest discover tests_services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
attrs==21.4.0 | ||
attrs>=21.4.0 | ||
Pygments==2.12.0 | ||
click==8.1.3 | ||
coverage>=6.3.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
attrs==21.4.0 | ||
attrs>=21.4.0 | ||
Pygments==2.12.0 | ||
click==8.1.3 | ||
coverage>=6.3.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
import unittest | ||
import requests | ||
import re | ||
|
||
|
||
HED_SERVER_URL_KEY = "HED_SERVER_URL_KEY" | ||
|
||
BASEURL = os.environ.get(HED_SERVER_URL_KEY, "http://127.0.0.1:33004/hed_dev") | ||
|
||
|
||
class Test(unittest.TestCase): | ||
def _get_path(self, filename): | ||
filename_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../tests/data/") | ||
return os.path.join(filename_path, filename) | ||
|
||
def _get_file_string(self, filename): | ||
filename = self._get_path(filename) | ||
with open(filename, 'rb') as fp: | ||
filename_string = fp.read().decode('ascii') | ||
|
||
return filename_string | ||
|
||
def _get_csrf_token(self): | ||
url = BASEURL | ||
response = requests.get(url) | ||
self.assertEqual(response.status_code, 200, "Get should be successful") | ||
header = response.headers | ||
cookie = header["Set-cookie"] | ||
csrf_token = re.search('let csrf_token = "(.*?)"', response.text) | ||
if not csrf_token: | ||
raise ValueError("No csrf token found on page") | ||
csrf_token = str(csrf_token.group(1)) | ||
return cookie, csrf_token | ||
|
||
def _get_headers(self): | ||
cookie, csrf_token = self._get_csrf_token() | ||
headers = { | ||
'X-CSRFToken': csrf_token, | ||
'Cookie': cookie | ||
} | ||
return headers | ||
|
||
def test_submit_service_sidecar_route(self): | ||
print("running test!") | ||
url = f"{BASEURL}/services_submit" | ||
|
||
headers = self._get_headers() | ||
json_data = {"sidecar_string": self._get_file_string("bids_events.json"), | ||
"check_for_warnings": 'on', | ||
"schema_version": '8.2.0', | ||
"service": 'sidecar_validate'} | ||
response = requests.post(url, json=json_data, headers=headers) | ||
self.assertEqual(response.status_code, 200, "Request should be successful") | ||
response_data = response.json() | ||
results = response_data["results"] | ||
self.assertEqual('success', results['msg_category'], | ||
"Expected message category to be 'success'") | ||
self.assertEqual('"8.2.0"', results['schema_version'], | ||
"Expected version 8.2.0 was used") | ||
|
||
|