Skip to content

Commit eb8226b

Browse files
authored
Adds integration tests for the Async Firstore module (#623)
* Add integration tests for async firstore module * fix: made pytest Python 3.6 compatible * Trigger Integration Tests * fix: correct copyright year
1 parent 1536e33 commit eb8226b

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

integration/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""pytest configuration and global fixtures for integration tests."""
1616
import json
1717

18+
import asyncio
1819
import pytest
1920

2021
import firebase_admin
@@ -70,3 +71,12 @@ def api_key(request):
7071
'command-line option.')
7172
with open(path) as keyfile:
7273
return keyfile.read().strip()
74+
75+
@pytest.fixture(scope="session")
76+
def event_loop():
77+
"""Create an instance of the default event loop for test session.
78+
This avoids early eventloop closure.
79+
"""
80+
loop = asyncio.get_event_loop_policy().new_event_loop()
81+
yield loop
82+
loop.close()

integration/test_firestore_async.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2022 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Integration tests for firebase_admin.firestore_async module."""
16+
import datetime
17+
import pytest
18+
19+
from firebase_admin import firestore_async
20+
21+
@pytest.mark.asyncio
22+
async def test_firestore_async():
23+
client = firestore_async.client()
24+
expected = {
25+
'name': u'Mountain View',
26+
'country': u'USA',
27+
'population': 77846,
28+
'capital': False
29+
}
30+
doc = client.collection('cities').document()
31+
await doc.set(expected)
32+
33+
data = await doc.get()
34+
assert data.to_dict() == expected
35+
36+
await doc.delete()
37+
data = await doc.get()
38+
assert data.exists is False
39+
40+
@pytest.mark.asyncio
41+
async def test_server_timestamp():
42+
client = firestore_async.client()
43+
expected = {
44+
'name': u'Mountain View',
45+
'timestamp': firestore_async.SERVER_TIMESTAMP # pylint: disable=no-member
46+
}
47+
doc = client.collection('cities').document()
48+
await doc.set(expected)
49+
50+
data = await doc.get()
51+
data = data.to_dict()
52+
assert isinstance(data['timestamp'], datetime.datetime)
53+
await doc.delete()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pylint == 2.3.1
33
pytest >= 6.2.0
44
pytest-cov >= 2.4.0
55
pytest-localserver >= 0.4.1
6+
pytest-asyncio >= 0.16.0
67

78
cachecontrol >= 0.12.6
89
google-api-core[grpc] >= 1.22.1, < 3.0.0dev; platform.python_implementation != 'PyPy'

0 commit comments

Comments
 (0)