File size: 2,690 Bytes
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
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
from firebase_admin import firestore
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(autouse=True)
def modify_mmcv_image():
    site_packages_path = get_site_packages()
    dirList = os.listdir(site_packages_path)
    if "mmcv" in dirList:
        shutil.copyfile("libs/image.py", os.path.join(site_packages_path, "mmcv/visualization/image.py"))
    else:
        pytest.exit('Error: Cannot modified mmcv.Image')
        
@pytest.fixture
def client():
    client = TestClient(app, "http://0.0.0.0:3000")
    yield client
@pytest.fixture
def token():
    token = ""
    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