On Github catalyst-training / python-advanced
import unittest import YourModule class RunTests(unittest.TestCase): def test_something(self): # Given o = YourModule.YourObject() # When result = o.thisShouldDoSomething(100) # Then self.assertTrue(result)- any method which begins with the text 'test_' is a test - you can also write 'setUp', 'tearDown' methods which will be called appropriately - there is also a rich selection of assertion functions - assertTrue, assertFalse, - assertEqual, assertAlmostEqual - assertRaises - etc
python -m unittest discover test/
......................................................... ---------------------------------------------------------------------- Ran 62 tests in 4.473s OK- This command will find all files in the 'test/' directory, that begin with 'test_' - and run them all....
WSGI is a specification, where a web application is implemented as a function or callable object.
It tightly defines the input - which is passed to the function as arguments, and the output - which is returned from the function call.
This allow for writing a web application without any need for dealing with HTTP.
Once that has been done, the application can be tested without the need for a webserver, and can be served up by any webserver that can talk WSGI.
- This make web applications - portable - testableDjango is a Python web application framework.
It really is easy to create a website using Django, and it's a good starting point for a real application.
It doesn't come bundled with python, so you need to install it yourself, depending on your OS, that could be as easy as:
$ sudo apt-get install python-django
$ django-admin startproject mysite $ cd mysite $ python manage.py migrate $ python manage.py runserver
Then, go to http://127.0.0.1:8000
- we have chosen not to configure anything, and that means: - We have a SQL lite database - We don't have a webserver - we are serving pages on an odd port - etc - normally we would sort those things out by editing settings.py$ python manage.py startapp myapp
# mysite/settings.py INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'myapp', )
# mysite/urls.py from django.conf.urls import patterns, include, url from django.contrib import admin urlpatterns = patterns('', # Examples: url(r'^$', 'myapp.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), )
# myapp/views.py from django.shortcuts import render from django.http import HttpResponse # Create your views here. def home(request): return HttpResponse("Here's the text of the Web page.")
So what are you supposed to use?
This page has all you need:
open source technologists