forked from googleapis/python-spanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_table_api.py
More file actions
73 lines (58 loc) · 2.46 KB
/
test_table_api.py
File metadata and controls
73 lines (58 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright 2021 Google LLC All rights reserved.
#
# 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.
import pytest
from google.api_core import exceptions
from google.cloud import spanner_v1
from google.cloud.spanner_admin_database_v1 import DatabaseDialect
def test_table_exists(shared_database):
table = shared_database.table("all_types")
assert table.exists()
def test_table_exists_not_found(shared_database):
table = shared_database.table("table_does_not_exist")
assert not table.exists()
def test_db_list_tables(shared_database):
tables = shared_database.list_tables()
table_ids = set(table.table_id for table in tables)
assert "contacts" in table_ids
# assert "contact_phones" in table_ids
assert "all_types" in table_ids
def test_db_list_tables_reload(shared_database):
for table in shared_database.list_tables():
assert table.exists()
schema = table.schema
assert isinstance(schema, list)
def test_table_reload_miss(shared_database):
table = shared_database.table("table_does_not_exist")
with pytest.raises(exceptions.NotFound):
table.reload()
def test_table_schema(shared_database, database_dialect):
table = shared_database.table("all_types")
schema = table.schema
expected = [
("pkey", spanner_v1.TypeCode.INT64),
("int_value", spanner_v1.TypeCode.INT64),
("bool_value", spanner_v1.TypeCode.BOOL),
("bytes_value", spanner_v1.TypeCode.BYTES),
("float_value", spanner_v1.TypeCode.FLOAT64),
("string_value", spanner_v1.TypeCode.STRING),
("timestamp_value", spanner_v1.TypeCode.TIMESTAMP),
("date_value", spanner_v1.TypeCode.DATE),
("int_array", spanner_v1.TypeCode.ARRAY),
]
expected = (
expected[:-2] if database_dialect == DatabaseDialect.POSTGRESQL else expected
)
found = {field.name: field.type_.code for field in schema}
for field_name, type_code in expected:
assert found[field_name] == type_code