Skip to content

Commit f17f951

Browse files
author
Jonathan Wayne Parrott
committed
Merge pull request #33 from jeffmendoza/tests
Add test for some samples.
2 parents a2cd34b + 16bccd0 commit f17f951

File tree

14 files changed

+162
-94
lines changed

14 files changed

+162
-94
lines changed

appengine/memcache/guestbook/tests/__init__.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
# from the app main.py
16+
from appengine.memcache.guestbook import main
17+
from tests import DatastoreTestbedCase
18+
19+
import webapp2
20+
21+
22+
class TestHandlers(DatastoreTestbedCase):
23+
def test_hello(self):
24+
# Build a request object passing the URI path to be tested.
25+
# You can also pass headers, query arguments etc.
26+
request = webapp2.Request.blank('/')
27+
# Get a response for that request.
28+
response = request.get_response(main.app)
29+
30+
# Let's check if the response is correct.
31+
self.assertEqual(response.status_int, 200)

datastore/ndb/modeling/tests/test_base.py

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

datastore/ndb/modeling/tests/test_contact_with_group_models.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414

1515
"""Test classes for code snippet for modeling article."""
1616

17-
18-
import unittest
19-
2017
from datastore.ndb.modeling import contact_with_group_models as models
2118

2219
from google.appengine.ext import ndb
2320

24-
import test_base
21+
from tests import DatastoreTestbedCase
2522

2623

27-
class ContactTestCase(test_base.TestCase):
24+
class ContactTestCase(DatastoreTestbedCase):
2825
"""A test case for the Contact model with groups."""
2926
def setUp(self):
3027
"""Creates 3 contacts and 1 group.
@@ -57,7 +54,3 @@ def test_groups(self):
5754
# How about 'members' property?
5855
friend_list = friends.members.fetch()
5956
self.assertEqual(len(friend_list), 1)
60-
61-
62-
if __name__ == '__main__':
63-
unittest.main()

datastore/ndb/modeling/tests/test_keyproperty_models.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414

1515
"""Test classes for code snippet for modeling article."""
1616

17-
1817
import unittest
1918

2019
from datastore.ndb.modeling import keyproperty_models as models
2120

22-
import test_base
21+
from tests import DatastoreTestbedCase
2322

2423

25-
class ContactTestCase(test_base.TestCase):
24+
class ContactTestCase(DatastoreTestbedCase):
2625
"""A test case for the Contact model class with KeyProperty."""
2726
NAME = 'Takashi Matsuo'
2827

@@ -50,7 +49,3 @@ def test_fails(self):
5049
numbers = contact.phone_numbers.fetch()
5150
self.assertEqual(1, len(numbers))
5251
# [END failing_test]
53-
54-
55-
if __name__ == '__main__':
56-
unittest.main()

datastore/ndb/modeling/tests/test_naive_models.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
1414

1515
"""Test classes for code snippet for modeling article."""
1616

17-
18-
import unittest
19-
2017
from datastore.ndb.modeling import naive_models as models
2118

22-
import test_base
19+
from tests import DatastoreTestbedCase
2320

2421

25-
class ContactTestCase(test_base.TestCase):
22+
class ContactTestCase(DatastoreTestbedCase):
2623
"""A test case for the naive Contact model classe."""
2724
NAME = 'Takashi Matsuo'
2825

@@ -36,7 +33,3 @@ def test_basic(self):
3633
"""Test for getting a NaiveContact entity."""
3734
contact = self.contact_key.get()
3835
self.assertEqual(contact.name, self.NAME)
39-
40-
41-
if __name__ == '__main__':
42-
unittest.main()

datastore/ndb/modeling/tests/test_parent_child_models.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414

1515
"""Test classes for code snippet for modeling article."""
1616

17-
18-
import unittest
19-
2017
from datastore.ndb.modeling import parent_child_models as models
2118

2219
from google.appengine.ext import ndb
2320

24-
import test_base
21+
from tests import DatastoreTestbedCase
2522

2623

27-
class ContactTestCase(test_base.TestCase):
24+
class ContactTestCase(DatastoreTestbedCase):
2825
"""A test case for the Contact model class with KeyProperty."""
2926
NAME = 'Takashi Matsuo'
3027

@@ -83,7 +80,3 @@ def test_phone_numbers(self):
8380
models.PhoneNumber.phone_type == 'mobile')
8481
entities = query.fetch()
8582
self.assertEqual(0, len(entities))
86-
87-
88-
if __name__ == '__main__':
89-
unittest.main()

datastore/ndb/modeling/tests/test_relation_model_models.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414

1515
"""Test classes for code snippet for modeling article."""
1616

17-
18-
import unittest
19-
2017
from datastore.ndb.modeling import relation_model_models as models
2118

2219
from google.appengine.ext import ndb
2320

24-
import test_base
21+
from tests import DatastoreTestbedCase
2522

2623

27-
class ContactTestCase(test_base.TestCase):
24+
class ContactTestCase(DatastoreTestbedCase):
2825
"""A test case for the Contact model with relationship model."""
2926
def setUp(self):
3027
"""Creates 1 contact and 1 company.
@@ -60,7 +57,3 @@ def test_relationship(self):
6057
title='president').put()
6158
# get the list of companies that Mary belongs to
6259
self.assertEqual(len(mary.companies), 2)
63-
64-
65-
if __name__ == '__main__':
66-
unittest.main()

datastore/ndb/modeling/tests/test_structured_property_models.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
1414

1515
"""Test classes for code snippet for modeling article."""
1616

17-
18-
import unittest
19-
2017
from datastore.ndb.modeling import structured_property_models as models
2118

22-
import test_base
19+
from tests import DatastoreTestbedCase
2320

2421

25-
class ContactTestCase(test_base.TestCase):
22+
class ContactTestCase(DatastoreTestbedCase):
2623
"""A test case for the Contact model with StructuredProperty."""
2724
def setUp(self):
2825
"""Creates one Contact entity with 2 phone numbers."""
@@ -67,7 +64,3 @@ def test_phone_numbers(self):
6764
self.assertEqual(len(scott.phone_numbers), 1)
6865
self.assertEqual(scott.phone_numbers[0].phone_type, 'home')
6966
self.assertEqual(scott.phone_numbers[0].number, '(650) 555 - 2200')
70-
71-
72-
if __name__ == '__main__':
73-
unittest.main()

datastore/ndb/overview/tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)