Skip to content

Commit cc9575c

Browse files
committed
1st pass at re-enabling automated linting/tests, + autopep8 some files to reduce linter errors
1 parent 3cd6507 commit cc9575c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+384
-183
lines changed

.github/scripts/authorize.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#! /bin/bash
2+
3+
# Copyright 2020 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+
# http://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+
# Utility for generating credentials used by tests.
18+
19+
# Union of scopes used by samples
20+
SCOPES=(
21+
"https://www.googleapis.com/auth/drive"
22+
"https://www.googleapis.com/auth/drive.activity"
23+
"https://mail.google.com/"
24+
"https://www.googleapis.com/auth/classroom.courses"
25+
"https://www.googleapis.com/auth/classroom.announcements"
26+
"https://www.googleapis.com/auth/classroom.rosters"
27+
"https://www.googleapis.com/auth/classroom.topics"
28+
"https://www.googleapis.com/auth/classroom.guardianlinks.students"
29+
"https://www.googleapis.com/auth/classroom.coursework.students"
30+
)
31+
32+
if [ -z "$CLIENT_ID_FILE" ]; then
33+
echo "CLIENT_ID_FILE environment not set. Please set and run again."
34+
exit 1
35+
fi
36+
37+
if [ ! -f "$CLIENT_ID_FILE" ]; then
38+
echo "$CLIENT_ID_FILE not found."
39+
exit 1
40+
fi
41+
42+
printf -v EXPANDED_SCOPES '%s,' "${SCOPES[@]}"
43+
gcloud auth application-default login \
44+
--client-id-file=client_secret.json \
45+
--scopes="${EXPANDED_SCOPES}"
46+
47+
cat "${HOME}/.config/gcloud/application_default_credentials.json"

.github/scripts/lint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /bin/bash
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
export LC_ALL=C.UTF-8
19+
export LANG=C.UTF-8
20+
21+
find . -iname "*.py" | xargs pylint

.github/scripts/test.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#! /bin/bash
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
export LC_ALL=C.UTF-8
17+
export LANG=C.UTF-8
18+
export PIPENV_PYTHON="${PYENV_ROOT}/shims/python"
19+
export GOOGLE_APPLICATION_CREDENTIALS="${HOME}/secrets/default_credentials.json"
20+
21+
if [ -f "requirements.txt" ]; then
22+
pipenv install -r "requirements.txt"
23+
fi
24+
25+
TEST_DIRS=`find . -name '*_test.py' -exec dirname '{}' \;| sort -u`
26+
27+
exit_code=0
28+
29+
for DIR in ${TEST_DIRS[@]}; do
30+
pushd "${DIR}"
31+
echo $DIR
32+
if [ -f "requirements.txt" ]; then
33+
# If requirements.txt present, create a new isolated environment
34+
touch Pipfile
35+
pipenv install -r "requirements.txt"
36+
fi
37+
pipenv run python -m unittest discover
38+
status=$?
39+
if [ $status -ne 0 ]; then
40+
exit_code=$status
41+
fi
42+
popd
43+
done
44+
45+
if [ $exit_code -ne 0 ]; then
46+
echo "Tests failed."
47+
fi
48+
49+
exit $exit_code

.github/workflows/ci.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.6
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install pylint
22+
- name: Lint with pylint
23+
run: ./.github/scripts/lint.sh
24+
test:
25+
runs-on: ubuntu-latest
26+
strategy:
27+
matrix:
28+
# TODO - expand matrix once stable
29+
python-version: [3.6]
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Set up Python ${{ matrix.python-version }}
33+
uses: actions/setup-python@v2
34+
with:
35+
python-version: ${{ matrix.python-version }}
36+
- name: Install dependencies
37+
run: |
38+
python -m pip install --upgrade pip
39+
pip install pipenv
40+
- name: Write test credentials
41+
run: |
42+
mkdir $HOME/secrets
43+
echo "$DEFAULT_CREDENTIALS" > $HOME/secrets/default_credentials.json
44+
echo "$CLIENT_ID_FILE" > $HOME/secrets/client_id.json
45+
env:
46+
DEFAULT_CREDENTIALS: ${{secrets.SNIPPETS_DEFAULT_CREDENTIALS}}
47+
CLIENT_ID_FILE: ${{secrets.SNIPPETS_CLIENT_ID_FILE}}
48+
- name: Run tests
49+
run: ./.github/scripts/test.sh

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

