Spaces:
Runtime error
Runtime error
File size: 2,744 Bytes
206aa5a dc66a7c 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a dc66a7c 73075be dc66a7c 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a 73075be 206aa5a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
from fastapi.testclient import TestClient
import mmcv
from app.main import app
import pytest
import json
import os
import site
import shutil
from fastapi.routing import APIRoute
from app import firebase_app
import requests
def get_site_packages():
# Get the list of directories
site_packages_dirs = site.getsitepackages()
# Find the "site-packages" directory in the list
for dir in site_packages_dirs:
if dir.endswith("site-packages"):
target_dir = dir
break
else:
target_dir = None
return target_dir
def endpoints():
endpoints = []
for route in app.routes:
if isinstance(route, APIRoute):
endpoints.append(route.path)
return endpoints
@pytest.fixture
def client():
client = TestClient(app, "http://0.0.0.0:3000")
yield client
@pytest.fixture
def token():
url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyArSoK9Wx9Hpe1R9ZywuLEIMVjCtHjO8Os"
payload = json.dumps(
{"email": "[email protected]", "password": "testing", "returnSecureToken": True}
)
headers = {"Content-Type": "application/json"}
response = requests.request("POST", url, headers=headers, data=payload)
token = response.json()["idToken"]
yield token
class TestFireBaseAPI:
def test_get_me(self, client, token):
if "/me" not in endpoints():
pytest.skip("This route isn't defined")
else:
if token != "":
payload = ""
headers = {
"accept": "application/json",
"Authorization": "Bearer " + token,
}
response = client.request("get", "me", headers=headers, data=payload)
assert response.status_code == 200
payload = ""
headers = {
"accept": "application/json",
"Content-Type": "application/json",
}
response = client.request("get", "me", headers=headers, data=payload)
assert response.status_code == 403
def test_invitation(self, client, token):
if "/invitation" not in endpoints():
pytest.skip("This route isn't defined")
else:
payload = ""
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer " + token,
}
response = client.request(
"post", "invitation", headers=headers, data=payload
)
assert response.status_code == 200
result = mmcv.imfrombytes(response.read())
assert result.shape[0] == 3
|