-
Notifications
You must be signed in to change notification settings - Fork 0
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 #14 from sdslabs/api_test
feat: added api_test
- Loading branch information
Showing
13 changed files
with
4,418 additions
and
2,548 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,37 @@ | ||
name: Python CI | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.7 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
- name: Install PostgreSQL 10 client | ||
run: | | ||
sudo apt-get -yqq install libpq-dev | ||
- name: Install libexempi3 | ||
run: | | ||
sudo apt-get install -y libexempi3 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install pytest && pip install requests | ||
- name: Start docker | ||
run: | | ||
docker container prune -f | ||
docker-compose up -d | ||
bash -c 'while [[ "$(curl --insecure -s -o /dev/null -w ''%{http_code}'' http://localhost:8005/api/v1/departments)" != "200" ]]; do sleep 10 && docker logs studyportal-nexus; done' | ||
./ingest.sh | ||
bash -c 'while [[ "$(curl --insecure -s -o /dev/null -w ''%{http_code}'' http://localhost:8005/api/v1/search/?q=test)" != "200" ]]; do sleep 5; done' | ||
- name: Run Tests | ||
run: | | ||
pytest |
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 @@ | ||
name: Normalize Repos | ||
name: Lint Test | ||
on: | ||
push: | ||
|
||
|
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
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
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,87 @@ | ||
import os | ||
import json | ||
import pytest | ||
import requests | ||
from studyportal.settings import CUR_DIR | ||
|
||
NEXUS_URL = 'http://localhost:8005/api/v1/' | ||
RESOURCES = os.path.join( | ||
CUR_DIR, | ||
'test/resources/rest_api' | ||
) | ||
|
||
|
||
class TestRestApi(): | ||
|
||
def test_get_department_by_abbr(self): | ||
with open(os.path.join(RESOURCES, 'sample_department_response.json')) as f: | ||
expected_response = json.load(f) | ||
r = requests.get(url=NEXUS_URL + 'departments/?department=ASED&format=json') | ||
actual_response = r.json() | ||
assert actual_response == expected_response | ||
|
||
def test_post_department(self): | ||
data = { | ||
'title': 'dep', | ||
'abbreviation': 'DEP', | ||
'imageurl': 'DEP.svg' | ||
} | ||
r = requests.post(url=NEXUS_URL + 'departments', data=data) | ||
assert r.status_code == 200 | ||
|
||
def test_get_courses_by_department(self): | ||
with open(os.path.join(RESOURCES, 'sample_course_list_response.json')) as f: | ||
expected_response = json.load(f) | ||
r = requests.get(url=NEXUS_URL + 'courses/?course=null&department=118&format=json') | ||
actual_response = r.json() | ||
assert actual_response == expected_response | ||
|
||
def test_get_course_by_code(self): | ||
with open(os.path.join(RESOURCES, 'sample_course_response.json')) as f: | ||
expected_response = json.load(f) | ||
r = requests.get(url=NEXUS_URL + 'courses/?course=ASN-700&department=118&format=json') | ||
actual_response = r.json() | ||
assert actual_response == expected_response | ||
|
||
def test_post_course(self): | ||
data = { | ||
'title': 'cour', | ||
'department': '120', | ||
'code': 'COU-000' | ||
} | ||
r = requests.post(url=NEXUS_URL + 'courses', data=data) | ||
assert r.status_code == 200 | ||
|
||
def test_get_files_by_course(self): | ||
with open(os.path.join(RESOURCES, 'sample_files_response.json')) as f: | ||
expected_response = json.load(f) | ||
r = requests.get(url=NEXUS_URL + 'files/?course=1251&filetype=null&format=json') | ||
actual_response = r.json() | ||
assert actual_response == expected_response | ||
|
||
def test_get_files_by_type(self): | ||
with open(os.path.join(RESOURCES, 'sample_files_response.json')) as f: | ||
expected_response = json.load(f) | ||
r = requests.get(url=NEXUS_URL + 'files/?course=1251&filetype=exampapers&format=json') | ||
actual_response = r.json() | ||
assert actual_response == expected_response | ||
|
||
def test_post_file(self): | ||
data = { | ||
'title': 'pdf.pdf', | ||
'driveid': '123456789', | ||
'downloads': 0, | ||
'size': '123545', | ||
'code': 'ARN-101', | ||
'filetype': 'tutorials', | ||
'finalized': 'True' | ||
} | ||
r = requests.post(url=NEXUS_URL + 'files', data=data) | ||
assert r.status_code == 200 | ||
|
||
def test_search(self): | ||
with open(os.path.join(RESOURCES, 'sample_search_response.json')) as f: | ||
expected_response = json.load(f) | ||
r = requests.get(url=NEXUS_URL + 'search/?q=test&format=json') | ||
actual_response = r.json() | ||
assert actual_response == expected_response |
This file was deleted.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
studyportal/test/resources/rest_api/sample_course_list_response.json
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,24 @@ | ||
[ | ||
{ | ||
"id": 1251, | ||
"title": "SEMINAR", | ||
"department": { | ||
"id": 118, | ||
"title": "Applied Science and Engineering", | ||
"abbreviation": "ASED", | ||
"imageurl": "ased.png" | ||
}, | ||
"code": "ASN-700" | ||
}, | ||
{ | ||
"id": 1250, | ||
"title": "Advanced Characterization Techniques", | ||
"department": { | ||
"id": 118, | ||
"title": "Applied Science and Engineering", | ||
"abbreviation": "ASED", | ||
"imageurl": "ased.png" | ||
}, | ||
"code": "AS-901" | ||
} | ||
] |
13 changes: 13 additions & 0 deletions
13
studyportal/test/resources/rest_api/sample_course_response.json
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,13 @@ | ||
[ | ||
{ | ||
"id": 1251, | ||
"title": "SEMINAR", | ||
"department": { | ||
"id": 118, | ||
"title": "Applied Science and Engineering", | ||
"abbreviation": "ASED", | ||
"imageurl": "ased.png" | ||
}, | ||
"code": "ASN-700" | ||
} | ||
] |
32 changes: 32 additions & 0 deletions
32
studyportal/test/resources/rest_api/sample_department_response.json
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,32 @@ | ||
{ | ||
"department": { | ||
"id": 118, | ||
"title": "Applied Science and Engineering", | ||
"abbreviation": "ASED", | ||
"imageurl": "ased.png" | ||
}, | ||
"courses": [ | ||
{ | ||
"id": 1251, | ||
"title": "SEMINAR", | ||
"department": { | ||
"id": 118, | ||
"title": "Applied Science and Engineering", | ||
"abbreviation": "ASED", | ||
"imageurl": "ased.png" | ||
}, | ||
"code": "ASN-700" | ||
}, | ||
{ | ||
"id": 1250, | ||
"title": "Advanced Characterization Techniques", | ||
"department": { | ||
"id": 118, | ||
"title": "Applied Science and Engineering", | ||
"abbreviation": "ASED", | ||
"imageurl": "ased.png" | ||
}, | ||
"code": "AS-901" | ||
} | ||
] | ||
} |
Oops, something went wrong.