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

Commit 8e014e7

Browse files
author
Bryan Mau
committed
Adding e2e tests for supported APIs.
1 parent df0c203 commit 8e014e7

6 files changed

Lines changed: 130 additions & 1 deletion

File tree

tests/e2e/client/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ all: upload test
77
test:
88
virtualenv env
99
env/bin/pip install -r requirements.txt
10-
env/bin/python main.py https://${GCLOUD_PROJECT}.appspot.com/
10+
env/bin/python main.py http://${GCLOUD_PROJECT}.appspot.com/
1111

1212
.PHONY: upload
1313
upload:

tests/e2e/tests/logging_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""E2E test for logging API.
2+
3+
Currently DOES NOT work.
4+
"""
5+
import json
6+
import logging
7+
import os
8+
import pytest
9+
10+
from google.appengine.api.logservice import logservice
11+
12+
13+
@pytest.fixture
14+
def request_id():
15+
return os.environ.get('REQUEST_LOG_ID')
16+
17+
def test_log(request_id):
18+
logging.info('TESTING')
19+
20+
21+
# This test must happen after test_log.
22+
def do_not_run_test_logservice_fetch(request_id):
23+
"""This test fails at logservice.fetch"""
24+
found_log = False
25+
for req_log in logservice.fetch(
26+
request_ids=[request_id],
27+
include_app_logs=True):
28+
for app_log in req_log.app_logs:
29+
if app_log.message == 'TESTING':
30+
found_log = True
31+
32+
assert found_log
33+

tests/e2e/tests/memcache_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Tests for the memcache API.
2+
3+
This test module is incomplete but is a starter.
4+
"""
5+
6+
import pytest
7+
import time
8+
9+
from google.appengine.api import memcache
10+
11+
12+
@pytest.fixture
13+
def defaults():
14+
memcache.flush_all()
15+
return {
16+
'client': memcache._CLIENT,
17+
'mapping': {
18+
'key1', 'data1',
19+
'key2', 'data2',
20+
'key3', 'data3',
21+
},
22+
'timeout': 2,
23+
'timeout_tolerance': 2,
24+
'namespace1': 'foo',
25+
'namespace2': 'bar',
26+
'default_range': 10,
27+
'default_incr_start': 1,
28+
'default_decr_start': 1000,
29+
'default_delta': 10,
30+
}
31+
32+
33+
def test_memcache(defaults):
34+
assert memcache.get('key1') == None
35+
memcache.set('key1', 'data1')
36+
assert memcache.get('key1') == 'data1'
37+
assert memcache.set('key1', 'data1', defaults['timeout'])
38+
time.sleep(defaults['timeout'] + defaults['timeout_tolerance'])
39+
assert memcache.get('key1') == None

tests/e2e/tests/search_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Tests for the search API.
2+
3+
This test module is incomplete but is a starter.
4+
"""
5+
6+
import pytest
7+
import time
8+
9+
from google.appengine.api import search
10+
11+
12+
@pytest.fixture
13+
def index():
14+
index = search.Index(name='simple-index', namespace='')
15+
doc = search.Document(doc_id='test_id', fields=[
16+
search.TextField(name='body', value='hello world'),
17+
])
18+
index.put(doc)
19+
return index
20+
21+
22+
def test_basic_search(index):
23+
resp = index.search('hello')
24+
assert len(resp.results) == 1
25+
result = resp.results[0]
26+
assert result.doc_id == 'test_id'
27+
assert result.language == 'en'
28+
assert result.fields[0].value == 'hello world'
29+
assert result.fields[0].name == 'body'

tests/e2e/tests/urlfetch_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Tests for the urlfetch API."""
2+
3+
import pytest
4+
import time
5+
6+
from google.appengine.api import urlfetch
7+
8+
9+
@pytest.fixture
10+
def url():
11+
return 'http://www.google.com'
12+
13+
def test_urlfetch(url):
14+
resp = urlfetch.fetch(url)
15+
assert resp.status_code == 200
16+
assert resp.headers['content-length'] == str(len(resp.content))

tests/e2e/tests/users_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""E2E test for Users API."""
2+
import pytest
3+
4+
from google.appengine.api import users
5+
6+
7+
@pytest.fixture
8+
def user():
9+
return users.get_current_user()
10+
11+
def test_current_user(user):
12+
assert user == None

0 commit comments

Comments
 (0)