Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit 88e598f

Browse files
committed
test: restore system tests
1 parent 6e8d47e commit 88e598f

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2018 Google LLC
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+
# https://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+
import os
16+
import time
17+
18+
from google.cloud import trace_v1
19+
20+
21+
class TestSystemTraceService(object):
22+
def test_list_traces(self):
23+
project_id = os.environ["PROJECT_ID"]
24+
25+
client = trace_v1.TraceServiceClient()
26+
project_id_2 = project_id
27+
response = client.list_traces(project_id=project_id_2)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2019 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# flake8: noqa
18+
19+
import os
20+
import pytest
21+
22+
from google.api_core import exceptions
23+
from google.cloud import trace_v1
24+
from test_utils.vpcsc_config import vpcsc_config
25+
26+
_VPCSC_PROHIBITED_MESSAGE = "Request is prohibited by organization's policy."
27+
28+
29+
@pytest.fixture
30+
def client():
31+
return trace_v1.TraceServiceClient()
32+
33+
34+
@vpcsc_config.skip_unless_inside_vpcsc
35+
def test_list_traces_w_inside(client):
36+
list(client.list_traces(project_id=vpcsc_config.project_inside)) # no perms issue
37+
38+
39+
@vpcsc_config.skip_unless_inside_vpcsc
40+
def test_list_traces_w_outside(client):
41+
with pytest.raises(exceptions.PermissionDenied) as exc:
42+
list(client.list_traces(project_id=vpcsc_config.project_outside))
43+
44+
assert _VPCSC_PROHIBITED_MESSAGE in exc.value.message
45+
46+
47+
@vpcsc_config.skip_unless_inside_vpcsc
48+
def test_get_trace_w_inside(client):
49+
with pytest.raises(exceptions.InvalidArgument):
50+
client.get_trace(project_id=vpcsc_config.project_inside, trace_id="") # no perms issue
51+
52+
53+
@vpcsc_config.skip_unless_inside_vpcsc
54+
def test_get_trace_w_outside(client):
55+
with pytest.raises(exceptions.PermissionDenied) as exc:
56+
client.get_trace(project_id=vpcsc_config.project_outside, trace_id="")
57+
58+
assert _VPCSC_PROHIBITED_MESSAGE in exc.value.message
59+
60+
61+
@vpcsc_config.skip_unless_inside_vpcsc
62+
def test_patch_traces_w_inside(client):
63+
with pytest.raises(exceptions.InvalidArgument):
64+
client.patch_traces(project_id=vpcsc_config.project_inside, traces={}) # no perms issue
65+
66+
67+
@vpcsc_config.skip_unless_inside_vpcsc
68+
def test_patch_traces_w_ouside(client):
69+
with pytest.raises(exceptions.PermissionDenied) as exc:
70+
client.patch_traces(project_id=vpcsc_config.project_outside, traces={})
71+
72+
assert _VPCSC_PROHIBITED_MESSAGE in exc.value.message
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2018 Google LLC
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+
# https://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+
import os
16+
import time
17+
18+
from google.cloud import trace_v2
19+
20+
21+
class TestSystemTraceService(object):
22+
def test_batch_write_spans(self):
23+
project_id = os.environ["PROJECT_ID"]
24+
25+
client = trace_v2.TraceServiceClient()
26+
name = f"projects/{project_id}"
27+
spans = []
28+
client.batch_write_spans(name=name, spans=spans)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2019 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# flake8: noqa
18+
19+
import os
20+
import pytest
21+
22+
from google.api_core import exceptions
23+
from google.cloud import trace_v2
24+
from test_utils.vpcsc_config import vpcsc_config
25+
26+
_VPCSC_PROHIBITED_MESSAGE = "Request is prohibited by organization's policy."
27+
28+
29+
@pytest.fixture
30+
def client():
31+
return trace_v2.TraceServiceClient()
32+
33+
34+
@vpcsc_config.skip_unless_inside_vpcsc
35+
def test_batch_write_spans_w_inside(client):
36+
project_inside = f"projects/{vpcsc_config.project_inside}"
37+
client.batch_write_spans(name=project_inside, spans=[]) # no raise
38+
39+
40+
@vpcsc_config.skip_unless_inside_vpcsc
41+
def test_batch_write_spans_w_outside(client):
42+
project_outside = f"projects/{vpcsc_config.project_outside}"
43+
44+
with pytest.raises(exceptions.PermissionDenied) as exc:
45+
client.batch_write_spans(name=project_outside, spans=[])
46+
47+
assert _VPCSC_PROHIBITED_MESSAGE in exc.value.message

0 commit comments

Comments
 (0)