Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit eba8fe9

Browse files
author
Jon Wayne Parrott
committed
Adding linting to tests
1 parent cc6a826 commit eba8fe9

11 files changed

Lines changed: 183 additions & 59 deletions

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ before_script:
99
script:
1010
- make test-vmruntime
1111
- make build
12+
- make -C tests/e2e/client lint

tests/e2e/client/Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
include ../../../common.mk
22

33
.PHONY: all
4-
all: upload test
4+
all: lint upload test
55

66
.PHONY: test
7-
test:
7+
test: virtualenv
88
virtualenv env
9-
env/bin/pip install -r requirements.txt
109
env/bin/python main.py http://${GCLOUD_PROJECT}.appspot.com/
1110

1211
.PHONY: upload
1312
upload:
1413
-e gsutil mb ${BUCKET} &> /dev/null
1514
gsutil rm ${BUCKET}/**
1615
gsutil cp ../tests/* ${BUCKET} &> /dev/null
16+
17+
.PHONY: virtualenv
18+
virtualenv:
19+
virtualenv env
20+
env/bin/pip install -r requirements.txt
21+
22+
.PHONY: lint
23+
lint: virtualenv
24+
env/bin/flake8 --import-order-style=google ../tests

tests/e2e/client/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
requests
2+
flake8
3+
flake8-import-order

tests/e2e/tests/app_identity_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
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+
115
from google.appengine.api import app_identity
216

317

tests/e2e/tests/logging_test.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
from google.appengine.api.logservice import logservice
2-
import json
1+
# Copyright 2016 Google Inc. All Rights Reserved.
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+
315
import logging
416
import os
5-
import pytest
617

18+
from google.appengine.api.logservice import logservice
19+
import pytest
720

821

922
@pytest.fixture
1023
def request_id():
11-
return os.environ.get('REQUEST_LOG_ID')
24+
return os.environ.get('REQUEST_LOG_ID')
25+
1226

1327
@pytest.mark.xfail
1428
def do_not_run_test_logservice_fetch(request_id):
15-
"""This test fails at logservice.fetch"""
16-
logging.info('TESTING')
17-
found_log = False
18-
for req_log in logservice.fetch(
19-
request_ids=[request_id],
20-
include_app_logs=True):
21-
for app_log in req_log.app_logs:
22-
if app_log.message == 'TESTING':
23-
found_log = True
24-
25-
assert found_log
29+
"""This test fails at logservice.fetch"""
30+
logging.info('TESTING')
31+
found_log = False
32+
for req_log in logservice.fetch(request_ids=[request_id],
33+
include_app_logs=True):
34+
for app_log in req_log.app_logs:
35+
if app_log.message == 'TESTING':
36+
found_log = True
2637

38+
assert found_log

tests/e2e/tests/memcache_test.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
from google.appengine.api import memcache
2-
import pytest
1+
# Copyright 2016 Google Inc. All Rights Reserved.
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+
315
import time
416

17+
from google.appengine.api import memcache
18+
519
key1 = 'key1'
620
data1 = 'data1'
721
timeout = 2
822
timeout_tolerance = 2
923

24+
1025
def test_memcache():
11-
assert memcache.get(key1) == None
12-
memcache.set(key1, data1)
13-
assert memcache.get(key1) == data1
14-
assert memcache.set(key1, data1, timeout)
15-
time.sleep(timeout + timeout_tolerance)
16-
assert memcache.get(key1) == None
26+
assert memcache.get(key1) is None
27+
memcache.set(key1, data1)
28+
assert memcache.get(key1) == data1
29+
assert memcache.set(key1, data1, timeout)
30+
time.sleep(timeout + timeout_tolerance)
31+
assert memcache.get(key1) is None

tests/e2e/tests/ndb_test.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
1-
import os
2-
import pytest
1+
# Copyright 2016 Google Inc. All Rights Reserved.
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.
314

415
from google.appengine.ext.ndb import model, tasklets
16+
import pytest
17+
518

619
class Employee(model.Model):
7-
name = model.StringProperty()
8-
age = model.IntegerProperty()
20+
name = model.StringProperty()
21+
age = model.IntegerProperty()
922

1023

1124
@pytest.fixture
1225
def ctx():
13-
ctx = tasklets.get_context()
14-
ctx.set_cache_policy(False)
15-
ctx.set_memcache_policy(False)
16-
return ctx
26+
ctx = tasklets.get_context()
27+
ctx.set_cache_policy(False)
28+
ctx.set_memcache_policy(False)
29+
return ctx
30+
1731

1832
def test_basics(ctx):
19-
worker = Employee(name='Alice', age=55)
20-
key = worker.put()
21-
same_worker = key.get()
22-
assert worker == same_worker
33+
worker = Employee(name='Alice', age=55)
34+
key = worker.put()
35+
same_worker = key.get()
36+
assert worker == same_worker

tests/e2e/tests/sanity_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
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.
114

215

316
def test_sanity():

tests/e2e/tests/search_test.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
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+
115
from google.appengine.api import search
216
import pytest
3-
import time
17+
418

519
@pytest.fixture
620
def index():
7-
index = search.Index(name='simple-index', namespace='')
8-
doc = search.Document(doc_id='test_id', fields=[
9-
search.TextField(name='body', value='hello world'),
10-
])
11-
index.put(doc)
12-
return index
21+
index = search.Index(name='simple-index', namespace='')
22+
doc = search.Document(
23+
doc_id='test_id',
24+
fields=[
25+
search.TextField(
26+
name='body',
27+
value='hello world'),
28+
])
29+
index.put(doc)
30+
return index
1331

1432

1533
def test_basic_search(index):
16-
resp = index.search('hello')
17-
assert len(resp.results) == 1
18-
result = resp.results[0]
19-
assert result.doc_id == 'test_id'
20-
assert result.language == 'en'
21-
assert result.fields[0].value == 'hello world'
22-
assert result.fields[0].name == 'body'
34+
resp = index.search('hello')
35+
assert len(resp.results) == 1
36+
result = resp.results[0]
37+
assert result.doc_id == 'test_id'
38+
assert result.language == 'en'
39+
assert result.fields[0].value == 'hello world'
40+
assert result.fields[0].name == 'body'

tests/e2e/tests/urlfetch_test.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
# Copyright 2016 Google Inc. All Rights Reserved.
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+
115
from google.appengine.api import urlfetch
2-
import pytest
3-
import time
416

517
url = 'http://www.google.com'
618

19+
720
def test_urlfetch():
8-
resp = urlfetch.fetch(url)
9-
assert resp.status_code == 200
10-
assert resp.headers['content-length'] == str(len(resp.content))
21+
resp = urlfetch.fetch(url)
22+
assert resp.status_code == 200
23+
assert resp.headers['content-length'] == str(len(resp.content))

0 commit comments

Comments
 (0)