Skip to content

Commit 31db9a9

Browse files
committed
Add test for some samples.
1 parent a2cd34b commit 31db9a9

File tree

6 files changed

+191
-0
lines changed

6 files changed

+191
-0
lines changed

appengine/memcache/guestbook/tests/__init__.py

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2015 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+
15+
import unittest
16+
17+
# from the app main.py
18+
from appengine.memcache.guestbook import main
19+
20+
from google.appengine.datastore import datastore_stub_util
21+
from google.appengine.ext import testbed
22+
23+
import webapp2
24+
25+
26+
class TestHandlers(unittest.TestCase):
27+
def setUp(self):
28+
"""Setup the datastore and memcache stub."""
29+
# First, create an instance of the Testbed class.
30+
self.testbed = testbed.Testbed()
31+
# Then activate the testbed, which prepares the service stubs for
32+
# use.
33+
self.testbed.activate()
34+
# Create a consistency policy that will simulate the High
35+
# Replication consistency model.
36+
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
37+
probability=0)
38+
# Initialize the datastore stub with this policy.
39+
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
40+
self.testbed.init_memcache_stub()
41+
42+
def tearDown(self):
43+
self.testbed.deactivate()
44+
45+
def test_hello(self):
46+
# Build a request object passing the URI path to be tested.
47+
# You can also pass headers, query arguments etc.
48+
request = webapp2.Request.blank('/')
49+
# Get a response for that request.
50+
response = request.get_response(main.app)
51+
52+
# Let's check if the response is correct.
53+
self.assertEqual(response.status_int, 200)
54+
# self.assertEqual(response.body, 'Hello, world!')

datastore/ndb/overview/tests/__init__.py

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2015 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+
15+
import unittest
16+
17+
# from the app main.py
18+
from datastore.ndb.overview import main
19+
20+
from google.appengine.datastore import datastore_stub_util
21+
from google.appengine.ext import testbed
22+
23+
import webapp2
24+
25+
26+
class TestHandlers(unittest.TestCase):
27+
def setUp(self):
28+
"""Setup the datastore and memcache stub."""
29+
# First, create an instance of the Testbed class.
30+
self.testbed = testbed.Testbed()
31+
# Then activate the testbed, which prepares the service stubs for
32+
# use.
33+
self.testbed.activate()
34+
# Create a consistency policy that will simulate the High
35+
# Replication consistency model.
36+
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
37+
probability=0)
38+
# Initialize the datastore stub with this policy.
39+
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
40+
self.testbed.init_memcache_stub()
41+
42+
def tearDown(self):
43+
self.testbed.deactivate()
44+
45+
def test_hello(self):
46+
# Build a request object passing the URI path to be tested.
47+
# You can also pass headers, query arguments etc.
48+
request = webapp2.Request.blank('/')
49+
# Get a response for that request.
50+
response = request.get_response(main.app)
51+
52+
# Let's check if the response is correct.
53+
self.assertEqual(response.status_int, 200)
54+
# self.assertEqual(response.body, 'Hello, world!')

datastore/ndb/transactions/tests/__init__.py

Whitespace-only changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2015 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+
15+
import unittest
16+
17+
# from the app main.py
18+
from datastore.ndb.transactions import main
19+
20+
from google.appengine.datastore import datastore_stub_util
21+
from google.appengine.ext import testbed
22+
23+
24+
25+
class TestHandlers(unittest.TestCase):
26+
def setUp(self):
27+
"""Setup the datastore and memcache stub."""
28+
# First, create an instance of the Testbed class.
29+
self.testbed = testbed.Testbed()
30+
# Then activate the testbed, which prepares the service stubs for
31+
# use.
32+
self.testbed.activate()
33+
# Create a consistency policy that will simulate the High
34+
# Replication consistency model.
35+
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
36+
probability=0)
37+
# Initialize the datastore stub with this policy.
38+
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
39+
self.testbed.init_memcache_stub()
40+
41+
main.app.config['TESTING'] = True
42+
self.app = main.app.test_client()
43+
44+
def tearDown(self):
45+
self.testbed.deactivate()
46+
47+
def test_hello(self):
48+
rv = self.app.get('/')
49+
self.assertIn('Permenant note page', rv.data)
50+
self.assertEqual(rv.status, '200 OK')
51+
52+
def test_post(self):
53+
rv = self.app.post('/add', data=dict(
54+
note_title='Title',
55+
note_text='Text'
56+
), follow_redirects=True)
57+
self.assertEqual(rv.status, '200 OK')
58+
59+
def test_post2(self):
60+
rv = self.app.post('/add', data=dict(
61+
note_title='Title2',
62+
note_text='Text'
63+
), follow_redirects=True)
64+
self.assertEqual(rv.status, '200 OK')
65+
66+
def test_post3(self):
67+
rv = self.app.post('/add', data=dict(
68+
note_title='Title3',
69+
note_text='Text'
70+
), follow_redirects=True)
71+
self.assertEqual(rv.status, '200 OK')
72+
73+
def test_there(self):
74+
rv = self.app.post('/add', data=dict(
75+
note_title='Title',
76+
note_text='New'
77+
), follow_redirects=True)
78+
rv = self.app.post('/add', data=dict(
79+
note_title='Title',
80+
note_text='There'
81+
), follow_redirects=True)
82+
self.assertIn('Already there', rv.data)
83+
self.assertEqual(rv.status, '200 OK')

0 commit comments

Comments
 (0)