Spaces:
Runtime error
Runtime error
FrancisGOS
commited on
Commit
·
a398c85
1
Parent(s):
2a7983b
<Test>: Fix test case
Browse files- .coverage +0 -0
- app/routers/video.py +2 -49
- custom_utils/__init__.py +0 -0
- custom_utils/utils.py +52 -0
- tests/test_friend_request.py +12 -5
- tests/test_video.py +2 -1
.coverage
CHANGED
Binary files a/.coverage and b/.coverage differ
|
|
app/routers/video.py
CHANGED
@@ -24,7 +24,7 @@ from app.routers.image import inferenceImage
|
|
24 |
from google.cloud.firestore_v1.base_query import FieldFilter
|
25 |
from google.cloud.firestore import ArrayUnion
|
26 |
from app import logger
|
27 |
-
|
28 |
router = APIRouter(prefix="/video", tags=["Video"])
|
29 |
|
30 |
|
@@ -166,51 +166,4 @@ def updateArtifact(artifactId: str, body):
|
|
166 |
artifact_snapshot = artifact_ref.get()
|
167 |
if artifact_snapshot.exists:
|
168 |
artifact_ref.update(body)
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
# This function cannot be automation test because the requirement of another device to receive notification
|
173 |
-
def sendMessage(artifactId: str, message: str = None):
|
174 |
-
token = []
|
175 |
-
artifact = db.collection("artifacts").document(artifactId).get()
|
176 |
-
if not artifact.exists:
|
177 |
-
return
|
178 |
-
user_ref = db.collection("user").where(
|
179 |
-
filter=FieldFilter("artifacts", "array-contains", "artifacts/" + artifactId)
|
180 |
-
)
|
181 |
-
for user in user_ref:
|
182 |
-
token.append(user.get().to_dict()["deviceId"])
|
183 |
-
if message is not None:
|
184 |
-
messaging.MulticastMessage(
|
185 |
-
data={
|
186 |
-
"notification": {
|
187 |
-
"title": message,
|
188 |
-
"body": "Video "
|
189 |
-
+ artifact.name
|
190 |
-
+ " has done inference. Click here to see the video",
|
191 |
-
},
|
192 |
-
},
|
193 |
-
android=messaging.AndroidConfig(
|
194 |
-
notification=messaging.AndroidNotification(
|
195 |
-
icon="stock_ticker_update", color="#f45342"
|
196 |
-
),
|
197 |
-
),
|
198 |
-
)
|
199 |
-
else:
|
200 |
-
messaging.MulticastMessage(
|
201 |
-
data={
|
202 |
-
"notification": {
|
203 |
-
"title": "Video " + artifact.name + " has done inference.",
|
204 |
-
"body": "Video "
|
205 |
-
+ artifact.name
|
206 |
-
+ " has done inference. Click here to see the video",
|
207 |
-
},
|
208 |
-
},
|
209 |
-
android=messaging.AndroidConfig(
|
210 |
-
notification=messaging.AndroidNotification(
|
211 |
-
icon="stock_ticker_update", color="#f45342"
|
212 |
-
),
|
213 |
-
),
|
214 |
-
)
|
215 |
-
response = messaging.send_multicast(message)
|
216 |
-
return response.success_count
|
|
|
24 |
from google.cloud.firestore_v1.base_query import FieldFilter
|
25 |
from google.cloud.firestore import ArrayUnion
|
26 |
from app import logger
|
27 |
+
from custom_utils import utils
|
28 |
router = APIRouter(prefix="/video", tags=["Video"])
|
29 |
|
30 |
|
|
|
166 |
artifact_snapshot = artifact_ref.get()
|
167 |
if artifact_snapshot.exists:
|
168 |
artifact_ref.update(body)
|
169 |
+
utils.sendMessage(artifactId)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
custom_utils/__init__.py
ADDED
File without changes
|
custom_utils/utils.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from firebase_admin import messaging
|
2 |
+
from app import db
|
3 |
+
from google.cloud.firestore_v1.base_query import FieldFilter
|
4 |
+
|
5 |
+
# This function cannot be automation test because the requirement of another device to receive notification
|
6 |
+
def sendMessage(artifactId: str, message: str = None):
|
7 |
+
token = []
|
8 |
+
artifact = db.collection("artifacts").document(artifactId).get()
|
9 |
+
if not artifact.exists:
|
10 |
+
return
|
11 |
+
artifact = artifact.to_dict()
|
12 |
+
user_ref = db.collection("user").where(
|
13 |
+
filter=FieldFilter("artifacts", "array_contains", "artifacts/" + artifactId)
|
14 |
+
).stream()
|
15 |
+
for user in user_ref:
|
16 |
+
token.append(user.to_dict()["deviceId"])
|
17 |
+
if message is not None:
|
18 |
+
msg = messaging.MulticastMessage(
|
19 |
+
data={
|
20 |
+
"notification": {
|
21 |
+
"title": message,
|
22 |
+
"body": "Video "
|
23 |
+
+ artifact["name"]
|
24 |
+
+ " has done inference. Click here to see the video",
|
25 |
+
},
|
26 |
+
},
|
27 |
+
android=messaging.AndroidConfig(
|
28 |
+
notification=messaging.AndroidNotification(
|
29 |
+
icon="stock_ticker_update", color="#f45342"
|
30 |
+
),
|
31 |
+
),
|
32 |
+
tokens=token
|
33 |
+
)
|
34 |
+
else:
|
35 |
+
msg = messaging.MulticastMessage(
|
36 |
+
data={
|
37 |
+
"notification": {
|
38 |
+
"title": "Video " + artifact['name'] + " has done inference.",
|
39 |
+
"body": "Video "
|
40 |
+
+ artifact["name"]
|
41 |
+
+ " has done inference. Click here to see the video",
|
42 |
+
},
|
43 |
+
},
|
44 |
+
android=messaging.AndroidConfig(
|
45 |
+
notification=messaging.AndroidNotification(
|
46 |
+
icon="stock_ticker_update", color="#f45342"
|
47 |
+
),
|
48 |
+
),
|
49 |
+
tokens=token
|
50 |
+
)
|
51 |
+
response = messaging.send_multicast(msg)
|
52 |
+
return response.success_count
|
tests/test_friend_request.py
CHANGED
@@ -11,7 +11,7 @@ from app.constants import deviceId
|
|
11 |
from fastapi.routing import APIRoute
|
12 |
from app import db
|
13 |
from google.cloud.firestore_v1.base_query import FieldFilter
|
14 |
-
|
15 |
|
16 |
def endpoints():
|
17 |
endpoints = []
|
@@ -235,10 +235,17 @@ class TestFriendRequest:
|
|
235 |
"Content-Type": "application/json",
|
236 |
"Authorization": "Bearer " + inviter["token"],
|
237 |
}
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
result = mmcv.imfrombytes(response.read())
|
243 |
# Check returned QR image
|
244 |
assert result.shape[2] == 3
|
|
|
11 |
from fastapi.routing import APIRoute
|
12 |
from app import db
|
13 |
from google.cloud.firestore_v1.base_query import FieldFilter
|
14 |
+
import time
|
15 |
|
16 |
def endpoints():
|
17 |
endpoints = []
|
|
|
235 |
"Content-Type": "application/json",
|
236 |
"Authorization": "Bearer " + inviter["token"],
|
237 |
}
|
238 |
+
flag = False
|
239 |
+
for i in range(5):
|
240 |
+
response = client.request(
|
241 |
+
"POST", "friend_request", headers=headers, data=payload
|
242 |
+
)
|
243 |
+
if(response.status_code == 200):
|
244 |
+
flag = True
|
245 |
+
break
|
246 |
+
else:
|
247 |
+
time.sleep(2)
|
248 |
+
assert flag == True
|
249 |
result = mmcv.imfrombytes(response.read())
|
250 |
# Check returned QR image
|
251 |
assert result.shape[2] == 3
|
tests/test_video.py
CHANGED
@@ -101,7 +101,8 @@ class TestVideoAPI:
|
|
101 |
for doc in docs:
|
102 |
# For each document in docs. Verify name and status of the artifact
|
103 |
index += 1
|
104 |
-
data = doc.
|
|
|
105 |
assert data["name"] == artifactName
|
106 |
assert data["status"] == "pending"
|
107 |
assert index == 1
|
|
|
101 |
for doc in docs:
|
102 |
# For each document in docs. Verify name and status of the artifact
|
103 |
index += 1
|
104 |
+
data = doc.to_dict()
|
105 |
+
print(data)
|
106 |
assert data["name"] == artifactName
|
107 |
assert data["status"] == "pending"
|
108 |
assert index == 1
|