Skip to content

Add integration tests for async Firstore module #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 Google Inc.
# Copyright 2022 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
"""pytest configuration and global fixtures for integration tests."""
import json

import asyncio
import pytest

import firebase_admin
Expand Down Expand Up @@ -70,3 +71,12 @@ def api_key(request):
'command-line option.')
with open(path) as keyfile:
return keyfile.read().strip()

@pytest.fixture(scope="session")
def event_loop():
"""Create an instance of the default event loop for test session.
This avoids early eventloop closure.
"""
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()
50 changes: 50 additions & 0 deletions integration/test_firestore_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2022 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Integration tests for firebase_admin.firestore_async module."""
import datetime

from firebase_admin import firestore_async

async def test_firestore_async():
client = firestore_async.client()
expected = {
'name': u'Mountain View',
'country': u'USA',
'population': 77846,
'capital': False
}
doc = client.collection('cities').document()
await doc.set(expected)

data = await doc.get()
assert data.to_dict() == expected

await doc.delete()
data = await doc.get()
assert data.exists is False

async def test_server_timestamp():
client = firestore_async.client()
expected = {
'name': u'Mountain View',
'timestamp': firestore_async.SERVER_TIMESTAMP # pylint: disable=no-member
}
doc = client.collection('cities').document()
await doc.set(expected)

data = await doc.get()
data = data.to_dict()
assert isinstance(data['timestamp'], datetime.datetime)
await doc.delete()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pylint == 2.3.1
pytest >= 6.2.0
pytest-cov >= 2.4.0
pytest-localserver >= 0.4.1
pytest-asyncio >= 0.18.3

cachecontrol >= 0.12.6
google-api-core[grpc] >= 1.22.1, < 3.0.0dev; platform.python_implementation != 'PyPy'
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[tool:pytest]
testpaths = tests
asyncio_mode=auto