├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app.yaml ├── appengine_config.py ├── client_secrets.json.enc ├── favicon.ico ├── main.py ├── migrations ├── README ├── alembic.ini ├── env.py ├── script.py.mako └── versions │ └── 3f1a8c31532b_.py ├── queue.yaml ├── requirements.txt ├── testrunner.py ├── tests ├── test_datastore.py ├── test_env_vars.py ├── test_login.py ├── test_mail.py └── test_task_queue.py └── vendor.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### VirtualEnv template 3 | # Virtualenv 4 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ 5 | .Python 6 | [Bb]in 7 | [Ii]nclude 8 | [Ll]ib 9 | [Ss]cripts 10 | pyvenv.cfg 11 | pip-selfcheck.json 12 | 13 | 14 | ### Python template 15 | # Byte-compiled / optimized / DLL files 16 | __pycache__/ 17 | *.py[cod] 18 | 19 | # C extensions 20 | *.so 21 | 22 | # Distribution / packaging 23 | .Python 24 | env/ 25 | build/ 26 | develop-eggs/ 27 | dist/ 28 | downloads/ 29 | eggs/ 30 | .eggs/ 31 | lib/ 32 | lib64/ 33 | parts/ 34 | sdist/ 35 | var/ 36 | *.egg-info/ 37 | .installed.cfg 38 | *.egg 39 | 40 | # PyInstaller 41 | # Usually these files are written by a python script from a template 42 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 43 | *.manifest 44 | *.spec 45 | 46 | # Installer logs 47 | pip-log.txt 48 | pip-delete-this-directory.txt 49 | 50 | # Unit test / coverage reports 51 | htmlcov/ 52 | .tox/ 53 | .coverage 54 | .coverage.* 55 | .cache 56 | nosetests.xml 57 | coverage.xml 58 | *,cover 59 | 60 | # Translations 61 | *.mo 62 | *.pot 63 | 64 | # Django stuff: 65 | *.log 66 | 67 | # Sphinx documentation 68 | docs/_build/ 69 | 70 | # PyBuilder 71 | target/ 72 | 73 | 74 | 75 | ### JetBrains template 76 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 77 | 78 | *.iml 79 | 80 | ## Directory-based project format: 81 | .idea/ 82 | # if you remove the above rule, at least ignore the following: 83 | 84 | # User-specific stuff: 85 | # .idea/workspace.xml 86 | # .idea/tasks.xml 87 | # .idea/dictionaries 88 | 89 | # Sensitive or high-churn files: 90 | # .idea/dataSources.ids 91 | # .idea/dataSources.xml 92 | # .idea/sqlDataSources.xml 93 | # .idea/dynamic.xml 94 | # .idea/uiDesigner.xml 95 | 96 | # Gradle: 97 | # .idea/gradle.xml 98 | # .idea/libraries 99 | 100 | # Mongo Explorer plugin: 101 | # .idea/mongoSettings.xml 102 | 103 | ## File-based project format: 104 | *.ipr 105 | *.iws 106 | 107 | ## Plugin-specific files: 108 | 109 | # IntelliJ 110 | /out/ 111 | 112 | # mpeltonen/sbt-idea plugin 113 | .idea_modules/ 114 | 115 | # JIRA plugin 116 | atlassian-ide-plugin.xml 117 | 118 | # Crashlytics plugin (for Android Studio and IntelliJ) 119 | com_crashlytics_export_strings.xml 120 | crashlytics.properties 121 | crashlytics-build.properties 122 | 123 | 124 | 125 | client_secrets.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: python 3 | python: 4 | - '2.7' 5 | cache: 6 | directories: 7 | - $HOME/gcloud/ 8 | env: 9 | global: 10 | - PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/client_secrets.json 11 | - secure: "ILXZQVz32tbzGb8iwvQEMPreKNRO/kXQAalwqjK/6CEyn1S0b35+sFNvYkMb7vFTixStJA9Jks+iJ/CEXTySNcJLhU89wiZEOUnRz+VdDRbFmIJ/+w3N/tlYjFCxGTL1jtTjwPEuxUjVQxrJ1B6MmRHTdlvXrpFyd1PTsn5Uyxxc0DdB3q5QDkn3kfX5kKZ7W4AR8LgDe+wHfs29kmhvnmk+9ADh9yYx+63xobKGJJBQDDEbR9M4AKAm71oImjmMpkz5Fzxvi4VvkLccDcKGEUeN+OWFWiOAmjEz0UCar5xBE3/Hzlc5DGXLBFfRg0AH47lZj04AeQri3hTW26YVZ2uyPOl19q9LLGkrJKTKf+Ov44qsubAs4/qGAlksu74nvGmKBKOf/kUYJ52a2cm0fuIkZJY4y99F4Mp3pDoFmYecAmWpAvugDBPpClY9l+5guccjoIe0bnErZF4xrTY19TLIV+RjeBqJ6MfPD5SybW+PU8Sk1/YQTLPT9WCRWm5vxXaJ43jPJSVNufqoyGhW7lLeCf3xpZUgm9m/aipOVPyTg74h9IrhcMLy+tTalgmrQwZOLnSybTxAQA+9LFEHv+1PcNa5hYkKlJ7x/XQ83q4R4JrLs3907GSYo51+B3RK5u/bG659UYPMmCYRqdDrbDTqrBQqoNGxEruT/W5pChU=" 12 | - secure: "USySRXCv0jiqrSbc38WSjW3A55iXJPoG3VSoCa2HaZJAADQ3ALjBYI8wq+ZaC7IlffxLA7vHp5S6aq5xfI/GGrhKXpTq2TQcbbq4dzU2yaX/tD4XFrQuMvsI5oHQz/ys+zCccUa4uLcPetDTvuCcvtJPdr/v4aNsou+35JZ/RzyQoEXjVFtt+l+JDu8jNOrl9LgXX3nN5/wvU9bHSMpLJgJaXGpF4WhkANtY72V+Ddwj6ZhpC5hlBwKjVx8rZvphemG43uCgU65my+Nodx7l4MLk18d/nIINVkpKuoXv2wYO+A85Lt4qHkHAya+FGVtFe7Pju2M0QcDwVws+c/M+7UsKLVdl1a6o5CAJs8heAt08jZae2ro8cJiJjiSGFPjugRiFf4LWqWYiynY1Qk9ooKSjFqpSib1Myk3Mmss7Eqis07YO7S44cqCSg4JXKQialduBIC7d+UYJan9YziBUmDr+YkKTy2rTHmiqUB95TDS+G0+JCueXmNWX1Fdpy+20osoTcBbS31NFCDLMTJ/QS1QzU7OxjEd5WwQZ8WiWSGE032wyHt9rMaL9c8h9G35f5T+H5CQjaDO0wUUU0B4xZ9+REsocHELcuaVBh2yfJvLJP6ln9vxb2pdVDAytHFbZ7KH4JQz5yeyWsLabCDr+ELzos8EhQGXwJ/qvDPz9IfI=" 13 | - secure: "DnVaMAqBADOgIaUamB5TnWp6+IR/BjemHRX4wjkKViGwac7tvnqCUmKcOcZBHyPfn/DxKaC3pXW47eJOGibQQtpO+RpOkKgqaMHhQn87LZ5guGfamrYTIkUlu0qjSWKjF7zynwfFhI0wBD99CZv+sIE48epvN6G+zLXUvFoDfBE26b1B2HlRYIFx9ZvDVexArg+EJ0hQmVg5AwPa6E7ABjrvShcYsGmf9mqfzP7hKgxQvItlGJIUL+zcoz54nL6SgLJypbDSmTf3Le7hd3Zfv4R7CcyGcPjnhEA9O4xXBrCeGMvmPyS2cQsPCVrxrc7E5PvXDknSZMsNOqLbQ9p9MBhcXfQbnu/HwbBzpRuWupXnavn7RXhzc2qS2L/X9Svy81ObvmfbAWziQ2ddIHxv4W+GfVD4xcm9XcAvJw9IHDMRrPx+oTgAw/sBz7kGmtOD7Omj/nDxfNV7QEr4QksbIkpMOjXyMU3oCWrxcvjJJS5o/oqhnPwCDjyWpulIK1HxEHGR5SPDUYAmoriI6wQKxRcxCT1tbW9YO517WnYeKf12sSYTnkR6slx1nhdBRLACJEG7KuIADrc/CsXP8YC8cN9za+xEkno+GeHmkL5kJyqBohX15uL+NvZHwlMkNbW/2Rszi1meW11rvqmZ4uHOZ57eB9+jUs8NnbF/o2ulOv0=" 14 | - secure: "D5gE1Lv7VgkbO3uCK0eMvoPGj8o7Qam77qb3DdsxjeWETmxBzkvmzzYx2mTggyKJMyZFP+1DV01aDybR6I+F88Vp1UxS4nxE82cjjUAik8LbK4LxQ0T4dmvgc+28551V3fysGRfB54tHuYkD3v6J+C34KdotVU9X2rtLKF2jay78b0VV2KKil2Nz0k5Qzrv6x7Lx4aMynVqQLY1MAc+LytNFXnxmyLJ5e3E50OEVL1c0EsAPUHze1g/KcMQV3vdch/Q0nZUTm7ShbmW5X9h0hMYiwHZF4LMA9BczUOqciFUg3BdjRM8P2akOhAPjJekr8ue6cIDnl7bdMgExSqEh37I7iMMm9dXYK000Am4dwW7a0puW+u336cDCuMdsZIEz/btSCSmsRMDSDFYBo69IpYXPDucZIU7B3pWzyjd/3ycl2Obfr6D5tGVLdAYHOcR35sesguIUVLRR07miswQiX+FyDVy2eyjLdQM1DAdcv0/HhCmTelkcZRb5jqU/SvkIO7Rf/ml0PRINuwYu/2sAwUUMraD/FHKAmggNDh848LPPr5GANt2ESCgvuuINcRMMCJ3LT6+xllkvgs7HHhx2Rctc1tio6sL1k2GnzX7aU8+wklkDaaDdsTWaCEzQPgShN9CavVxSlQyYyNT7NLt+RatT8Qs4IuIT8ZcdFWRFB/M=" 15 | - versionlabel=$(git rev-parse --abbrev-ref HEAD)-$(date -u +"%Y%m%d-%H%M%S") 16 | 17 | before_install: 18 | - openssl aes-256-cbc -K $encrypted_0f97f4d13dc8_key -iv $encrypted_0f97f4d13dc8_iv 19 | -in client_secrets.json.enc -out client_secrets.json -d 20 | - if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then mkdir -p $HOME/gcloud && wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz 21 | --directory-prefix=$HOME/gcloud && cd $HOME/gcloud && tar xzf google-cloud-sdk.tar.gz 22 | && printf '\ny\n\ny\ny\n' | ./google-cloud-sdk/install.sh && cd $TRAVIS_BUILD_DIR; 23 | fi 24 | - gcloud -q components update 25 | - if [ -a client_secrets.json ]; then gcloud -q auth activate-service-account --key-file 26 | client_secrets.json; fi 27 | - gcloud config set project causal-flame-94214 28 | 29 | install: 30 | - pip install -t lib -r requirements.txt 31 | - pip install virtualenvwrapper 32 | - source virtualenvwrapper.sh 33 | - add2virtualenv ./lib 34 | - pip install coveralls 35 | 36 | before_script: 37 | - mysql -e 'create database migrate_dev;' 38 | - TARGET_DB=$TEST_DB python main.py db upgrade 39 | 40 | script: 41 | # - python testrunner.py $HOME/gcloud/google-cloud-sdk ./tests 42 | - coverage run --source . testrunner.py $HOME/gcloud/google-cloud-sdk ./tests 43 | 44 | after_success: 45 | - coveralls 46 | - gcloud -q preview app deploy app.yaml --version=1 47 | # commenting this out since the dedicated ip addy was removed to avoid costs! 48 | # - TARGET_DB=$PROD_DB python main.py db upgrade 49 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement 9 | (CLA). 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then you'll need to sign an [individual CLA] 13 | (https://developers.google.com/open-source/cla/individual). 14 | * If you work for a company that wants to allow you to contribute your work, 15 | then you'll need to sign a [corporate CLA] 16 | (https://developers.google.com/open-source/cla/corporate). 17 | 18 | Follow either of the two links above to access the appropriate CLA and 19 | instructions for how to sign and return it. Once we receive it, we'll be able to 20 | accept your pull requests. 21 | 22 | ## Contributing A Patch 23 | 24 | 1. Submit an issue describing your proposed change to the repo in question. 25 | 1. The repo owner will respond to your issue promptly. 26 | 1. If your proposed change is accepted, and you haven't already done so, sign a 27 | Contributor License Agreement (see details above). 28 | 1. Fork the desired repo, develop and test your code changes. 29 | 1. Ensure that your code adheres to the existing style in the sample to which 30 | you are contributing. Refer to the 31 | [Google Cloud Platform Samples Style Guide] 32 | (https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the 33 | recommended coding standards for this organization. 34 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 35 | 1. Submit a pull request. 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Project Name [![Build Status](https://travis-ci.org/russomi/appengine-python-flask-travis-ci.svg?branch=master)](https://travis-ci.org/russomi/appengine-python-flask-travis-ci) [![Coverage Status](https://coveralls.io/repos/russomi/appengine-python-flask-travis-ci/badge.svg?branch=master)](https://coveralls.io/r/russomi/appengine-python-flask-travis-ci?branch=master) 2 | 3 | Project description. 4 | 5 | See our other [Google Cloud Platform github 6 | repos](https://github.com/GoogleCloudPlatform) for sample applications and 7 | scaffolding for other frameworks and use cases. 8 | 9 | ## Run Locally 10 | 1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/), including the [gcloud tool](https://cloud.google.com/sdk/gcloud/), and [gcloud app component](https://cloud.google.com/sdk/gcloud-app). 11 | 2. Setup the gcloud tool. 12 | 13 | ``` 14 | gcloud components update app 15 | gcloud auth login 16 | gcloud config set project 17 | ``` 18 | You don't need a valid app-id to run locally, but will need a valid id to deploy below. 19 | 20 | 1. Clone this repo. 21 | 22 | ``` 23 | git clone https://github.com/GoogleCloudPlatform/.git 24 | ``` 25 | 1. Run this project locally from the command line. 26 | 27 | ``` 28 | gcloud preview app run / 29 | ``` 30 | 31 | 1. Visit the application at [http://localhost:8080](http://localhost:8080). 32 | 33 | ## Deploying 34 | 35 | 1. Use the [Cloud Developer Console](https://console.developer.google.com) to create a project/app id. (App id and project id are identical) 36 | 2. Configure gcloud with your app id. 37 | 38 | ``` 39 | gcloud config set project 40 | ``` 41 | 1. Use the [Admin Console](https://appengine.google.com) to view data, queues, and other App Engine specific administration tasks. 42 | 1. Use gcloud to deploy your app. 43 | 44 | ``` 45 | gcloud preview app deploy / 46 | ``` 47 | 48 | 1. Congratulations! Your application is now live at your-app-id.appspot.com 49 | 50 | ## Contributing changes 51 | 52 | * See [CONTRIBUTING.md](CONTRIBUTING.md) 53 | 54 | ## Licensing 55 | 56 | * See [LICENSE](LICENSE) 57 | -------------------------------------------------------------------------------- /app.yaml: -------------------------------------------------------------------------------- 1 | # This file specifies your Python application's runtime configuration 2 | # including URL routing, versions, static file uploads, etc. See 3 | # https://developers.google.com/appengine/docs/python/config/appconfig 4 | # for details. 5 | 6 | # TODO: Enter your application id below. If you have signed up 7 | # using cloud.google.com/console use the "project id" for your application 8 | # id. 9 | 10 | # application: your-application-id-here 11 | # version: 1 12 | runtime: python27 13 | api_version: 1 14 | threadsafe: yes 15 | 16 | # Handlers define how to route requests to your application. 17 | handlers: 18 | 19 | # App Engine serves and caches static files contained in the listed directories 20 | # (and subdirectories). Uncomment and set the directory as needed. 21 | #- url: /client 22 | # static_dir: client 23 | 24 | # This handler tells app engine how to route requests to a WSGI application. 25 | # The script value is in the format . 26 | # where is a WSGI application object. 27 | - url: .* # This regex directs all routes to main.app 28 | script: main.app 29 | 30 | # Third party libraries that are included in the App Engine SDK must be listed 31 | # here if you want to use them. See 32 | # https://developers.google.com/appengine/docs/python/tools/libraries27 for 33 | # a list of libraries included in the SDK. Third party libs that are *not* part 34 | # of the App Engine SDK don't need to be listed here, instead add them to your 35 | # project directory, either as a git submodule or as a plain subdirectory. 36 | # TODO: List any other App Engine SDK libs you may need here. 37 | libraries: 38 | - name: MySQLdb 39 | version: latest 40 | -------------------------------------------------------------------------------- /appengine_config.py: -------------------------------------------------------------------------------- 1 | """`appengine_config` gets loaded when starting a new application instance.""" 2 | import vendor 3 | # insert `lib` as a site directory so our `main` module can load 4 | # third-party libraries, and override built-ins with newer 5 | # versions. 6 | vendor.add('lib') 7 | -------------------------------------------------------------------------------- /client_secrets.json.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/russomi-labs/appengine-python-flask-travis-ci/0eadba6a0b81a758dd5fc9ca971b636a3f156096/client_secrets.json.enc -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/russomi-labs/appengine-python-flask-travis-ci/0eadba6a0b81a758dd5fc9ca971b636a3f156096/favicon.ico -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | """`main` is the top level module for your Flask application.""" 2 | 3 | # Import the Flask Framework 4 | import os 5 | from flask import Flask 6 | from flask.ext.sqlalchemy import SQLAlchemy 7 | from flask.ext.script import Manager 8 | from flask.ext.migrate import Migrate, MigrateCommand 9 | 10 | app = Flask(__name__) 11 | app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('TARGET_DB') 12 | 13 | db = SQLAlchemy(app) 14 | migrate = Migrate(app, db) 15 | 16 | manager = Manager(app) 17 | manager.add_command('db', MigrateCommand) 18 | 19 | 20 | class User(db.Model): 21 | id = db.Column(db.Integer, primary_key=True) 22 | name = db.Column(db.String(128)) 23 | 24 | 25 | @app.route('/') 26 | def hello(): 27 | """Return a friendly HTTP greeting.""" 28 | return 'Hello World!' 29 | 30 | 31 | @app.errorhandler(404) 32 | def page_not_found(e): 33 | """Return a custom 404 error.""" 34 | return 'Sorry, Nothing at this URL.', 404 35 | 36 | 37 | @app.errorhandler(500) 38 | def page_not_found(e): 39 | """Return a custom 500 error.""" 40 | return 'Sorry, unexpected error: {}'.format(e), 500 41 | 42 | 43 | # this is used when we run manager commands from the terminal 44 | if __name__ == '__main__': 45 | manager.run() 46 | -------------------------------------------------------------------------------- /migrations/README: -------------------------------------------------------------------------------- 1 | Generic single-database configuration. -------------------------------------------------------------------------------- /migrations/alembic.ini: -------------------------------------------------------------------------------- 1 | # A generic, single database configuration. 2 | 3 | [alembic] 4 | # template used to generate migration files 5 | # file_template = %%(rev)s_%%(slug)s 6 | 7 | # set to 'true' to run the environment during 8 | # the 'revision' command, regardless of autogenerate 9 | # revision_environment = false 10 | 11 | 12 | # Logging configuration 13 | [loggers] 14 | keys = root,sqlalchemy,alembic 15 | 16 | [handlers] 17 | keys = console 18 | 19 | [formatters] 20 | keys = generic 21 | 22 | [logger_root] 23 | level = WARN 24 | handlers = console 25 | qualname = 26 | 27 | [logger_sqlalchemy] 28 | level = WARN 29 | handlers = 30 | qualname = sqlalchemy.engine 31 | 32 | [logger_alembic] 33 | level = INFO 34 | handlers = 35 | qualname = alembic 36 | 37 | [handler_console] 38 | class = StreamHandler 39 | args = (sys.stderr,) 40 | level = NOTSET 41 | formatter = generic 42 | 43 | [formatter_generic] 44 | format = %(levelname)-5.5s [%(name)s] %(message)s 45 | datefmt = %H:%M:%S 46 | -------------------------------------------------------------------------------- /migrations/env.py: -------------------------------------------------------------------------------- 1 | from __future__ import with_statement 2 | from alembic import context 3 | from sqlalchemy import engine_from_config, pool 4 | from logging.config import fileConfig 5 | 6 | # this is the Alembic Config object, which provides 7 | # access to the values within the .ini file in use. 8 | config = context.config 9 | 10 | # Interpret the config file for Python logging. 11 | # This line sets up loggers basically. 12 | fileConfig(config.config_file_name) 13 | 14 | # add your model's MetaData object here 15 | # for 'autogenerate' support 16 | # from myapp import mymodel 17 | # target_metadata = mymodel.Base.metadata 18 | from flask import current_app 19 | config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI')) 20 | target_metadata = current_app.extensions['migrate'].db.metadata 21 | 22 | # other values from the config, defined by the needs of env.py, 23 | # can be acquired: 24 | # my_important_option = config.get_main_option("my_important_option") 25 | # ... etc. 26 | 27 | 28 | def run_migrations_offline(): 29 | """Run migrations in 'offline' mode. 30 | 31 | This configures the context with just a URL 32 | and not an Engine, though an Engine is acceptable 33 | here as well. By skipping the Engine creation 34 | we don't even need a DBAPI to be available. 35 | 36 | Calls to context.execute() here emit the given string to the 37 | script output. 38 | 39 | """ 40 | url = config.get_main_option("sqlalchemy.url") 41 | context.configure(url=url) 42 | 43 | with context.begin_transaction(): 44 | context.run_migrations() 45 | 46 | 47 | def run_migrations_online(): 48 | """Run migrations in 'online' mode. 49 | 50 | In this scenario we need to create an Engine 51 | and associate a connection with the context. 52 | 53 | """ 54 | engine = engine_from_config(config.get_section(config.config_ini_section), 55 | prefix='sqlalchemy.', 56 | poolclass=pool.NullPool) 57 | 58 | connection = engine.connect() 59 | context.configure(connection=connection, 60 | target_metadata=target_metadata, 61 | **current_app.extensions['migrate'].configure_args) 62 | 63 | try: 64 | with context.begin_transaction(): 65 | context.run_migrations() 66 | finally: 67 | connection.close() 68 | 69 | if context.is_offline_mode(): 70 | run_migrations_offline() 71 | else: 72 | run_migrations_online() 73 | 74 | -------------------------------------------------------------------------------- /migrations/script.py.mako: -------------------------------------------------------------------------------- 1 | """${message} 2 | 3 | Revision ID: ${up_revision} 4 | Revises: ${down_revision} 5 | Create Date: ${create_date} 6 | 7 | """ 8 | 9 | # revision identifiers, used by Alembic. 10 | revision = ${repr(up_revision)} 11 | down_revision = ${repr(down_revision)} 12 | 13 | from alembic import op 14 | import sqlalchemy as sa 15 | ${imports if imports else ""} 16 | 17 | def upgrade(): 18 | ${upgrades if upgrades else "pass"} 19 | 20 | 21 | def downgrade(): 22 | ${downgrades if downgrades else "pass"} 23 | -------------------------------------------------------------------------------- /migrations/versions/3f1a8c31532b_.py: -------------------------------------------------------------------------------- 1 | """empty message 2 | 3 | Revision ID: 3f1a8c31532b 4 | Revises: None 5 | Create Date: 2015-05-12 11:18:09.966469 6 | 7 | """ 8 | 9 | # revision identifiers, used by Alembic. 10 | revision = '3f1a8c31532b' 11 | down_revision = None 12 | 13 | from alembic import op 14 | import sqlalchemy as sa 15 | 16 | 17 | def upgrade(): 18 | ### commands auto generated by Alembic - please adjust! ### 19 | op.create_table('user', 20 | sa.Column('id', sa.Integer(), nullable=False), 21 | sa.Column('name', sa.String(length=128), nullable=True), 22 | sa.PrimaryKeyConstraint('id') 23 | ) 24 | ### end Alembic commands ### 25 | 26 | 27 | def downgrade(): 28 | ### commands auto generated by Alembic - please adjust! ### 29 | op.drop_table('user') 30 | ### end Alembic commands ### 31 | -------------------------------------------------------------------------------- /queue.yaml: -------------------------------------------------------------------------------- 1 | queue: 2 | - name: default 3 | rate: 5/s 4 | - name: queue-1 5 | rate: 5/s 6 | - name: queue-2 7 | rate: 5/s 8 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # This requirements file lists all third-party dependencies for this project. 2 | # 3 | # Run 'pip install -r requirements.txt -t lib/' to install these dependencies 4 | # in `lib/` subdirectory. 5 | # 6 | # Note: The `lib` directory is added to `sys.path` by `appengine_config.py`. 7 | Flask==0.10 8 | Flask-Migrate 9 | MySQL-python -------------------------------------------------------------------------------- /testrunner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2015 Google Inc 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # [START runner] 17 | import optparse 18 | import sys 19 | import unittest 20 | import os 21 | 22 | USAGE = """%prog SDK_PATH TEST_PATH 23 | Run unit tests for App Engine apps. 24 | 25 | SDK_PATH Path to Google Cloud or Google App Engine SDK installation, usually 26 | ~/google_cloud_sdk 27 | TEST_PATH Path to package containing test modules""" 28 | 29 | 30 | def main(sdk_path, test_path): 31 | # If the sdk path points to a google cloud sdk installation 32 | # then we should alter it to point to the GAE platform location. 33 | if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')): 34 | sys.path.insert(0, os.path.join(sdk_path, 'platform/google_appengine')) 35 | else: 36 | sys.path.insert(0, sdk_path) 37 | 38 | # Ensure that the google.appengine.* packages are available 39 | # in tests as well as all bundled third-party packages. 40 | import dev_appserver 41 | dev_appserver.fix_sys_path() 42 | 43 | # Loading appengine_config from the current project ensures that any 44 | # changes to configuration there are available to all tests (e.g. 45 | # sys.path modifications, namespaces, etc.) 46 | try: 47 | import appengine_config 48 | (appengine_config) 49 | except ImportError: 50 | print "Note: unable to import appengine_config." 51 | 52 | # Discover and run tests. 53 | suite = unittest.loader.TestLoader().discover(test_path) 54 | result = unittest.TextTestRunner(verbosity=2).run(suite) 55 | 56 | # Fail the build if the suite was not successful! 57 | if not result.wasSuccessful(): 58 | sys.exit(result) 59 | 60 | if __name__ == '__main__': 61 | parser = optparse.OptionParser(USAGE) 62 | options, args = parser.parse_args() 63 | if len(args) != 2: 64 | print 'Error: Exactly 2 arguments required.' 65 | parser.print_help() 66 | sys.exit(1) 67 | SDK_PATH = args[0] 68 | TEST_PATH = args[1] 69 | main(SDK_PATH, TEST_PATH) 70 | 71 | # [END runner] 72 | -------------------------------------------------------------------------------- /tests/test_datastore.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc 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 | # [START imports] 16 | import unittest 17 | from google.appengine.api import memcache 18 | from google.appengine.ext import ndb 19 | from google.appengine.ext import testbed 20 | # [END imports] 21 | 22 | 23 | # [START datastore_example_1] 24 | class TestModel(ndb.Model): 25 | """A model class used for testing.""" 26 | number = ndb.IntegerProperty(default=42) 27 | text = ndb.StringProperty() 28 | 29 | 30 | class TestEntityGroupRoot(ndb.Model): 31 | """Entity group root""" 32 | pass 33 | 34 | 35 | def GetEntityViaMemcache(entity_key): 36 | """Get entity from memcache if available, from datastore if not.""" 37 | entity = memcache.get(entity_key) 38 | if entity is not None: 39 | return entity 40 | key = ndb.Key(urlsafe=entity_key) 41 | entity = key.get() 42 | if entity is not None: 43 | memcache.set(entity_key, entity) 44 | return entity 45 | # [END datastore_example_1] 46 | 47 | 48 | # [START datastore_example_test] 49 | class DatstoreTestCase(unittest.TestCase): 50 | 51 | def setUp(self): 52 | # First, create an instance of the Testbed class. 53 | self.testbed = testbed.Testbed() 54 | # Then activate the testbed, which prepares the service stubs for use. 55 | self.testbed.activate() 56 | # Next, declare which service stubs you want to use. 57 | self.testbed.init_datastore_v3_stub() 58 | self.testbed.init_memcache_stub() 59 | # Clear ndb's in-context cache between tests. 60 | # This prevents data from leaking between tests. 61 | # Alternatively, you could disable caching by 62 | # using ndb.get_context().set_cache_policy(False) 63 | ndb.get_context().clear_cache() 64 | 65 | # [END datastore_example_test] 66 | 67 | # [START datastore_example_teardown] 68 | def tearDown(self): 69 | self.testbed.deactivate() 70 | # [END datastore_example_teardown] 71 | 72 | # [START datastore_example_insert] 73 | def testInsertEntity(self): 74 | TestModel().put() 75 | self.assertEqual(1, len(TestModel.query().fetch(2))) 76 | # [END datastore_example_insert] 77 | 78 | # [START datastore_example_filter] 79 | def testFilterByNumber(self): 80 | root = TestEntityGroupRoot(id="root") 81 | TestModel(parent=root.key).put() 82 | TestModel(number=17, parent=root.key).put() 83 | query = TestModel.query(ancestor=root.key).filter(TestModel.number == 42) 84 | results = query.fetch(2) 85 | self.assertEqual(1, len(results)) 86 | self.assertEqual(42, results[0].number) 87 | # [END datastore_example_filter] 88 | 89 | # [START datastore_example_memcache] 90 | def testGetEntityViaMemcache(self): 91 | entity_key = TestModel(number=18).put().urlsafe() 92 | retrieved_entity = GetEntityViaMemcache(entity_key) 93 | self.assertNotEqual(None, retrieved_entity) 94 | self.assertEqual(18, retrieved_entity.number) 95 | # [END datastore_example_memcache] 96 | 97 | 98 | # [START HRD_example_1] 99 | from google.appengine.datastore import datastore_stub_util 100 | 101 | 102 | class HighReplicationTestCaseOne(unittest.TestCase): 103 | 104 | def setUp(self): 105 | # First, create an instance of the Testbed class. 106 | self.testbed = testbed.Testbed() 107 | # Then activate the testbed, which prepares the service stubs for use. 108 | self.testbed.activate() 109 | # Create a consistency policy that will simulate the High Replication 110 | # consistency model. 111 | self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy( 112 | probability=0) 113 | # Initialize the datastore stub with this policy. 114 | self.testbed.init_datastore_v3_stub(consistency_policy=self.policy) 115 | # Initialize memcache stub too, since ndb also uses memcache 116 | self.testbed.init_memcache_stub() 117 | # Clear in-context cache before each test. 118 | ndb.get_context().clear_cache() 119 | 120 | def tearDown(self): 121 | self.testbed.deactivate() 122 | 123 | def testEventuallyConsistentGlobalQueryResult(self): 124 | class TestModel(ndb.Model): 125 | pass 126 | 127 | user_key = ndb.Key('User', 'ryan') 128 | 129 | # Put two entities 130 | ndb.put_multi([ 131 | TestModel(parent=user_key), 132 | TestModel(parent=user_key) 133 | ]) 134 | 135 | # Global query doesn't see the data. 136 | self.assertEqual(0, TestModel.query().count(3)) 137 | # Ancestor query does see the data. 138 | self.assertEqual(2, TestModel.query(ancestor=user_key).count(3)) 139 | # [END HRD_example_1] 140 | 141 | # [START HRD_example_2] 142 | def testDeterministicOutcome(self): 143 | # 50% chance to apply. 144 | self.policy.SetProbability(.5) 145 | # Use the pseudo random sequence derived from seed=2. 146 | self.policy.SetSeed(2) 147 | 148 | class TestModel(ndb.Model): 149 | pass 150 | 151 | TestModel().put() 152 | 153 | self.assertEqual(0, TestModel.query().count(3)) 154 | self.assertEqual(0, TestModel.query().count(3)) 155 | # Will always be applied before the third query. 156 | self.assertEqual(1, TestModel.query().count(3)) 157 | # [END HRD_example_2] 158 | 159 | 160 | # [START main] 161 | if __name__ == '__main__': 162 | unittest.main() 163 | # [END main] 164 | -------------------------------------------------------------------------------- /tests/test_env_vars.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc 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 | # [START env_example] 16 | import unittest 17 | import os 18 | from google.appengine.ext import testbed 19 | 20 | 21 | class EnvVarsTestCase(unittest.TestCase): 22 | def setUp(self): 23 | self.testbed = testbed.Testbed() 24 | self.testbed.activate() 25 | self.testbed.setup_env( 26 | app_id='your-app-id', 27 | my_config_setting='example', 28 | overwrite=True) 29 | 30 | def tearDown(self): 31 | self.testbed.deactivate() 32 | 33 | def testEnvVars(self): 34 | assert os.environ['APPLICATION_ID'] == 'your-app-id' 35 | assert os.environ['MY_CONFIG_SETTING'] == 'example' 36 | # [END env_example] 37 | 38 | if __name__ == '__main__': 39 | unittest.main() 40 | -------------------------------------------------------------------------------- /tests/test_login.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc 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 | # [START login_example] 16 | import unittest 17 | from google.appengine.ext import testbed 18 | from google.appengine.api import users 19 | 20 | 21 | class LoginTestCase(unittest.TestCase): 22 | # [START setup] 23 | def setUp(self): 24 | self.testbed = testbed.Testbed() 25 | self.testbed.activate() 26 | self.testbed.init_user_stub() 27 | # [END setup] 28 | 29 | def tearDown(self): 30 | self.testbed.deactivate() 31 | 32 | # [START login] 33 | def loginUser(self, email='user@example.com', id='123', is_admin=False): 34 | self.testbed.setup_env( 35 | user_email=email, 36 | user_id=id, 37 | user_is_admin='1' if is_admin else '0', 38 | overwrite=True) 39 | # [END login] 40 | 41 | # [START test] 42 | def testLogin(self): 43 | assert not users.get_current_user() 44 | self.loginUser() 45 | assert users.get_current_user().email() == 'user@example.com' 46 | self.loginUser(is_admin=True) 47 | assert users.is_current_user_admin() 48 | # [END test] 49 | # [END login_example] 50 | 51 | if __name__ == '__main__': 52 | unittest.main() 53 | -------------------------------------------------------------------------------- /tests/test_mail.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc 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 | # [START mail_example] 16 | import unittest 17 | from google.appengine.ext import testbed 18 | from google.appengine.api import mail 19 | 20 | 21 | class MailTestCase(unittest.TestCase): 22 | 23 | def setUp(self): 24 | self.testbed = testbed.Testbed() 25 | self.testbed.activate() 26 | self.testbed.init_mail_stub() 27 | self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME) 28 | 29 | def tearDown(self): 30 | self.testbed.deactivate() 31 | 32 | def testMailSent(self): 33 | mail.send_mail(to='alice@example.com', 34 | subject='This is a test', 35 | sender='bob@example.com', 36 | body='This is a test e-mail') 37 | messages = self.mail_stub.get_sent_messages(to='alice@example.com') 38 | self.assertEqual(1, len(messages)) 39 | self.assertEqual('alice@example.com', messages[0].to) 40 | # [END mail_example] 41 | 42 | if __name__ == '__main__': 43 | unittest.main() 44 | -------------------------------------------------------------------------------- /tests/test_task_queue.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc 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 operator 16 | # [START taskqueue] 17 | import unittest 18 | from google.appengine.ext import testbed 19 | from google.appengine.api import taskqueue 20 | from google.appengine.ext import deferred 21 | 22 | 23 | class TaskQueueTestCase(unittest.TestCase): 24 | def setUp(self): 25 | self.testbed = testbed.Testbed() 26 | self.testbed.activate() 27 | 28 | # root_path must be set the the location of queue.yaml. 29 | # Otherwise, only the 'default' queue will be available. 30 | self.testbed.init_taskqueue_stub(root_path='.') 31 | self.taskqueue_stub = self.testbed.get_stub( 32 | testbed.TASKQUEUE_SERVICE_NAME) 33 | 34 | def tearDown(self): 35 | self.testbed.deactivate() 36 | 37 | def testTaskAddedToQueue(self): 38 | taskqueue.Task(name='my_task', url='/url/of/my/task/').add() 39 | tasks = self.taskqueue_stub.get_filtered_tasks() 40 | assert len(tasks) == 1 41 | assert tasks[0].name == 'my_task' 42 | # [END taskqueue] 43 | 44 | # [START filtering] 45 | def testFiltering(self): 46 | taskqueue.Task(name='task_one', url='/url/of/task/1/').add('queue-1') 47 | taskqueue.Task(name='task_two', url='/url/of/task/2/').add('queue-2') 48 | 49 | # All tasks 50 | tasks = self.taskqueue_stub.get_filtered_tasks() 51 | assert len(tasks) == 2 52 | 53 | # Filter by name 54 | tasks = self.taskqueue_stub.get_filtered_tasks(name='task_one') 55 | assert len(tasks) == 1 56 | assert tasks[0].name == 'task_one' 57 | 58 | # Filter by URL 59 | tasks = self.taskqueue_stub.get_filtered_tasks(url='/url/of/task/1/') 60 | assert len(tasks) == 1 61 | assert tasks[0].name == 'task_one' 62 | 63 | # Filter by queue 64 | tasks = self.taskqueue_stub.get_filtered_tasks(queue_names='queue-1') 65 | assert len(tasks) == 1 66 | assert tasks[0].name == 'task_one' 67 | 68 | # Multiple queues 69 | tasks = self.taskqueue_stub.get_filtered_tasks( 70 | queue_names=['queue-1', 'queue-2']) 71 | assert len(tasks) == 2 72 | # [END filtering] 73 | 74 | # [START deferred] 75 | def testTaskAddedByDeferred(self): 76 | deferred.defer(operator.add, 1, 2) 77 | 78 | tasks = self.taskqueue_stub.get_filtered_tasks() 79 | assert len(tasks) == 1 80 | 81 | result = deferred.run(tasks[0].payload) 82 | assert result == 3 83 | # [END deferred] 84 | 85 | if __name__ == '__main__': 86 | unittest.main() 87 | -------------------------------------------------------------------------------- /vendor.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014 Jon Wayne Parrott, [proppy], Michael R. Bernstein 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # Notes: 18 | # - Imported from https://github.com/jonparrott/Darth-Vendor/. 19 | # - Added license header. 20 | # - Renamed `darth.vendor` to `vendor.add` to match upcoming SDK interface. 21 | # - Renamed `position` param to `index` to match upcoming SDK interface. 22 | # - Removed funny arworks docstring. 23 | 24 | import site 25 | import os.path 26 | import sys 27 | 28 | 29 | def add(folder, index=1): 30 | """ 31 | Adds the given folder to the python path. Supports namespaced packages. 32 | By default, packages in the given folder take precedence over site-packages 33 | and any previous path manipulations. 34 | 35 | Args: 36 | folder: Path to the folder containing packages, relative to ``os.getcwd()`` 37 | position: Where in ``sys.path`` to insert the vendor packages. By default 38 | this is set to 1. It is inadvisable to set it to 0 as it will override 39 | any modules in the current working directory. 40 | """ 41 | 42 | # Check if the path contains a virtualenv. 43 | site_dir = os.path.join(folder, 'lib', 'python' + sys.version[:3], 'site-packages') 44 | if os.path.exists(site_dir): 45 | folder = site_dir 46 | # Otherwise it's just a normal path, make it absolute. 47 | else: 48 | folder = os.path.join(os.path.dirname(__file__), folder) 49 | 50 | # Use site.addsitedir() because it appropriately reads .pth 51 | # files for namespaced packages. Unfortunately, there's not an 52 | # option to choose where addsitedir() puts its paths in sys.path 53 | # so we have to do a little bit of magic to make it play along. 54 | 55 | # We're going to grab the current sys.path and split it up into 56 | # the first entry and then the rest. Essentially turning 57 | # ['.', '/site-packages/x', 'site-packages/y'] 58 | # into 59 | # ['.'] and ['/site-packages/x', 'site-packages/y'] 60 | # The reason for this is we want '.' to remain at the top of the 61 | # list but we want our vendor files to override everything else. 62 | sys.path, remainder = sys.path[:1], sys.path[1:] 63 | 64 | # Now we call addsitedir which will append our vendor directories 65 | # to sys.path (which was truncated by the last step.) 66 | site.addsitedir(folder) 67 | 68 | # Finally, we'll add the paths we removed back. 69 | # The final product is something like this: 70 | # ['.', '/vendor-folder', /site-packages/x', 'site-packages/y'] 71 | sys.path.extend(remainder) 72 | --------------------------------------------------------------------------------