Skip to content

Commit 84c7c3b

Browse files
gmcrocopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 580972070 Change-Id: If078fc4ab3a2b7654bf95fc32f78557b8cf4ac80
1 parent 65d1007 commit 84c7c3b

4 files changed

Lines changed: 376 additions & 0 deletions

File tree

system_tests/backend_test.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2023 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+
# 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+
"""E2E tests for the backend Python container."""
16+
17+
import json
18+
import os
19+
import urllib
20+
21+
22+
import google.auth.transport.requests
23+
import google.cloud.logging
24+
import google.oauth2.id_token
25+
import pytest
26+
27+
28+
_BACKEND_URL_ENV_VAR = 'BACKEND_URL'
29+
30+
client = google.cloud.logging.Client()
31+
client.setup_logging()
32+
33+
34+
@pytest.mark.systemtest
35+
def test_accessible_accounts():
36+
auth_request = google.auth.transport.requests.Request()
37+
url = os.environ.get(_BACKEND_URL_ENV_VAR)
38+
39+
id_token = google.oauth2.id_token.fetch_id_token(auth_request, url)
40+
41+
assert id_token is not None, 'Could not fetch id token for get accounts.'
42+
43+
request = urllib.request.Request(f'{url}/accessible_accounts')
44+
request.add_header('Authorization', f'Bearer {id_token}')
45+
46+
with urllib.request.urlopen(request) as response:
47+
assert (
48+
response.status == 200
49+
), 'Got non-200 response from /accessible_accounts'
50+
body = response.read()
51+
account_dict = json.loads(body)
52+
assert account_dict, 'Could not find accessible accounts'
53+
54+
55+
@pytest.mark.systemtest
56+
@pytest.mark.skipif(
57+
os.getenv('TEST_FAILURE_ALERTING') != 'TRUE',
58+
reason='Test failure alerting is not set to TRUE.',
59+
)
60+
def test_that_always_fails():
61+
"""A deliberately failing test, to check alerts are sent when tests fail."""
62+
assert False

system_tests/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2023 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+
# 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+
"""Global pytest configurations.
16+
17+
New markers can be defined here to tag tests for categorizing these tests into
18+
different group and pytest can be directed to run tests in a specific group.
19+
20+
Example usage:
21+
@pytest.mark.systemtest
22+
def test_something():
23+
pass
24+
25+
Ref:
26+
https://docs.pytest.org/en/7.1.x/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files
27+
"""
28+
29+
30+
def pytest_configure(config):
31+
config.addinivalue_line(
32+
'markers', 'systemtest: mark test as a system test.'
33+
)

system_tests/requirements.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
google-auth
2+
google-cloud-logging

0 commit comments

Comments
 (0)