From f5255f6e9bab58d8cfb16245570c69491e36d3d2 Mon Sep 17 00:00:00 2001 From: jkyle109 Date: Wed, 13 Jul 2022 14:26:05 -0400 Subject: [PATCH 1/4] Add integration tests for async firstore module --- integration/conftest.py | 12 ++++++- integration/test_firestore_async.py | 50 +++++++++++++++++++++++++++++ requirements.txt | 1 + setup.cfg | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 integration/test_firestore_async.py diff --git a/integration/conftest.py b/integration/conftest.py index 169e02d5b..f3b024edd 100644 --- a/integration/conftest.py +++ b/integration/conftest.py @@ -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. @@ -15,6 +15,7 @@ """pytest configuration and global fixtures for integration tests.""" import json +import asyncio import pytest import firebase_admin @@ -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() diff --git a/integration/test_firestore_async.py b/integration/test_firestore_async.py new file mode 100644 index 000000000..51ca7bddb --- /dev/null +++ b/integration/test_firestore_async.py @@ -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() diff --git a/requirements.txt b/requirements.txt index 0dd529c04..83ac7e1c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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' diff --git a/setup.cfg b/setup.cfg index 25c649748..e05977654 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,3 @@ [tool:pytest] testpaths = tests +asyncio_mode=auto From c333d7c8646a794312f3e2233bff124ee1dd4acd Mon Sep 17 00:00:00 2001 From: jkyle109 Date: Thu, 14 Jul 2022 10:23:58 -0400 Subject: [PATCH 2/4] fix: made pytest Python 3.6 compatible --- integration/test_firestore_async.py | 3 +++ requirements.txt | 2 +- setup.cfg | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/integration/test_firestore_async.py b/integration/test_firestore_async.py index 51ca7bddb..2a5b93217 100644 --- a/integration/test_firestore_async.py +++ b/integration/test_firestore_async.py @@ -14,9 +14,11 @@ """Integration tests for firebase_admin.firestore_async module.""" import datetime +import pytest from firebase_admin import firestore_async +@pytest.mark.asyncio async def test_firestore_async(): client = firestore_async.client() expected = { @@ -35,6 +37,7 @@ async def test_firestore_async(): data = await doc.get() assert data.exists is False +@pytest.mark.asyncio async def test_server_timestamp(): client = firestore_async.client() expected = { diff --git a/requirements.txt b/requirements.txt index 83ac7e1c2..87142fe93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +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 +pytest-asyncio >= 0.16.0 cachecontrol >= 0.12.6 google-api-core[grpc] >= 1.22.1, < 3.0.0dev; platform.python_implementation != 'PyPy' diff --git a/setup.cfg b/setup.cfg index e05977654..25c649748 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,2 @@ [tool:pytest] testpaths = tests -asyncio_mode=auto From b80a6cc05243a85b2a312f7d5ae58e17ae9bcef4 Mon Sep 17 00:00:00 2001 From: jkyle109 Date: Thu, 14 Jul 2022 12:38:17 -0400 Subject: [PATCH 3/4] Trigger Integration Tests From 4474535120463b40fe4b00dcab303683fc07f2cb Mon Sep 17 00:00:00 2001 From: jkyle109 Date: Thu, 14 Jul 2022 12:56:51 -0400 Subject: [PATCH 4/4] fix: correct copyright year --- integration/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/conftest.py b/integration/conftest.py index f3b024edd..71f53f612 100644 --- a/integration/conftest.py +++ b/integration/conftest.py @@ -1,4 +1,4 @@ -# Copyright 2022 Google Inc. +# Copyright 2017 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.