From 73d220c41823e773d60451491543cd6eae14805b Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 14 Sep 2015 10:35:29 -0700 Subject: [PATCH 1/7] Fixing typo of datstore to datastore, closes #61 --- appengine/localtesting/test_datastore.py | 2 +- blog/introduction-to-data-models-in-cloud-datastore/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appengine/localtesting/test_datastore.py b/appengine/localtesting/test_datastore.py index 512d32e6332..8a505d05b1a 100644 --- a/appengine/localtesting/test_datastore.py +++ b/appengine/localtesting/test_datastore.py @@ -47,7 +47,7 @@ def GetEntityViaMemcache(entity_key): # [START datastore_example_test] -class DatstoreTestCase(unittest.TestCase): +class DatastoreTestCase(unittest.TestCase): def setUp(self): # First, create an instance of the Testbed class. diff --git a/blog/introduction-to-data-models-in-cloud-datastore/README.md b/blog/introduction-to-data-models-in-cloud-datastore/README.md index 1620f5dc016..a94f51f3949 100644 --- a/blog/introduction-to-data-models-in-cloud-datastore/README.md +++ b/blog/introduction-to-data-models-in-cloud-datastore/README.md @@ -1,7 +1,7 @@ # Introduction to data models in Cloud Datastore This sample code is used in [this blog post](). It demonstrates two data models -using [Google Cloud Datstore](https://cloud.google.com/datastore). +using [Google Cloud Datastore](https://cloud.google.com/datastore). ## Prerequisites From c48772b515276c388f02a153f138f6368ee67914 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 14 Sep 2015 10:46:14 -0700 Subject: [PATCH 2/7] Some improvements to images test case coverage (this needs to be revisited and updated to webtest) --- appengine/images/tests/test_guestbook.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/appengine/images/tests/test_guestbook.py b/appengine/images/tests/test_guestbook.py index 6daa09dec32..dd07ca79f8c 100644 --- a/appengine/images/tests/test_guestbook.py +++ b/appengine/images/tests/test_guestbook.py @@ -28,6 +28,12 @@ def setUp(self): reload(main) def test_get(self): + main.Greeting( + parent=main.guestbook_key('default_guestbook'), + author='123', + content='abc' + ).put() + # Build a request object passing the URI path to be tested. # You can also pass headers, query arguments etc. request = webapp2.Request.blank('/') @@ -43,7 +49,7 @@ def test_post(self, mock_images): request = webapp2.Request.blank( '/sign', POST={'content': 'asdf'}, - ) + ) response = request.get_response(main.app) mock_images.resize.assert_called_once_with(mock.ANY, 32, 32) @@ -53,10 +59,11 @@ def test_post(self, mock_images): def test_img(self): greeting = main.Greeting( parent=main.guestbook_key('default_guestbook'), - id=123, + id=123 ) greeting.author = 'asdf' greeting.content = 'asdf' + greeting.avatar = b'123' greeting.put() request = webapp2.Request.blank( @@ -79,7 +86,7 @@ def test_post_and_get(self, mock_images): request = webapp2.Request.blank( '/sign', POST={'content': 'asdf'}, - ) + ) response = request.get_response(main.app) request = webapp2.Request.blank('/') From cdab5f0d2e8b191163ce04d3dadfbe7528a6cc45 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 14 Sep 2015 10:50:45 -0700 Subject: [PATCH 3/7] Adding main block to coverage ignore --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index d312cd95450..77313b95b00 100644 --- a/.coveragerc +++ b/.coveragerc @@ -10,3 +10,4 @@ include = [report] exclude_lines = pragma: NO COVER + if __name__ == '__main__' From 23ae9b202c57c155ce2216510ed3deebaad75231 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 14 Sep 2015 10:54:50 -0700 Subject: [PATCH 4/7] 100% coverage for storage tests --- storage/tests/test_compose_objects.py | 29 +++++++++++++++++++++++++++ tests/resources/file1.txt | 1 + tests/resources/file2.txt | 1 + 3 files changed, 31 insertions(+) create mode 100644 storage/tests/test_compose_objects.py create mode 100644 tests/resources/file1.txt create mode 100644 tests/resources/file2.txt diff --git a/storage/tests/test_compose_objects.py b/storage/tests/test_compose_objects.py new file mode 100644 index 00000000000..d9ca356904c --- /dev/null +++ b/storage/tests/test_compose_objects.py @@ -0,0 +1,29 @@ +# Copyright 2015, Google, Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os + +from storage.compose_objects import main +from tests import CloudBaseTest + + +class TestComposeObjects(CloudBaseTest): + def test_main(self): + args = [ + 'ignored_command_name', + self.constants['bucketName'], + 'dest.txt', + os.path.join(self.resource_path, 'file1.txt'), + os.path.join(self.resource_path, 'file2.txt'), + ] + main(args) diff --git a/tests/resources/file1.txt b/tests/resources/file1.txt new file mode 100644 index 00000000000..e2129701f1a --- /dev/null +++ b/tests/resources/file1.txt @@ -0,0 +1 @@ +file1 diff --git a/tests/resources/file2.txt b/tests/resources/file2.txt new file mode 100644 index 00000000000..6c493ff740f --- /dev/null +++ b/tests/resources/file2.txt @@ -0,0 +1 @@ +file2 From 7e9e500025ce82dab9da334dd6623c05799838fa Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 14 Sep 2015 11:29:26 -0700 Subject: [PATCH 5/7] Renaming blog folder for datastore samples to be a proper package name, increasing coverage --- .coveragerc | 2 +- blog/__init__.py | 0 .../README.md | 0 .../__init__.py | 0 .../blog.py | 0 .../requirements.txt | 0 .../test_blog.py | 2 +- .../test_wiki.py | 22 +++++++++++++++++++ .../wiki.py | 0 tox.ini | 12 ++++------ 10 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 blog/__init__.py rename blog/{introduction-to-data-models-in-cloud-datastore => introduction_to_data_models_in_cloud_datastore}/README.md (100%) create mode 100644 blog/introduction_to_data_models_in_cloud_datastore/__init__.py rename blog/{introduction-to-data-models-in-cloud-datastore => introduction_to_data_models_in_cloud_datastore}/blog.py (100%) rename blog/{introduction-to-data-models-in-cloud-datastore => introduction_to_data_models_in_cloud_datastore}/requirements.txt (100%) rename blog/{introduction-to-data-models-in-cloud-datastore => introduction_to_data_models_in_cloud_datastore}/test_blog.py (97%) create mode 100644 blog/introduction_to_data_models_in_cloud_datastore/test_wiki.py rename blog/{introduction-to-data-models-in-cloud-datastore => introduction_to_data_models_in_cloud_datastore}/wiki.py (100%) diff --git a/.coveragerc b/.coveragerc index 77313b95b00..5a6f23dafbb 100644 --- a/.coveragerc +++ b/.coveragerc @@ -10,4 +10,4 @@ include = [report] exclude_lines = pragma: NO COVER - if __name__ == '__main__' + if __name__ == '__main__': diff --git a/blog/__init__.py b/blog/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/blog/introduction-to-data-models-in-cloud-datastore/README.md b/blog/introduction_to_data_models_in_cloud_datastore/README.md similarity index 100% rename from blog/introduction-to-data-models-in-cloud-datastore/README.md rename to blog/introduction_to_data_models_in_cloud_datastore/README.md diff --git a/blog/introduction_to_data_models_in_cloud_datastore/__init__.py b/blog/introduction_to_data_models_in_cloud_datastore/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/blog/introduction-to-data-models-in-cloud-datastore/blog.py b/blog/introduction_to_data_models_in_cloud_datastore/blog.py similarity index 100% rename from blog/introduction-to-data-models-in-cloud-datastore/blog.py rename to blog/introduction_to_data_models_in_cloud_datastore/blog.py diff --git a/blog/introduction-to-data-models-in-cloud-datastore/requirements.txt b/blog/introduction_to_data_models_in_cloud_datastore/requirements.txt similarity index 100% rename from blog/introduction-to-data-models-in-cloud-datastore/requirements.txt rename to blog/introduction_to_data_models_in_cloud_datastore/requirements.txt diff --git a/blog/introduction-to-data-models-in-cloud-datastore/test_blog.py b/blog/introduction_to_data_models_in_cloud_datastore/test_blog.py similarity index 97% rename from blog/introduction-to-data-models-in-cloud-datastore/test_blog.py rename to blog/introduction_to_data_models_in_cloud_datastore/test_blog.py index f1e866f9150..113d3c974a0 100644 --- a/blog/introduction-to-data-models-in-cloud-datastore/test_blog.py +++ b/blog/introduction_to_data_models_in_cloud_datastore/test_blog.py @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from blog import main +from .blog import main from tests import CloudBaseTest diff --git a/blog/introduction_to_data_models_in_cloud_datastore/test_wiki.py b/blog/introduction_to_data_models_in_cloud_datastore/test_wiki.py new file mode 100644 index 00000000000..6e3b69c10ed --- /dev/null +++ b/blog/introduction_to_data_models_in_cloud_datastore/test_wiki.py @@ -0,0 +1,22 @@ +# Copyright 2015, Google, Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .wiki import main +from tests import CloudBaseTest + + +class WikiTestCase(CloudBaseTest): + """Simple test case that ensures the wiki code doesn't throw any errors.""" + + def test_main(self): + main(self.constants['projectId']) diff --git a/blog/introduction-to-data-models-in-cloud-datastore/wiki.py b/blog/introduction_to_data_models_in_cloud_datastore/wiki.py similarity index 100% rename from blog/introduction-to-data-models-in-cloud-datastore/wiki.py rename to blog/introduction_to_data_models_in_cloud_datastore/wiki.py diff --git a/tox.ini b/tox.ini index be6b9b3ef80..521cba10655 100644 --- a/tox.ini +++ b/tox.ini @@ -14,10 +14,10 @@ deps = coverage nose-exclude coverargs = - --with-coverage - --cover-tests - --cover-branches - --cover-inclusive + --with-coverage + --cover-tests + --cover-branches + --cover-inclusive [testenv:gae] deps = @@ -49,11 +49,7 @@ deps = gcloud commands = nosetests \ - --exclude-dir=bigquery/tests/appengine \ - --exclude-dir=bigquery/samples/appengine_auth \ --exclude-dir=appengine \ - --exclude-dir=datastore/ndb \ - --exclude-dir=localtesting \ {[testenv]coverargs} \ {posargs} From 795e5ec6a017fb6f0beb2a9a5474fd53674c9fe9 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 14 Sep 2015 11:31:16 -0700 Subject: [PATCH 6/7] Adding link to datastore blog sample in datstore directory --- datastore/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/datastore/README.md b/datastore/README.md index 53711bb146e..ebea408ecfa 100644 --- a/datastore/README.md +++ b/datastore/README.md @@ -5,3 +5,4 @@ This section contains samples for [Google Cloud Datastore](https://cloud.google. ## Other Samples * [Google App Engine & NDB](../appengine/ndb). +* [Blog Sample: Introduction to Data Models in Cloud Datastore](../blog/introduction_to_data_models_in_cloud_datastore). From d9ea86ade87675d59c39834d6fd432a19b4e91d6 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 14 Sep 2015 13:04:43 -0700 Subject: [PATCH 7/7] Fixing lint issues --- .../test_blog.py | 3 ++- .../test_wiki.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/blog/introduction_to_data_models_in_cloud_datastore/test_blog.py b/blog/introduction_to_data_models_in_cloud_datastore/test_blog.py index 113d3c974a0..f3042700deb 100644 --- a/blog/introduction_to_data_models_in_cloud_datastore/test_blog.py +++ b/blog/introduction_to_data_models_in_cloud_datastore/test_blog.py @@ -11,9 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .blog import main from tests import CloudBaseTest +from .blog import main + class BlogTestCase(CloudBaseTest): """Simple test case that ensures the blog code doesn't throw any errors.""" diff --git a/blog/introduction_to_data_models_in_cloud_datastore/test_wiki.py b/blog/introduction_to_data_models_in_cloud_datastore/test_wiki.py index 6e3b69c10ed..19a850e8eb9 100644 --- a/blog/introduction_to_data_models_in_cloud_datastore/test_wiki.py +++ b/blog/introduction_to_data_models_in_cloud_datastore/test_wiki.py @@ -11,9 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .wiki import main from tests import CloudBaseTest +from .wiki import main + class WikiTestCase(CloudBaseTest): """Simple test case that ensures the wiki code doesn't throw any errors."""