This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathmain_test.py
More file actions
53 lines (40 loc) · 1.47 KB
/
main_test.py
File metadata and controls
53 lines (40 loc) · 1.47 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
# Copyright 2018 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.
import os
import uuid
from google.cloud import bigtable
import pytest
from main import main
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
BIGTABLE_INSTANCE = os.environ["BIGTABLE_INSTANCE"]
TABLE_ID_FORMAT = "quickstart-test-{}"
@pytest.fixture()
def table():
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
client = bigtable.Client(project=PROJECT, admin=True)
instance = client.instance(BIGTABLE_INSTANCE)
table = instance.table(table_id)
column_family_id = "cf1"
column_families = {column_family_id: None}
table.create(column_families=column_families)
row = table.direct_row("r1")
row.set_cell(column_family_id, "c1", "test-value")
row.commit()
yield table_id
table.delete()
def test_main(capsys, table):
table_id = table
main(PROJECT, BIGTABLE_INSTANCE, table_id)
out, _ = capsys.readouterr()
assert "Row key: r1\nData: test-value\n" in out