GithubHelp home page GithubHelp logo

rbanffy / testable_appengine Goto Github PK

View Code? Open in Web Editor NEW
31.0 9.0 2.0 86 KB

A testable Python skeleton application for Google's App Engine and AppScale environments

License: Apache License 2.0

Makefile 37.94% Shell 4.11% Python 57.95%
virtualenv makefile engine dev-appserver pudb ipdb sdk python google-appengine

testable_appengine's Introduction

testable_appengine

A testable Python skeleton application for Google App Engine and AppScale environments.

![Demo] (https://raw.githubusercontent.com/wiki/rbanffy/testable_appengine/screencap.gif)

Why?

Writing properly testable Python applications to run on Google App Engine is not trivial. Keeping the different application environments segregated is also an issue if all environments share the same SDK and Python environment. This template helps you build your application in such way it's contained in a folder, along with its virtualenvironment and separate copy of the SDK. It also preinstall ipdb and pudb debuggers, nose, pytest and webtest testing tools, appengine-fixture-loader (to load test or bootstrap data), and flake8 to do style checks on your code.

This tree was extracted from a larger project that makes use of it and further evolved on its own, with the enhancements ported back.

![nosetests running] (https://raw.githubusercontent.com/wiki/rbanffy/testable_appengine/screenshot.png)

Overall Structure

When you clone the Git repo, you'll have a tree structure not unlike the one below. This is the starting point for yout app.

├── build  (will be created when you run `make venv`)
├── cache  (will be created when you run `make venv`)
├── LICENSE
├── Makefile  (includes resourecs/Makefile)
├── README.md  (this file)
├── requirements.txt
├── resources
│   ├── autogenerated
│   ├── get_current_sdk_version.sh
│   ├── Makefile
│   └── requirements.txt (includes ../requirements.txt)
├── src  (contains a sample application)
│   ├── app.yaml
│   └── main.py
└── tests
    ├── __init__.py
    ├── persons.json
    └── sanity_test.py

Setting up your development environment

There is a makefile in the root directory. Running make venv will build a virtualenv in the .env folder, download the App Engine SDK, build the appropriate .pth files for your machine and install all requirements from the resources/requirements.txt file. If you wish to use a Python environment you provide yourself, you can make the virtualenv youself and run make libraries with VENV pointing to your virtualenv (as in VENV=.my_env make libraries)

The actual makefile is under resources. Your own makefile (with your own targets) should include it and extend it like the included Makefile does.

Please check the makefile before using it, as it may not make sense for your environment. It was tested on Ubuntu, Fedora, OSX (10.7+, provided you have functional pip and virtualenv utilities) and Windows 8.1 under Cygwin and Windows 10 under Ubuntu on Windows. If you are developing under Windows and don't use Cygwin or the Windows Subsystem for Linux, you are suffering more than you need for no good reason.

![Under Windows+Cygwin] (https://raw.githubusercontent.com/wiki/rbanffy/testable_appengine/windows.png)

![Under Ubuntu on Windows] (https://raw.githubusercontent.com/wiki/rbanffy/testable_appengine/ubuntu_on_windows.png)

When done, you can activate your virtualenv with the usual source .env/bin/activate or your favorite virtualenv tool. The tests will not function outside the local virtualenv. From the virtualenv, invoking dev_appserver.py and appcfg.py will use the versions in the SDK downloaded during install (check the Makefile for current version).

Your app should go in the local folder. Run your application using the dev_appserver.py script from within the virtualenv, as in dev_appserver.py .. Deploying ignores the files that do not belong to your application (the license, this README, cache, tests, resources and so on).

Tests

There are tests in the tests folder. The sanity_test.py checks whether everything is sane after you set up the environment.

Debugging

Debugging works like you'd expect. You just use pdb, ipdb or pudb (ipdb and pudb seem to have a tendency not to work under the dev_appserver, but pdb is just fine). Rule is, use ipbd or pudb if you want to debug something that's called by a test (run something like pudb .env/bin/nosetests), pdb for a live web application. Worst case scenario is that you just need to edit a little more. You can also easily use iPython to explore your ideas before you commit them to code.

![ipython prompt and ipdb in a test] (https://raw.githubusercontent.com/wiki/rbanffy/testable_appengine/using_ipdb.png)

![Using pudb] (https://raw.githubusercontent.com/wiki/rbanffy/testable_appengine/pudb.png)

Contributing

File a bug report (enhancement suggestions are fine too), fork it, PEP-8 it, test it, and, if it works, send a pull request. When in doubt, get in touch. We'll figure out what needs to be done.

This app is proudly checked with Travis

testable_appengine's People

Contributors

dependabot[bot] avatar rbanffy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

testable_appengine's Issues

Making it usable as a git submodule

Git submodules rule. It would be great if we could put most of the meat into a git submodule and make Makefile into a symlink (or something that refers to a Makefile inside the submodule.

SDK version detection is flaky (at best)

Google tends to break https://appengine.google.com/api/updatecheck (it's broken right now) and this breaks the environment setup and any CI that depends on it. We need a better way to do it.

Suggested fix: getting a deprecated SDK (the one updatecheck points to) from a location like https://storage.googleapis.com/appengine-sdks/deprecated/1919/google_appengine_1.9.19.zip if the current version wget fails to get the SDK from https://storage.googleapis.com/appengine-sdks/featured/.

(and thanks to Kanat Bekt for finding this out: http://bekt.github.io/p/gae-sdk/)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.