personalkollen fredag 5 juli 13



Similar documents
Survey of Unit-Testing Frameworks. by John Szakmeister and Tim Woods

CME 193: Introduction to Scientific Python Lecture 8: Unit testing, more modules, wrap up

Test-Driven Development with Python

Profiling, debugging and testing with Python. Jonathan Bollback, Georg Rieckh and Jose Guzman

Introduction to Django Web Framework

Slides prepared by : Farzana Rahman TESTING WITH JUNIT IN ECLIPSE

Slides from INF3331 lectures - web programming in Python

Python Cryptography & Security. José Manuel

Effective Django. Build Nathan Yergler

Chapter 2 Writing Simple Programs

Using Python, Django and MySQL in a Database Course

Python Testing with unittest, nose, pytest

Advanced Topics: Biopython

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

web frameworks design comparison draft - please help me improve it focus on Model-View-Controller frameworks

Web [Application] Frameworks

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

Django tutorial. October 22, 2010

Introduction to web development with Python and Django Documentation

<?php if (Login::isLogged(Login::$_login_front)) { Helper::redirect(Login::$_dashboard_front); }

django-gcm Documentation

Writing robust scientific code with testing (and Python) Pietro Berkes, Enthought UK

Python 2 and 3 compatibility testing via optional run-time type checking

Test Driven Development

Unit testing with mock code EuroPython 2004 Stefan Schwarzer p.1/25

Ruby On Rails A Cheatsheet. Ruby On Rails Commands

Python programming Testing

Para perfeccionistas con deadlines

Unit Testing. and. JUnit

Testing Python. Applying Unit Testing, TDD, BDD and Acceptance Testing

Flask-SSO Documentation

+ Introduction to JUnit. IT323 Software Engineering II By: Mashael Al-Duwais

SSRS Reporting Using Report Builder 3.0. By Laura Rogers Senior SharePoint Consultant Rackspace Hosting

Unit Testing with FlexUnit. by John Mason

Unit testing with JUnit and CPPUnit. Krzysztof Pietroszek

Participant Guide. Together we are moving towards a day without brain tumors!

depl Documentation Release depl contributors

django-cron Documentation

Python for Test Automation i. Python for Test Automation

Introduction to FreeNAS development

API Endpoint Methods NAME DESCRIPTION GET /api/v4/analytics/dashboard/ POST /api/v4/analytics/dashboard/ GET /api/v4/analytics/dashboard/{id}/ PUT

Nupic Web Application development

How To Send Your Newsletter

The Application Getting Started Screen is display when the Recruiting Matrix 2008 Application is Started.

SPARROW Gateway. Developer Data Vault Payment Type API. Version 2.7 (6293)

Ruby on Rails on Minitest

Software Engineering. Top-Down Design. Bottom-Up Design. Software Process. Top-Down vs. Bottom-Up 13/02/2012

Relational Database Concepts

Automated Web Testing with Selenium

JUnit. Introduction to Unit Testing in Java

Software Testing. Theory and Practicalities

Hibernate Validator. Olivier Devoisin Kevin Gallardo. Université Pierre et Marie Curie. 9 Decembre 2014

Tutorial on Relational Database Design

Memopol Documentation

Testing Tools and Techniques

Chapter 3. Data Analysis and Diagramming

Homework 1. Comp 140 Fall 2008

Chapter 3 Writing Simple Programs. What Is Programming? Internet. Witin the web server we set lots and lots of requests which we need to respond to

Automate APIs with Groovy Script

Web Development Paradigms and how django and GAE webapp approach them.

NORTHERNTEL BUSINESS. Voice Messaging. changing the way you do business. Centrex. User s Guide: northerntel.

SQL 2: GETTING INFORMATION INTO A DATABASE. MIS2502 Data Analytics

How to work with Panels in LimeSurvey

PHPUnit Manual. Sebastian Bergmann

Using Toaster in a Production Environment

Download: Server-side technologies. WAMP (Windows), MAMP (Mac),

An Example: Video Rental System

Author: Sascha Wolski Sebastian Hennebrueder Tutorials for Struts, EJB, xdoclet and eclipse.

Microsoft Access Database Management through LabVIEW and MySQL

Table of Contents. Table of Contents

latest Release 0.2.6

Exploring Algorithms with Python

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID:

EASTSIDE HIGH SCHOOL Student Information

Web Development with Flask and the Raspberry Pi Leading by Example CUAUHTEMOC CARBAJAL ITESM CEM 22/04/2014

Web Framework Performance Examples from Django and Rails

Python and Google App Engine

Use Mail Merge to create a form letter

Exercise 0. Although Python(x,y) comes already with a great variety of scientic Python packages, we might have to install additional dependencies:

Quick Reference Guide For CallPilot R1.5 Setup Parameters

Modern Web Application Framework Python, SQL Alchemy, Jinja2 & Flask

L7_L10. MongoDB. Big Data and Analytics by Seema Acharya and Subhashini Chellappan Copyright 2015, WILEY INDIA PVT. LTD.

