Ruby/Rails enjoy some really nice and powerful Behavior Driven Design/Development testing frameworks like Cucumber and RSpec.
Does Python/Django enjoy the same thing (I'm not talking about simple unit testing like PyUnit)?
There is a new tools called Lettuce that promises to be a Pythonic version of Cucumber. It is starting with Django integration. That plus the existing testing tools in Django make it pretty good for unit testing.
There's also a tool called Windmill that provides a solid browser-based testing tool for building GUI tests. Couple that with a tool like Lettuce for writing acceptance tests and the straight unittest and nosetests and I'd say you're set.
The thing to remember, there's a slightly different culture between Ruby and Python. Ruby has a preference for tests above all else. In Python it's documentation. As such, there's not a million and one testing frameworks in Python, just a few really solid ones with the occasional outlier (like Lettuce).
Hope this helps.
in case someone is still visiting here,
Aloe, is a lettuce upgrade and has integration for django 1.8.
I'm starting to use it now.
If you are referring to high level testing, and not unit testing, then you can still use Cucumber. Cucumber can be hooked up with Webrat and Mechanize, and you can use that setup to write stories to test your Django app. I have a setup like that. You can also hook up Cucumber with Watir, and do browser based testing.
There isn't something like FactoryGirl to auto generate data for your model, but you can use Django fixtures to create initial data for your model, and only have the fixtures installed when you are in testing mode. Then you can start a test, and have some data to test with.
With those things, you can setup a fairly comprehensive high level test suite. Then you can use Django unit test to do low level testing.
I'm working with Robot Test Framework http://code.google.com/p/robotframework/. It is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD).
It's flexible and powerful and also allows BDD style in a similar way to lettuce/cucumber.
I had a good experience with TestBrowser, which allows you to write functional tests at a high level. See http://pypi.python.org/pypi/homophony for integration of TestBrowser with Django.
Related
We have developed the APIs using the python eve framework . Is there a way we can write the unit test cases for the APIs we have developed in EVE. Is there a Unit Test case component bundled into Python EVE.I need to bundle them with my Continuous Integration setup.
If yes please help me with the steps how to proceed with it.
You could start by looking at Eve's own test suite. There's 600+ examples in there. There are two base classes that provide a lot of utility methods: TestMinimal and TestBase. Almost all other test classes inherit from either of those. You probably want to use TestMinimal as it takes care of setting up and dropping the MongoDB connection for you. It also provides stuff like assert200, assert404 etc.
In general, you use the test_client object, as you do with Flask itself. Have a look at Testing Flask Applications too and Eve's Running the Tests page.
I have been reading about testing in django. One thing that was recommended was use of django-webtest for functional testing. I found a decent article here that teaches how to go about functional testing in selenium using python. But people have also recommended Ian Bicking's WebTest's extension djagno-webtest to use for testing forms in django. How is testing with webtest and testing with selenium different in context of django forms?
So from functional testing point of view:
How does django-webtest and selenium go side by side?
Do we need to have both of them or any one would do?
The key difference is that selenium runs an actual browser, while WebTest hooks to the WSGI.
This results in the following differences:
You can't test JS code with WebTest, since there is nothing to run it.
WebTest is much faster since it hooks to the WSGI, this also means a smaller memory footprint
WebTest does not require to actually run the server on a port so it's a bit easier to parallize
WebTest does not check different problems that occur with actual browsers, like specific browser version bugs (cough.. internet explorer.. cough..)
Bottom line:
PREFER to use WebTest, unless you MUST use Selenium for things that can't be tested with WebTest.
The important thing to know about Selenium is that it's primarily built to be a server-agnostic testing framework. It doesn't matter what framework or server-side implementation is used to create the front-end as long as it behaves as expected. Also, while you can (and when possible you probably should) write tests manually in Selenium, many tests are recorded macros of someone going through the motions that are then turned into code automatically.
On the other hand, django-webtest is built to work specifically on Django websites. It's actually a Django-specific extension to WebTest, which is not Django-only, but WSGI-only (and therefore Python-only). Because of that, it can interact with the application with a higher level of awareness of how things work on the server. This can make running tests faster and can also makes it easy to write more granular, detailed tests. Also, unlike Selenium, your tests can't be automatically written as recorded macros.
Otherwise, the two tools have generally the same purpose and are intended to test the same kinds of things. That said, I would suggest picking one rather than using both.
I am currently writing a new test runner for Django and I'd like to know if it's possible to TDD my test runner using my own test runner. Kinda like compiler bootstrapping where a compiler compiles itself.
Assuming it's possible, how can it be done?
Yes. One of the examples Kent Beck works through in his book "Test Driven Development: By Example" is a test runner.
Bootstrapping is a cool technique, but it does have a circular-definition problem. How can you write tests with a framework that doesn't exist yet?
Bootstrapping compilers can get around this problem in several ways, but it's my understanding that usually the first implementation isn't bootstrapped. Later bootstraps would be rewrites that then use the original compiler to compile themselves.
So use an existing framework to write it the first time out. Then, once you have a stable release, you can re-write the tests using your own test-runner.
I'm making a simple web app where I have some simple python scripts that do the text crunchin g I need - but I'm not quite sure how to interface it with a client who'd only want to see some HTML forms.
There's so many different server side frameworks out there - but I don't think I need anything too heavy duty - just a mechanism to accept data from the forms that the user fills in, and feed it to my Python code and back.
Could someone suggest what tools I should look into and what design paradigms I should follow? Simple pointers to different references around the web with a single line about their significance would also help.
Best.
At the moment, the best lightweight and yet very powerful framework for python IMO is Flask. If you want form abstraction there is a WTFlask plugin for it which is WTForms adapted for flask - http://flask.pocoo.org/.
Web2py is also a very good framework for starters because it has helpers and wizards for creating/running an application, and also has something like an admin interface, offering an On-line IDE functionality. - http://www.web2py.com/
I proposed these two frameworks because you can start fast with them, they both have good documentation, both are powerful yet easy and they are pretty friendly for beginners.
Not normally supported with cheap hosting, but mod_python on apache might be right up your alley.
You could also have html talk to python through cgi (Which has been the way of doing it for years before php came along).
The standard Design pattern commonly seen in web apps is Model-View-Controller, so google around.
I've used Django (heavy and something of a non-trivial initial learning curve), and web.py (very small & simple), and over the past year, I've been pretty happy using tornado.
People can argue about the async details, but that's not even why I use it. It's pretty fast, it's super quick to get started with, it comes with examples that get you doing things quickly, and -- most important to me -- It's a web server and framework in one, which means you don't have to muck with mod_python vs mod_wsgi vs cgi vs fcgi vs whatever. Deployment is really easy.
I'm lucky enough to have full control over the architecture of my company's app, and I've decided to scrap our prototype written in Ruby/Rails and start afresh in Python. This is for a few reasons: I want to learn Python, I prefer the syntax and I've basically said "F**k it, let's do it."
So, baring in mind this is going to be a pretty intensive app, I'd like to hear your opinions on the following:
Generic web frameworks
ORM/Database Layer (perhaps to work with MongoDB)
RESTful API w/ oAuth/xAuth authentication
Testing/BDD support
Message queue (I'd like to keep this in Python if possible)
The API is going to need to interface with a Clojure app to handle some internal data stuff, and interface with the message queue, so if it's not Python it'd be great to have some libraries to it.
TDD/BDD is very important to me, so the more tested, the better!
It'll be really interesting to read your thoughts on this. Much appreciated.
My best,
Jamie
Frameworks
OK, so I'm a little biased here as I currently make extensive use of Django and organise the Django User Group in London so bear that in mind when reading the following.
Start with Django because it's a great gateway drug. Lots of documentation and literature, a very active community of people to talk to and lots of example code around the web.
That's a completely non-technical reason. Pylons is probably purer in terms of Python philosophy (being much more a collection of discrete bits and pieces) but lots of the technical stuff is personal preference, at least until you get into Python more. Compare the very active Django tag on Stack Overflow with that of pylons or turbogears though and I'd argue getting started is simply easier with Django irrespective of anything to do with code.
Personally I default to Django, but find that an increasing amount of time I actually opt for writing using simpler micro frameworks (think Sinatra rather than Rails). Lots of things to choose from (good list here, http://fewagainstmany.com/blog/python-micro-frameworks-are-all-the-rage). I tend to use MNML (because I wrote parts of it and it's tiny) but others are actively developed. I tend to do this for small, stupid web services which are then strung together with a Django project in the middle serving people.
Worth noting here is appengine. You have to work within it's limitations and it's not designed for everything but it's a great way to just play with Python and get something up and working quickly. It makes a great testbed for learning and experimentation.
Mongo/ORM
On the MongoDB front you'll likely want to look at the basic python mongo library ( http://api.mongodb.org/python/ ) first to see if it has everything you need. If you really do want something a little more ORM like then mongoengine (http://hmarr.com/mongoengine/) might be what you're looking for. A bunch of folks are also working on making Django specifically integrate more seamlessly with nosql backends. Some of that is for future Django releases, but django-norel ( http://www.allbuttonspressed.com/projects/django-nonrel) has code now.
For relational data SQLAlchemy ( http://www.sqlalchemy.org/) is good if you want something standalone. Django's ORM is also excellent if you're using Django.
API
The most official Oauth library is python-oauth2 ( http://github.com/simplegeo/python-oauth2), which handily has a Django example as part of it's docs.
Piston ( http://bitbucket.org/jespern/django-piston/wiki/Home) is a Django app which provides lots of tools for building APIs. It has the advantage of being pretty active and well maintained and in production all over the place. Other projects exist too, including Dagny ( http://zacharyvoase.github.com/dagny/) which is an early attempt to create something akin to RESTful resources in Rails.
In reality any Python framework (or even just raw WSGI code) should be reasonably good for this sort of task.
Testing
Python has unittest as part of it's standard library, and unittest2 is in python 2.7 (but backported to previous versions too http://pypi.python.org/pypi/unittest2/0.1.4). Some people also like Nose ( http://code.google.com/p/python-nose/), which is an alternative test runner with some additional features. Twill ( http://twill.idyll.org/) is also nice, it's a "a simple scripting language for Web browsing", so handy for some functional testing. Freshen ( http://github.com/rlisagor/freshen) is a port of cucumber to Python. I haven't yet gotten round to using this in anger, but a quick look now suggests it's much better than when I last looked.
I actually also use Ruby for high level testing of Python apps and apis because I love the combination of celerity and cucumber. But I'm weird and get funny looks from other Python people for this.
Message Queues
For a message queue, whatever language I'm using, I now always use RabbitMQ. I've had some success with stompserver in the past but Rabbit is awesome. Don't worry that it's not itself written in Python, neither is PostgresSQL, Nginx or MongoDB - all for good reason. What you care about are the libraries available. What you're looking for here is py-amqplib ( http://barryp.org/software/py-amqplib/) which is a low level library for talking amqp (the protocol for talking to rabbit as well as other message queues). I've also used Carrot ( http://github.com/ask/carrot/), which is easier to get started with and provides a nicer API. Think bunny in Ruby if you're familiar with that.
Environment
Whatever bits and pieces you decide to use from the Python ecosystem I'd recommend getting to who pip and virtualenv ( http://clemesha.org/blog/2009/jul/05/modern-python-hacker-tools-virtualenv-fabric-pip/ - note that fabric is also cool, but not essential and these docs are out of date on that tool). Think about using Ruby without gem, bundler or rvm and you'll be in the right direction.
Ok, you might be making a mistake, the same one I made when I started with python.
Before you decide on a thing like django, which is an excellent, yet atypical python web framework, spend an night cuddled up with:
This, is a good start. Make sure you do A little Werkzeug watching , Then check out
some classic WebOb. Maybe, if you feel the fire in the blood, and you might, wsgi is a bit flawed, but only to the gods, check out Flask
I'm not saying use it, Django is beautiful too, but if you don't know python, and you go through django, you run the risk of learning a framework.
WSGI is super straightforward. You'll find out about Paste, and Pastescript, and Pylons.
Then, make your decision. It'll be much easier learning stuff doing bare bones wsgi or Flask, stuff like variable assignment, using the interpreter, style concerns, testing, on 3 files for a couple of nights, instead of django. Take 2 nights. Then you'll see the great similarity between python web frameworks, instead of the differences. Hell, you might even roll with Flask.
Just some advice, I did the same thing with ruby, going in through Rails, and... well, strong words were said.
Language, then basic wsgi and testing, then pick your framework and roll
I'm new to python myself, and plan to get more in depth with it this year. I've had a few false starts at this, but always professional needs bring me back to PHP. The few times I've done some development, I've had really good experiences with web2py as a python framework. It's quite well done, and complete in features, while still being extremely lightweight. The database layer seems to be very flexible and mature.
As for TDD/BDD and the rest of your questions, I don't have any experience with python options, but would be interested to hear what others say.
I am using Twisted Framework based Nevow library for python based web app.
All your criteria fit into this single framework.