-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 只測試各端點是否能夠正常回傳 `200: OK` 的 http 回應,不包含特殊測資測試
- Loading branch information
Showing
13 changed files
with
418 additions
and
0 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,48 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
from src.api import schemas | ||
|
||
client = TestClient(app) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, status_code", | ||
[ | ||
("/buses/main", 200), | ||
("/buses/main/info/toward_main_gate", 200), | ||
("/buses/main/info/toward_tsmc_building", 200), | ||
("/buses/main/schedules/weekday/toward_main_gate", 200), | ||
("/buses/main/schedules/weekday/toward_tsmc_building", 200), | ||
("/buses/main/schedules/weekend/toward_main_gate", 200), | ||
("/buses/main/schedules/weekend/toward_tsmc_building", 200), | ||
("/buses/nanda", 200), | ||
("/buses/nanda/info/toward_main_campus", 200), | ||
("/buses/nanda/info/toward_south_campus", 200), | ||
("/buses/nanda/schedules/weekday/toward_main_campus", 200), | ||
("/buses/nanda/schedules/weekday/toward_south_campus", 200), | ||
("/buses/nanda/schedules/weekend/toward_main_campus", 200), | ||
("/buses/nanda/schedules/weekend/toward_south_campus", 200), | ||
], | ||
) | ||
def test_buses_endpoints(url, status_code): | ||
response = client.get(url=url) | ||
assert response.status_code == status_code | ||
|
||
|
||
@pytest.mark.parametrize("stop_name", [_.value for _ in schemas.buses.StopsName]) | ||
@pytest.mark.parametrize("bus_type", [_.value for _ in schemas.buses.BusType]) | ||
@pytest.mark.parametrize("day", [_.value for _ in schemas.buses.BusDay]) | ||
@pytest.mark.parametrize("direction", [_.value for _ in schemas.buses.BusDirection]) | ||
def test_buses_stops(stop_name, bus_type, day, direction): | ||
response = client.get(url=f"/buses/stops/{stop_name}/{bus_type}/{day}/{direction}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("bus_type", [_.value for _ in schemas.buses.BusType]) | ||
@pytest.mark.parametrize("day", [_.value for _ in schemas.buses.BusDay]) | ||
@pytest.mark.parametrize("direction", [_.value for _ in schemas.buses.BusDirection]) | ||
def test_buses_detailed(bus_type, day, direction): | ||
response = client.get(url=f"/buses/detailed/{bus_type}/{day}/{direction}") | ||
assert response.status_code == 200 |
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,10 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_careers(): | ||
response = client.get(url="/resources/careers/bulletin/recruitment") | ||
assert response.status_code == 200 |
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,36 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
|
||
client = TestClient(app) | ||
id_list = [ | ||
"7e00db83-b407-4320-af55-0a1b1f5734ad", | ||
"8dfa4f30-2339-4ec2-aee9-0da58e78fdde", | ||
"ed3ac738-8102-43fb-844c-3abbd5f493d8", | ||
"4955571d-ec87-4c8f-bc39-c3b39142558c", | ||
] | ||
name_list = ["清華學院", "理學院", "主計"] | ||
|
||
|
||
def test_contacts(): | ||
response = client.get(url=f"/contacts") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("id", id_list) | ||
def test_contacts_id(id): | ||
response = client.get(url=f"/contacts/{id}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("name", name_list) | ||
def test_contacts_name(name): | ||
response = client.get(url=f"/contacts/searches/{name}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("name", name_list) | ||
def test_contacts_name_post(name): | ||
response = client.post(url="/contacts/searches/", json={"name": name}) | ||
assert response.status_code == 200 |
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 pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
from src.api import schemas | ||
|
||
client = TestClient(app) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, status_code", | ||
[ | ||
("/courses/", 200), | ||
("/courses/fields/info", 200), | ||
("/courses/lists/16weeks", 200), | ||
("/courses/lists/microcredits", 200), | ||
("/courses/lists/xclass", 200), | ||
], | ||
) | ||
def test_courses_endpoints(url, status_code): | ||
response = client.get(url=url) | ||
assert response.status_code == status_code | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"field_name", [_.value for _ in schemas.courses.CourseFieldName] | ||
) | ||
def test_courses_fields(field_name): | ||
response = client.get(url=f"/courses/fields/{field_name}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"field_name", [_.value for _ in schemas.courses.CourseFieldName] | ||
) | ||
@pytest.mark.parametrize("value", ["testing"]) | ||
def test_courses_fields(field_name, value): | ||
response = client.get(url=f"/courses/fields/{field_name}/{value}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"field_name", [_.value for _ in schemas.courses.CourseFieldName] | ||
) | ||
@pytest.mark.parametrize("value", ["testing"]) | ||
def test_courses_search(field_name, value): | ||
response = client.get(url=f"/courses/searches?field={field_name}&value={value}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("path", ["id", "classroom", "time", "teacher"]) | ||
@pytest.mark.parametrize("value", ["testing"]) | ||
def test_courses_search_extension(path, value): | ||
response = client.get(url=f"/courses/searches/{path}/{value}") | ||
assert response.status_code == 404 | ||
|
||
|
||
@pytest.mark.parametrize("path", ["credits"]) | ||
@pytest.mark.parametrize("op", ["gt", "lt", "gte", "lte"]) | ||
def test_courses_search_credits(path, op): | ||
response = client.get(url=f"/courses/searches/{path}/3?op={op}") | ||
assert response.status_code == 200 |
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,18 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, status_code", | ||
[ | ||
("/", 200), | ||
("/ping", 200), | ||
], | ||
) | ||
def test_default_endpoints(url, status_code): | ||
response = client.get(url=url) | ||
assert response.status_code == status_code |
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,63 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
from src.api import schemas | ||
|
||
client = TestClient(app) | ||
restaurant_name_list = [ | ||
"麥當勞", | ||
"紅燒如意坊", | ||
"茗釀茶品", | ||
"蘇記食堂", | ||
"友記快餐館", | ||
"蘇記牛肉麵", | ||
"帕森義大利麵", | ||
"顏記文昌雞", | ||
"家味燒臘", | ||
"喜番咖哩", | ||
"牛肉先生", | ||
"墨尼捲餅", | ||
"珍御品粥麵館", | ||
] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, status_code", | ||
[ | ||
("/dining/", 200), | ||
("/dining/buildings", 200), | ||
("/dining/restaurants", 200), | ||
], | ||
) | ||
def test_dining_endpoints(url, status_code): | ||
response = client.get(url=url) | ||
assert response.status_code == status_code | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"building_name", [_.value for _ in schemas.dining.DiningBuildingName] | ||
) | ||
def test_dining_buildings(building_name): | ||
response = client.get(url=f"/dining/buildings/{building_name}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("restaurant_name", restaurant_name_list) | ||
def test_dining_restaurants(restaurant_name): | ||
response = client.get(url=f"/dining/restaurants/{restaurant_name}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"day_of_week", [_.value for _ in schemas.dining.DiningSceduleName] | ||
) | ||
def test_dining_schedules(day_of_week): | ||
response = client.get(url=f"/dining/scedules/{day_of_week}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("restaurant_name", restaurant_name_list) | ||
def test_dining_searches_restaurants(restaurant_name): | ||
response = client.get(url=f"/dining/searches/restaurants/{restaurant_name}") | ||
assert response.status_code == 200 |
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,10 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_energy(): | ||
response = client.get(url="/energy/electricity_usage") | ||
assert response.status_code == 200 |
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 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, status_code", | ||
[ | ||
("/resources/events/libarys", 200), | ||
("/resources/events/goodjob", 200), | ||
("/resources/events/arts_center", 200), | ||
("/resources/events/global_affairs", 200), | ||
("/resources/events/health_center", 200), | ||
("/resources/events/bulletin/art_and_cultural", 200), | ||
("/resources/events/bulletin/academic", 200), | ||
("/resources/events/bulletin/academic", 200), | ||
], | ||
) | ||
def test_events_endpoints(url, status_code): | ||
response = client.get(url=url) | ||
assert response.status_code == status_code |
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,34 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
from src.api import schemas | ||
|
||
client = TestClient(app) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, status_code", | ||
[ | ||
("/libraries/space", 200), | ||
("/libraries/lost_and_found", 200), | ||
("/libraries/goods", 200), | ||
], | ||
) | ||
def test_libraries_endpoints(url, status_code): | ||
response = client.get(url=url) | ||
assert response.status_code == status_code | ||
|
||
|
||
@pytest.mark.parametrize("rss", [_.value for _ in schemas.resources.LibraryRssType]) | ||
def test_libraries_rss(rss): | ||
response = client.get(url=f"/libraries/rss/{rss}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"library_name", [_.value for _ in schemas.resources.LibraryName] | ||
) | ||
def test_libraries_openinghours(library_name): | ||
response = client.get(url=f"/libraries/openinghours/{library_name}") | ||
assert response.status_code == 200 |
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,35 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
|
||
client = TestClient(app) | ||
id_list = [ | ||
"b876aa09-40a8-427b-8bc7-1933978690e2", | ||
"6db26190-de4d-4d45-ae25-dccc5e47d795", | ||
"66e128f8-f457-489e-bbc4-b631ddc5edef", | ||
] | ||
name_list = ["校門", "產業", "綜合", "台積", "台達"] | ||
|
||
|
||
def test_locations(): | ||
response = client.get(url="/locations") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("id", id_list) | ||
def test_locations_id(id): | ||
response = client.get(url=f"/locations/{id}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("name", name_list) | ||
def test_locations_name(name): | ||
response = client.get(url=f"/locations/searches/{name}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("name", name_list) | ||
def test_locations_searches(name): | ||
response = client.post(url="/locations/searches", json={"name": name}) | ||
assert response.status_code == 200 |
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,29 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from src import app | ||
from src.api import schemas | ||
|
||
client = TestClient(app) | ||
newsletter_link_list = [ | ||
"https://newsletter.cc.nthu.edu.tw/nthu-list/index.php/zh/home-zh-tw/listid-44-" | ||
] | ||
|
||
|
||
def test_newsletter(): | ||
response = client.get(url=f"/newsletter/") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"newsletter_name", [_.value for _ in schemas.newsletter.NewsletterName] | ||
) | ||
def test_newsletter_searches(newsletter_name): | ||
response = client.get(url=f"/newsletters/{newsletter_name}") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("newsletter_link", newsletter_link_list) | ||
def test_newsletter_paths_link(newsletter_link): | ||
response = client.get(url=f"/newsletters/paths/{newsletter_link}") | ||
assert response.status_code == 200 |
Oops, something went wrong.