|
14 | 14 |
|
15 | 15 | """Tests for firebase_admin.firestore.""" |
16 | 16 |
|
| 17 | +import platform |
| 18 | + |
17 | 19 | import pytest |
18 | 20 |
|
19 | 21 | import firebase_admin |
20 | 22 | from firebase_admin import credentials |
21 | | -from firebase_admin import firestore |
| 23 | +try: |
| 24 | + from firebase_admin import firestore |
| 25 | +except ImportError: |
| 26 | + pass |
22 | 27 | from tests import testutils |
23 | 28 |
|
24 | 29 |
|
25 | | -def teardown_function(): |
26 | | - testutils.cleanup_apps() |
| 30 | +@pytest.mark.skipif( |
| 31 | + platform.python_implementation() == 'PyPy', |
| 32 | + reason='Firestore is not supported on PyPy') |
| 33 | +class TestFirestore(object): |
| 34 | + """Test class Firestore APIs.""" |
| 35 | + |
| 36 | + def teardown_method(self, method): |
| 37 | + del method |
| 38 | + testutils.cleanup_apps() |
27 | 39 |
|
28 | | -def test_no_project_id(): |
29 | | - def evaluate(): |
30 | | - firebase_admin.initialize_app(testutils.MockCredential()) |
31 | | - with pytest.raises(ValueError): |
32 | | - firestore.client() |
33 | | - testutils.run_without_project_id(evaluate) |
| 40 | + def test_no_project_id(self): |
| 41 | + def evaluate(): |
| 42 | + firebase_admin.initialize_app(testutils.MockCredential()) |
| 43 | + with pytest.raises(ValueError): |
| 44 | + firestore.client() |
| 45 | + testutils.run_without_project_id(evaluate) |
34 | 46 |
|
35 | | -def test_project_id(): |
36 | | - cred = credentials.Certificate(testutils.resource_filename('service_account.json')) |
37 | | - firebase_admin.initialize_app(cred, {'projectId': 'explicit-project-id'}) |
38 | | - client = firestore.client() |
39 | | - assert client is not None |
40 | | - assert client.project == 'explicit-project-id' |
| 47 | + def test_project_id(self): |
| 48 | + cred = credentials.Certificate(testutils.resource_filename('service_account.json')) |
| 49 | + firebase_admin.initialize_app(cred, {'projectId': 'explicit-project-id'}) |
| 50 | + client = firestore.client() |
| 51 | + assert client is not None |
| 52 | + assert client.project == 'explicit-project-id' |
41 | 53 |
|
42 | | -def test_project_id_with_explicit_app(): |
43 | | - cred = credentials.Certificate(testutils.resource_filename('service_account.json')) |
44 | | - app = firebase_admin.initialize_app(cred, {'projectId': 'explicit-project-id'}) |
45 | | - client = firestore.client(app=app) |
46 | | - assert client is not None |
47 | | - assert client.project == 'explicit-project-id' |
| 54 | + def test_project_id_with_explicit_app(self): |
| 55 | + cred = credentials.Certificate(testutils.resource_filename('service_account.json')) |
| 56 | + app = firebase_admin.initialize_app(cred, {'projectId': 'explicit-project-id'}) |
| 57 | + client = firestore.client(app=app) |
| 58 | + assert client is not None |
| 59 | + assert client.project == 'explicit-project-id' |
48 | 60 |
|
49 | | -def test_service_account(): |
50 | | - cred = credentials.Certificate(testutils.resource_filename('service_account.json')) |
51 | | - firebase_admin.initialize_app(cred) |
52 | | - client = firestore.client() |
53 | | - assert client is not None |
54 | | - assert client.project == 'mock-project-id' |
| 61 | + def test_service_account(self): |
| 62 | + cred = credentials.Certificate(testutils.resource_filename('service_account.json')) |
| 63 | + firebase_admin.initialize_app(cred) |
| 64 | + client = firestore.client() |
| 65 | + assert client is not None |
| 66 | + assert client.project == 'mock-project-id' |
55 | 67 |
|
56 | | -def test_service_account_with_explicit_app(): |
57 | | - cred = credentials.Certificate(testutils.resource_filename('service_account.json')) |
58 | | - app = firebase_admin.initialize_app(cred) |
59 | | - client = firestore.client(app=app) |
60 | | - assert client is not None |
61 | | - assert client.project == 'mock-project-id' |
| 68 | + def test_service_account_with_explicit_app(self): |
| 69 | + cred = credentials.Certificate(testutils.resource_filename('service_account.json')) |
| 70 | + app = firebase_admin.initialize_app(cred) |
| 71 | + client = firestore.client(app=app) |
| 72 | + assert client is not None |
| 73 | + assert client.project == 'mock-project-id' |
62 | 74 |
|
63 | | -def test_geo_point(): |
64 | | - geo_point = firestore.GeoPoint(10, 20) # pylint: disable=no-member |
65 | | - assert geo_point.latitude == 10 |
66 | | - assert geo_point.longitude == 20 |
| 75 | + def test_geo_point(self): |
| 76 | + geo_point = firestore.GeoPoint(10, 20) # pylint: disable=no-member |
| 77 | + assert geo_point.latitude == 10 |
| 78 | + assert geo_point.longitude == 20 |
67 | 79 |
|
68 | | -def test_server_timestamp(): |
69 | | - assert firestore.SERVER_TIMESTAMP is not None # pylint: disable=no-member |
| 80 | + def test_server_timestamp(self): |
| 81 | + assert firestore.SERVER_TIMESTAMP is not None # pylint: disable=no-member |
0 commit comments