phuochungus commited on
Commit
494a6d9
2 Parent(s): 11213cb fd0fc53

Merge branch 'main' of https://github.com/HunyyDev/SE113.O12_KCPM

Browse files
.github/workflows/test.yml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Python Package using Conda
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ pull_request:
7
+ branches:
8
+ - main
9
+ jobs:
10
+ build-linux:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ with:
16
+ lfs: true
17
+ - name: Set up Python 3.8
18
+ uses: actions/setup-python@v3
19
+ with:
20
+ python-version: '3.8'
21
+ - name: install dependency
22
+ run: |
23
+ git lfs checkout
24
+ pip install -r app/requirements.txt
25
+ - name: Run test
26
+ run: pytest
27
+ env:
28
+ SUPABASE_URL: ${{secrets.SUPABASE_URL}}
29
+ SUPABASE_KEY: ${{secrets.SUPABASE_KEY}}
30
+ FIREBASE_CREDENTIALS: ${{secrets.FIREBASE_CREDENTIALS}}
31
+ NEO4J_URI: ${{secrets.NEO4J_URI}}
32
+ NEO4J_USERNAME: ${{secrets.NEO4J_USERNAME}}
33
+ NEO4J_PASSWORD: ${{secrets.NEO4J_PASSWORD}}
34
+ AURA_INSTANCEID: ${{secrets.AURA_INSTANCEID}}
35
+ AURA_INSTANCENAME: ${{secrets.AURA_INSTANCENAME}}
36
+ FIREBASE_API_KEY: ${{secrets.FIREBASE_API_KEY}}
.gitignore CHANGED
@@ -7,3 +7,4 @@ demo
7
  **/*.mp4
8
  **/*.jpg
9
  .pytest_cache
 
 
7
  **/*.mp4
8
  **/*.jpg
9
  .pytest_cache
10
+ !demo.jpg
app/__init__.py CHANGED
@@ -5,6 +5,7 @@ import logging
5
  from dotenv import load_dotenv
6
  from mmdeploy_runtime import Detector
7
  from supabase import create_client, Client
 
8
  from firebase_admin import credentials, initialize_app
9
  from firebase_admin import firestore
10
  from neo4j import GraphDatabase
@@ -26,12 +27,14 @@ key: str = os.environ.get("SUPABASE_KEY")
26
  supabase: Client = create_client(url, key)
27
 
28
  # LOAD FIREBASE ADMIN SDK
29
- firebase_app = initialize_app(
30
- credential=credentials.Certificate(
31
- json.loads(os.environ.get("FIREBASE_CREDENTIALS"))
 
 
32
  )
33
- )
34
-
35
  db = firestore.client()
36
 
37
  # LOAD NEO4J DB
 
5
  from dotenv import load_dotenv
6
  from mmdeploy_runtime import Detector
7
  from supabase import create_client, Client
8
+ import firebase_admin
9
  from firebase_admin import credentials, initialize_app
10
  from firebase_admin import firestore
11
  from neo4j import GraphDatabase
 
27
  supabase: Client = create_client(url, key)
28
 
29
  # LOAD FIREBASE ADMIN SDK
30
+ if not firebase_admin._apps:
31
+ firebase_app = initialize_app(
32
+ credential=credentials.Certificate(
33
+ json.loads(os.environ.get("FIREBASE_CREDENTIALS"))
34
+ )
35
  )
36
+ else:
37
+ firebase_app = firebase_admin._apps
38
  db = firestore.client()
39
 
40
  # LOAD NEO4J DB
app/routers/friend_request.py CHANGED
@@ -9,7 +9,6 @@ from app import db, logger
9
  from enum import Enum
10
  from app.graphdb.main import insert2PersonAndSetFriend
11
 
12
-
13
  router = APIRouter(prefix="/friend_request", tags=["friend_request"])
14
 
15
 
 
9
  from enum import Enum
10
  from app.graphdb.main import insert2PersonAndSetFriend
11
 
 
12
  router = APIRouter(prefix="/friend_request", tags=["friend_request"])
13
 
14
 
app/routers/test_friend_request.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ import json
3
+ import requests
4
+ @pytest.fixture
5
+ def token_inviter():
6
+ url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyArSoK9Wx9Hpe1R9ZywuLEIMVjCtHjO8Os"
7
+
8
+ payload = json.dumps({
9
+ "email": "test@gmail.com",
10
+ "password": "testing",
11
+ "returnSecureToken": True
12
+ })
13
+ headers = {
14
+ 'Content-Type': 'application/json'
15
+ }
16
+ response = requests.request("POST", url, headers=headers, data=payload)
17
+ token = response.json()["idToken"]
18
+ yield token
19
+ @pytest.fixture()
20
+ def token_invitee():
21
+ url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyArSoK9Wx9Hpe1R9ZywuLEIMVjCtHjO8Os"
22
+
23
+ payload = json.dumps({
24
+ "email": "test2@gmail.com",
25
+ "password": "testing2",
26
+ "returnSecureToken": True
27
+ })
28
+ headers = {
29
+ 'Content-Type': 'application/json'
30
+ }
31
+ response = requests.request("POST", url, headers=headers, data=payload)
32
+ token = response.json()["idToken"]
33
+ yield token
app/test_main.py CHANGED
@@ -8,7 +8,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()
@@ -27,23 +27,25 @@ def 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):
 
8
  import shutil
9
  from fastapi.routing import APIRoute
10
  from app import firebase_app
11
+ import requests
12
  def get_site_packages():
13
  # Get the list of directories
14
  site_packages_dirs = site.getsitepackages()
 
27
  for route in app.routes:
28
  if isinstance(route, APIRoute):
29
  endpoints.append(route.path)
30
+ return endpoints
 
 
 
 
 
 
 
 
 
31
  @pytest.fixture
32
  def client():
33
  client = TestClient(app, "http://0.0.0.0:3000")
34
  yield client
35
  @pytest.fixture
36
  def token():
37
+ url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyArSoK9Wx9Hpe1R9ZywuLEIMVjCtHjO8Os"
38
+
39
+ payload = json.dumps({
40
+ "email": "test@gmail.com",
41
+ "password": "testing",
42
+ "returnSecureToken": True
43
+ })
44
+ headers = {
45
+ 'Content-Type': 'application/json'
46
+ }
47
+ response = requests.request("POST", url, headers=headers, data=payload)
48
+ token = response.json()["idToken"]
49
  yield token
50
  class TestFireBaseAPI():
51
  def test_get_me(self, client, token):
demo.jpg ADDED