Spaces:
Runtime error
Runtime error
Merge pull request #6 from HunyyDev/NMPhap/testing
Browse files- app/constants.py +2 -0
- app/dependencies.py +1 -1
- app/requirements.txt +1 -0
- app/routers/test_image.py +8 -1
- app/test_main.py +82 -0
app/constants.py
CHANGED
@@ -166,3 +166,5 @@ classNames = [
|
|
166 |
"hair drier",
|
167 |
"toothbrush",
|
168 |
]
|
|
|
|
|
|
166 |
"hair drier",
|
167 |
"toothbrush",
|
168 |
]
|
169 |
+
|
170 |
+
test_uid = "VAbtgG1IrWSOqoJgxe7u2yEqpIg2"
|
app/dependencies.py
CHANGED
@@ -13,7 +13,7 @@ async def get_current_user(
|
|
13 |
credentials_exception = HTTPException(
|
14 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
15 |
detail="Could not validate credentials",
|
16 |
-
headers={"WWW-Authenticate": "Bearer"},
|
17 |
)
|
18 |
try:
|
19 |
payload = auth.verify_id_token(credentials.credentials)
|
|
|
13 |
credentials_exception = HTTPException(
|
14 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
15 |
detail="Could not validate credentials",
|
16 |
+
headers={"WWW-Authenticate": "Bearer "},
|
17 |
)
|
18 |
try:
|
19 |
payload = auth.verify_id_token(credentials.credentials)
|
app/requirements.txt
CHANGED
@@ -10,3 +10,4 @@ supabase==1.0.4
|
|
10 |
uvicorn==0.23.2
|
11 |
python-multipart==0.0.6
|
12 |
firebase_admin==6.2.0
|
|
|
|
10 |
uvicorn==0.23.2
|
11 |
python-multipart==0.0.6
|
12 |
firebase_admin==6.2.0
|
13 |
+
pytest
|
app/routers/test_image.py
CHANGED
@@ -5,12 +5,19 @@ from app.routers.image import inferenceImage
|
|
5 |
import pytest
|
6 |
import pytest
|
7 |
from fastapi.testclient import TestClient
|
|
|
8 |
from app.main import app
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
@pytest.fixture
|
11 |
def client():
|
12 |
client = TestClient(app, "http://0.0.0.0:3000")
|
13 |
yield client
|
|
|
14 |
class TestImageRoute():
|
15 |
img = mmcv.imread('demo.jpg')
|
16 |
url = "http://0.0.0.0:3000/image"
|
|
|
5 |
import pytest
|
6 |
import pytest
|
7 |
from fastapi.testclient import TestClient
|
8 |
+
from fastapi.routing import APIRoute
|
9 |
from app.main import app
|
10 |
+
def endpoints():
|
11 |
+
endpoints = []
|
12 |
+
for route in app.routes:
|
13 |
+
if isinstance(route, APIRoute):
|
14 |
+
endpoints.append(route.path)
|
15 |
+
return endpoints
|
16 |
@pytest.fixture
|
17 |
def client():
|
18 |
client = TestClient(app, "http://0.0.0.0:3000")
|
19 |
yield client
|
20 |
+
@pytest.mark.skipif("/image" not in endpoints(), reason="Route not defined")
|
21 |
class TestImageRoute():
|
22 |
img = mmcv.imread('demo.jpg')
|
23 |
url = "http://0.0.0.0:3000/image"
|
app/test_main.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi.testclient import TestClient
|
2 |
+
import mmcv
|
3 |
+
from app.main import app
|
4 |
+
import pytest
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
import site
|
8 |
+
import shutil
|
9 |
+
from fastapi.routing import APIRoute
|
10 |
+
from app import firebase_app
|
11 |
+
from firebase_admin import firestore
|
12 |
+
def get_site_packages():
|
13 |
+
# Get the list of directories
|
14 |
+
site_packages_dirs = site.getsitepackages()
|
15 |
+
|
16 |
+
# Find the "site-packages" directory in the list
|
17 |
+
for dir in site_packages_dirs:
|
18 |
+
if dir.endswith("site-packages"):
|
19 |
+
target_dir = dir
|
20 |
+
break
|
21 |
+
else:
|
22 |
+
target_dir=None
|
23 |
+
return target_dir
|
24 |
+
|
25 |
+
def endpoints():
|
26 |
+
endpoints = []
|
27 |
+
for route in app.routes:
|
28 |
+
if isinstance(route, APIRoute):
|
29 |
+
endpoints.append(route.path)
|
30 |
+
return endpoints
|
31 |
+
@pytest.fixture(autouse=True)
|
32 |
+
def modify_mmcv_image():
|
33 |
+
site_packages_path = get_site_packages()
|
34 |
+
dirList = os.listdir(site_packages_path)
|
35 |
+
if "mmcv" in dirList:
|
36 |
+
shutil.copyfile("libs/image.py", os.path.join(site_packages_path, "mmcv/visualization/image.py"))
|
37 |
+
else:
|
38 |
+
pytest.exit('Error: Cannot modified mmcv.Image')
|
39 |
+
|
40 |
+
@pytest.fixture
|
41 |
+
def client():
|
42 |
+
client = TestClient(app, "http://0.0.0.0:3000")
|
43 |
+
yield client
|
44 |
+
@pytest.fixture
|
45 |
+
def token():
|
46 |
+
token = ""
|
47 |
+
yield token
|
48 |
+
class TestFireBaseAPI():
|
49 |
+
def test_get_me(self, client, token):
|
50 |
+
if "/me" not in endpoints():
|
51 |
+
pytest.skip("This route isn't defined")
|
52 |
+
else:
|
53 |
+
if token != "":
|
54 |
+
payload = ""
|
55 |
+
headers = {
|
56 |
+
'accept': 'application/json',
|
57 |
+
"Authorization":"Bearer " + token
|
58 |
+
}
|
59 |
+
response = client.request("get", 'me', headers=headers, data=payload)
|
60 |
+
assert response.status_code == 200
|
61 |
+
payload = ""
|
62 |
+
headers = {
|
63 |
+
'accept': 'application/json',
|
64 |
+
'Content-Type': 'application/json',
|
65 |
+
}
|
66 |
+
response = client.request("get", 'me', headers=headers, data=payload)
|
67 |
+
assert response.status_code == 403
|
68 |
+
def test_invitation(self,client, token):
|
69 |
+
if"/invitation" not in endpoints():
|
70 |
+
pytest.skip("This route isn't defined")
|
71 |
+
else:
|
72 |
+
payload = ''
|
73 |
+
headers = {
|
74 |
+
'accept': 'application/json',
|
75 |
+
'Content-Type': 'application/json',
|
76 |
+
"Authorization": "Bearer " + token
|
77 |
+
}
|
78 |
+
response = client.request("post", 'invitation', headers=headers, data=payload)
|
79 |
+
assert response.status_code == 200
|
80 |
+
result = mmcv.imfrombytes(response.read())
|
81 |
+
assert result.shape[0] == 3
|
82 |
+
|