Group Administrator User Guide

Transcription:

personalkollen

It is getting better! Photo: http://www.flickr.com/photos/bee/3290452839/

from django.test import TestCase class TestHelloWorld(TestCase): def test_hello_world(self): response = self.client.get('/hi/') self.assertequal(response.status_code, 200) self.assertequal(response.content, 'Hello World!')

def test_hello_world(client): response = client.get('/hi/') assert response.status_code == 200 assert response.content == 'Hello World!'

def test_hello_world(client): response = client.get('/hi/') assert response.status_code == 200 assert response.content == 'Hello World!'

$ py.test F =================== FAILURES ==================== test_hello_world client = <django.test.client.client object at 0x1065f58d0> def test_hello_world(client): response = client.get('/hi/') assert response.status_code == 200 > assert response.content == 'Hello World!' E assert 'Hello EuroPython!' == 'Hello World!' E - Hello EuroPython! E + Hello World! test_hello_world.py:5: AssertionError

assertalmostequal assertalmostequals assertdictcontainssubset assertdictequal assertequal assertequals assertfalse assertgreater assertgreaterequal assertin assertis assertisinstance assertisnone assertisnot assertisnotnone assertitemsequal assertless assertlessequal assertlistequal assertmultilineequal assertnotalmostequal assertnotalmostequals assertnotequal assertnotequals assertnotin assertnotisinstance assertnotregexpmatches assertraises assertraisesregexp assertregexpmatches assertsequenceequal assertsetequal asserttrue asserttupleequal

pip install pytest- django

pip install - e.

export DJANGO_SETTINGS_MODULE=settings

Photo: http://www.flickr.com/photos/mark_i_geo/3498456758

[pytest] DJANGO_SETTINGS_MODULE=settings

$ py.test

$ py.test test_views.py

$ py.test - k test_foo

test_*.py

[pytest] python_files = *.py

polls/tests/views.py blog/tests/views.py

tests/polls/views.py tests/blog/models.py

unit_tests/blog/models.py functional_tests/test_foo.py

py.test - - reuse- db

[pytest] addopts = - - reuse- db

from datetime import datetime, time from django.http import HttpResponse def greet(request): now = datetime.now().time() if time(5) < now < time(12): greeting = 'morning' elif time(18) < now < time(21): greeting = 'evening' else: greeting = 'day' return HttpResponse('Good %s!' % greeting)

from datetime import datetime, time from django.http import HttpResponse def greet(request): now = datetime.now().time() if time(5) < now < time(12): greeting = 'morning' elif time(18) < now < time(21): greeting = 'evening' else: greeting = 'day' return HttpResponse('Good %s!' % greeting)

# greeter.py from datetime import time def greeting_at(time_of_day): if time(5) < time_of_day < time(12): return 'morning' elif time(18) < time_of_day < time(21): return 'evening' else: return 'day'

# views.py from datetime import time from django.http import HttpResponse from.greeter import greeting_at def greet(request): now = datetime.now().time() greeting = greeting_at(now) return HttpResponse('Good %s!' % greeting)

!

import pytest @pytest.mark.django_db def test_user_count(): assert User.objects.count() == 0

def test_user_count(): assert User.objects.count() == 0

test_user_count test_db_access.py:4: in test_user_count > assert User.objects.count() == 0... snip... E Failed: Database access not allowed, use the "django_db" mark to enable

import pytest pytestmark = pytest.mark.django_db def test_foo(): pass def test_bar(): pass

$ py.test - m 'not django_db'

[{"model": "myapp.person", "pk": 1, "fields": {"first_name": "John", "last_name": "Lennon"}}, {"model": "myapp.person", "pk": 2, "fields": {"first_name": "Paul", "last_name": "McCartney"}} ] Slow & hard to maintain.. avoid them!

from django.db import models class Group(models.Model): name = models.textfield() class Person(models.Model): first_name = models.textfield() last_name = models.textfield() group = models.foreignkey(group) def group_letter(self): return self.group.name[0].upper()

import factory from yourapp.models import Person, Group class GroupFactory(factory.Factory): FACTORY_FOR = Group name = 'Developers' class PersonFactory(factory.Factory): FACTORY_FOR = Person first_name = 'John' last_name = 'Doe' group = factory.subfactory(groupfactory)

from yourfactories import PersonFactory def test_group_letter(): person = PersonFactory.build( group name='admins') assert person.group_letter() == 'A'

import pytest @pytest.mark.django_db def test_group_letter(): person = PersonFactory.create( group name='admins') assert person.group_letter() == 'A'

def test_with_client(client): response = client.get('/foo/') assert response.status_code == 200

def test_foo(settings): settings.date_format = 'Y- m- d'

import pytest @pytest.fixture def person(): return PersonFactory.build()

import pytest from your_factories import UserFactory @pytest.fixture def person_in_db(db): return PersonFactory.create()