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

Commit 30b6dfc

Browse files
committed
Merge pull request #81 from GoogleCloudPlatform/add_e2e_tests
Modifying test harness for 10x test development velocity. Client now…
2 parents 953b110 + 75fb66e commit 30b6dfc

8 files changed

Lines changed: 48 additions & 8 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ docs/_build/
5252

5353
# PyBuilder
5454
target/
55+
56+
# Generated test files
57+
tests/e2e/app/app.yaml
58+
tests/e2e/app/Dockerfile
59+

common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ ifeq ($(origin DOCKER_IMAGE_NAME), undefined)
44
GCLOUD_PROJECT:=$(shell gcloud config list project --format="value(core.project)")
55
DOCKER_IMAGE_NAME:=gcr.io/$(GCLOUD_PROJECT)/google-python-compat
66
endif
7+
BUCKET=gs://${GCLOUD_PROJECT}-python-compat-e2e-tests

tests/e2e/app/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include ../../../common.mk
44
all: deploy
55

66
.PHONY: deploy
7-
deploy: build-base generate-dockerfile copy-tests
7+
deploy: build-base generate-dockerfile generate-app-yaml
88
gcloud preview app deploy -q
99

1010
.PHONY: build-base
@@ -15,6 +15,6 @@ build-base:
1515
generate-dockerfile:
1616
sed "s#\$$DOCKER_IMAGE_NAME#$(DOCKER_IMAGE_NAME)#g" Dockerfile.in > Dockerfile
1717

18-
.PHONY: copy-tests
19-
copy-tests:
20-
cp -r ../tests .
18+
.PHONY: generate-app-yaml
19+
generate-app-yaml:
20+
sed "s#\$$CLOUD_STORAGE_BUCKET#$(BUCKET)#g" app.yaml.in > app.yaml
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ vm: true
44
handlers:
55
- url: .*
66
script: main.app
7+
8+
env_variables:
9+
CLOUD_STORAGE_BUCKET: $CLOUD_STORAGE_BUCKET

tests/e2e/app/main.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import sys
16-
import contextlib
1715
from cStringIO import StringIO
16+
from gcloud import storage
1817

19-
import webapp2
18+
import contextlib
2019
import pytest
20+
import os
21+
import shutil
22+
import sys
23+
import webapp2
24+
25+
# Configure this environment variable via app.yaml.in.
26+
# Cut off the 'gs://' portion of the name.
27+
GCLOUD_STORAGE_BUCKET = os.environ['CLOUD_STORAGE_BUCKET'][5:]
2128

2229

2330
@contextlib.contextmanager
@@ -32,7 +39,20 @@ def capture():
3239

3340

3441
class TestRunnerHandler(webapp2.RequestHandler):
42+
3543
def get(self):
44+
# Set up test directory.
45+
if os.path.isdir('tests'):
46+
shutil.rmtree('tests')
47+
os.mkdir('tests')
48+
49+
# Refresh the tests from cloud storage.
50+
bucket = storage.Client().get_bucket(GCLOUD_STORAGE_BUCKET)
51+
blob_iter = bucket.list_blobs()
52+
for blob in blob_iter:
53+
blob.download_to_filename('tests/%s' % blob.name)
54+
55+
# Run the tests.
3656
with capture() as outf:
3757
result = pytest.main(['tests'])
3858

tests/e2e/app/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
gcloud
12
pytest
23
webapp2
34
webob

tests/e2e/client/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
include ../../../common.mk
22

33
.PHONY: all
4-
all:
4+
all: upload test
5+
6+
.PHONY: test
7+
test:
58
virtualenv env
69
env/bin/pip install -r requirements.txt
710
env/bin/python main.py https://${GCLOUD_PROJECT}.appspot.com/
11+
12+
.PHONY: upload
13+
upload:
14+
-e gsutil mb ${BUCKET} &> /dev/null
15+
gsutil rm ${BUCKET}/**
16+
gsutil cp ../tests/* ${BUCKET} &> /dev/null

tests/e2e/tests/ndb_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import pytest
23

34
from google.appengine.ext.ndb import model, tasklets
45

0 commit comments

Comments
 (0)