|
| 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() |
0 commit comments