admin_sdk/directory/quickstart.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# If modifying these scopes, delete the file token.json.
2424
SCOPES = ['https://www.googleapis.com/auth/admin.directory.user']
2525

26+
2627
def main():
2728
"""Shows basic usage of the Admin SDK Directory API.
2829
Prints the emails and names of the first 10 users in the domain.
@@ -50,7 +51,7 @@ def main():
5051
# Call the Admin SDK Directory API
5152
print('Getting the first 10 users in the domain')
5253
results = service.users().list(customer='my_customer', maxResults=10,
53-
orderBy='email').execute()
54+
orderBy='email').execute()
5455
users = results.get('users', [])
5556

5657
if not users:
@@ -59,7 +60,7 @@ def main():
5960
print('Users:')
6061
for user in users:
6162
print(u'{0} ({1})'.format(user['primaryEmail'],
62-
user['name']['fullName']))
63+
user['name']['fullName']))
6364

6465

6566
if __name__ == '__main__':

admin_sdk/reports/quickstart.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# If modifying these scopes, delete the file token.json.
2424
SCOPES = ['https://www.googleapis.com/auth/admin.reports.audit.readonly']
2525

26+
2627
def main():
2728
"""Shows basic usage of the Admin SDK Reports API.
2829
Prints the time, email, and name of the last 10 login events in the domain.
@@ -50,7 +51,7 @@ def main():
5051
# Call the Admin SDK Reports API
5152
print('Getting the last 10 login events')
5253
results = service.activities().list(userKey='all', applicationName='login',
53-
maxResults=10).execute()
54+
maxResults=10).execute()
5455
activities = results.get('items', [])
5556

5657
if not activities:
@@ -59,7 +60,8 @@ def main():
5960
print('Logins:')
6061
for activity in activities:
6162
print(u'{0}: {1} ({2})'.format(activity['id']['time'],
62-
activity['actor']['email'], activity['events'][0]['name']))
63+
activity['actor']['email'], activity['events'][0]['name']))
64+
6365

6466
if __name__ == '__main__':
6567
main()

admin_sdk/reseller/quickstart.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# If modifying these scopes, delete the file token.json.
2424
SCOPES = ['https://www.googleapis.com/auth/apps.order']
2525

26+
2627
def main():
2728
"""Calls the Admin SDK Reseller API. Prints the customer ID, SKU ID,
2829
and plan name of the first 10 subscriptions managed by the domain.
@@ -57,7 +58,8 @@ def main():
5758
print('Subscriptions:')
5859
for subscription in subscriptions:
5960
print(u'{0} ({1}, {2})'.format(subscription['customerId'],
60-
subscription['skuId'], subscription['plan']['planName']))
61+
subscription['skuId'], subscription['plan']['planName']))
62+
6163

6264
if __name__ == '__main__':
6365
main()

apps_script/execute/execute.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from httplib2 import Http
2020
from oauth2client import file as oauth_file, client, tools
2121

22+
2223
def main():
2324
"""Runs the sample.
2425
"""
@@ -42,7 +43,7 @@ def main():
4243
try:
4344
# Make the API request.
4445
response = service.scripts().run(body=request,
45-
scriptId=SCRIPT_ID).execute()
46+
scriptId=SCRIPT_ID).execute()
4647

4748
if 'error' in response:
4849
# The API executed, but the script returned an error.
@@ -59,7 +60,7 @@ def main():
5960
print("Script error stacktrace:")
6061
for trace in error['scriptStackTraceElements']:
6162
print("\t{0}: {1}".format(trace['function'],
62-
trace['lineNumber']))
63+
trace['lineNumber']))
6364
else:
6465
# The structure of the result depends upon what the Apps Script
6566
# function returns. Here, the function returns an Apps Script Object

apps_script/quickstart/quickstart.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
}
4343
'''.strip()
4444

45+
4546
def main():
4647
"""Calls the Apps Script API.
4748
"""

0 commit comments

Comments
 (0)