SlideShare a Scribd company logo
1 of 36
Download to read offline
more than a
side salad:
behaviour driven testing and
test driven design in Django
with Lettuce
Danielle Madeley
 blogs.gnome.org/danni  dannipenguin
Just what is test
driven
development?
Tests first;
code second
http://www.nilkanth.com/2007/06/08/three­monkeys­of­test­driven­development/
But how do we
write tests when
we don't know
what the code
looks like?
Don't test code;
test behaviours
As a visitor to the site
I want to create an account using my Google
login
So that I can log in without needing another
password
GivenI have a valid Google account
WhenI visit the siteAnd I click create account
ThenI am redirected to Google
http://www.flickr.com/photos/27369469@N08/2660160225
Lettuce
http://lettuce.it
http://www.flickr.com/photos/65567316@N00/2742564457
Feature: Authenticate to API
As a searcher/API user
I want to authenticate to the API
So that I can make queries
Scenario: I am not authenticated to the API
When I get the resource "/api/v3/hello/"
Then I get the response code 401
Steps
http://www.flickr.com/photos/60364452@N00/504844510
from lettuce import step, world
@step(r'I get the resource "([^"]*)"')
def get_resource(step, url):
"""
Make a GET request to the given URL
"""
world.response = world.client.get(url)
Steps are
stateful
http://www.flickr.com/photos/chrisconnell/3201514924/
from django.test.client import Client
from lettuce import before, step, world
from nose.tools import assert_equals
@before.each_scenario
def set_default_client(scenario):
world.client = Client()
@step(r'I get the resource "([^"]*)"')
def get_resource(step, url):
world.response = world.client.get(url)
@step(r'I get the response code (d+)')
def check_response_code(step, code):
code = int(code)
assert_equals(world.response.status_code, code)
./manage.py
harvest
# settings.py
INSTALLED_APPS = (
...
'lettuce.django',
'myapp',
)
LETTUCE_APPS = (
'myapp',
)
LETTUCE_USE_TEST_DATABASE = True
Selenium
http://www.flickr.com/photos/21663307@N02/3599012763
from lettuce import before, world
# import external lettuce steps
import lettuce_webdriver.webdriver
@before.all
def set_browser():
"""
Create a browser instance for use in tests.
"""
world.browser = webdriver.PhantomJS(...)
world.browser.set_window_size(1200, 800)
def site_url(url):
base_url = 'http://%s' % socket.gethostname()
if server.port is not 80:
base_url += ':%d' % server.port
return urlparse.urljoin(base_url, url)
@step("I visit the site")
def open_site(step):
step.given('I visit "%s"' % site_url('/'))
Scenario: Add consumer with blank Contact name
When I log in to admin with username "admin" and
And I click "Consumers"
And I click "Add consumer"
And I fill in "Organisation" with "OOOO"
And I fill in "Contact name" with ""
And I fill in "Contact number" with "0399999999"
And I fill in "Website" with "www.test.com"
And I press "Save"
Then I should see "This field is required"
And there should be 0 consumers in the database
Fixtures
Feature: Create new API key
As an administrator
I want to create a new API key
So that I can enable others to query API
Background:
Given I have users in the database:
| username | password | is_superuser |
| admin | secret | true |
Built in steps using
Django's model
introspection
Given I have users in the database:
...
Then there should be 1 consumer in the database
And consumer should be present in the database:
...
Which are extendable
@creates_models(User)
def create_user(step):
data = hashes_data(step)
for hash_ in data:
is_superuser = hash_.pop('is_superuser', Fals
if is_superuser:
user = User.objects.create_superuser(**ha
else:
user = User.objects.create_user(**hash_)
user.save()
reset_sequence(User)
Best practice
Given I have items in my cart
When I go to checkout
And I pay for the items
Then everything worked
write reusable
steps
write reusable scenarios
Scenario Outline: I edit a user to add a team
Given users have permissions:
| user | organisation | permission |
| peon@org.org | OrgCorp | organisation_user |
And I log in with email "<email>" through the profile serve
When I visit site page "organisation/1/admin/user/4/edit"
And I select option "Team 1" from selector "Team"
And I press "Save"
Then there should be 1 organisation member metadata in the
Then organisation member metadata should be present in the
| organisation__name | user__email | team |
| OrgCorp | peon@org.org | Team 1 |
Examples:
| email |
| god@god.org |
| superuser@org.org |
| poweruser@org.org |
tie each feature file
to a single story
include scenarios
and anti-scenarios
Other uses
http://www.flickr.com/photos/omcoc/3050378171/
fin ;-P
questions?
colophon This presentation was done in reveal.js using Junction, Cantarell
and Source Code Pro with photography from the Creative Commons.
Infoxchange is hiring. Come and chat to me!
 blogs.gnome.org/danni  dannipenguin
http://www.flickr.com/photos/mau3ry/3763640652/

More Related Content

What's hot

Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Joke Puts
 
Plugging into plugins
Plugging into pluginsPlugging into plugins
Plugging into pluginsJosh Harrison
 
devise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwandevise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwanTse-Ching Ho
 
Dicas de palestra
Dicas de palestraDicas de palestra
Dicas de palestraFabio Akita
 
Manipulating Magento - Meet Magento Belgium 2017
Manipulating Magento - Meet Magento Belgium 2017Manipulating Magento - Meet Magento Belgium 2017
Manipulating Magento - Meet Magento Belgium 2017Joke Puts
 
Widgets: Making Your Site Great and Letting Others Help - WordCamp Victoria
Widgets: Making Your Site Great and Letting Others Help - WordCamp VictoriaWidgets: Making Your Site Great and Letting Others Help - WordCamp Victoria
Widgets: Making Your Site Great and Letting Others Help - WordCamp VictoriaJeff Richards
 
Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Matteo Collina
 
Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3성일 한
 
Unit Tests Aren't Enough
Unit Tests Aren't EnoughUnit Tests Aren't Enough
Unit Tests Aren't EnoughTrotter Cashion
 
SES Toronto 2008; Joe Dolson
SES Toronto 2008; Joe DolsonSES Toronto 2008; Joe Dolson
SES Toronto 2008; Joe DolsonJoseph Dolson
 
The Wide World Of Google Developer Technologies (STLIC 02-10)
The Wide World Of Google Developer Technologies (STLIC 02-10)The Wide World Of Google Developer Technologies (STLIC 02-10)
The Wide World Of Google Developer Technologies (STLIC 02-10)jasonacooper
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Frameworkvaluebound
 
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...Ho Chi Minh City Software Testing Club
 
jQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsjQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsHome
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaJason Noble
 
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4성일 한
 
Using HTML code to add page number and its output are there..
Using HTML code to add page number and its output are there..Using HTML code to add page number and its output are there..
Using HTML code to add page number and its output are there..Praseela R
 
Testing C# and ASP.net using Ruby
Testing C# and ASP.net using RubyTesting C# and ASP.net using Ruby
Testing C# and ASP.net using RubyBen Hall
 

What's hot (20)

Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
 
Plugging into plugins
Plugging into pluginsPlugging into plugins
Plugging into plugins
 
devise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwandevise tutorial - 2011 rubyconf taiwan
devise tutorial - 2011 rubyconf taiwan
 
Api
ApiApi
Api
 
Dicas de palestra
Dicas de palestraDicas de palestra
Dicas de palestra
 
Manipulating Magento - Meet Magento Belgium 2017
Manipulating Magento - Meet Magento Belgium 2017Manipulating Magento - Meet Magento Belgium 2017
Manipulating Magento - Meet Magento Belgium 2017
 
Widgets: Making Your Site Great and Letting Others Help - WordCamp Victoria
Widgets: Making Your Site Great and Letting Others Help - WordCamp VictoriaWidgets: Making Your Site Great and Letting Others Help - WordCamp Victoria
Widgets: Making Your Site Great and Letting Others Help - WordCamp Victoria
 
Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)
 
Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3Ionic으로 모바일앱 만들기 #3
Ionic으로 모바일앱 만들기 #3
 
Unit Tests Aren't Enough
Unit Tests Aren't EnoughUnit Tests Aren't Enough
Unit Tests Aren't Enough
 
SES Toronto 2008; Joe Dolson
SES Toronto 2008; Joe DolsonSES Toronto 2008; Joe Dolson
SES Toronto 2008; Joe Dolson
 
The Wide World Of Google Developer Technologies (STLIC 02-10)
The Wide World Of Google Developer Technologies (STLIC 02-10)The Wide World Of Google Developer Technologies (STLIC 02-10)
The Wide World Of Google Developer Technologies (STLIC 02-10)
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
 
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
 
jQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsjQtouch, Building Awesome Webapps
jQtouch, Building Awesome Webapps
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp Atlanta
 
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4
 
Using HTML code to add page number and its output are there..
Using HTML code to add page number and its output are there..Using HTML code to add page number and its output are there..
Using HTML code to add page number and its output are there..
 
Testing C# and ASP.net using Ruby
Testing C# and ASP.net using RubyTesting C# and ASP.net using Ruby
Testing C# and ASP.net using Ruby
 
Catalog display
Catalog displayCatalog display
Catalog display
 

Similar to More than a side salad: behaviour driven testing and test driven design in Django with Lettuce

Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with CucumberBrandon Keepers
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web FrameworkDavid Gibbons
 
Controller Testing: You're Doing It Wrong
Controller Testing: You're Doing It WrongController Testing: You're Doing It Wrong
Controller Testing: You're Doing It Wrongjohnnygroundwork
 
Introduction to Web APIs and the Google+ API - BarCamp Phnom Penh 2011
Introduction to Web APIs and the Google+ API - BarCamp Phnom Penh 2011Introduction to Web APIs and the Google+ API - BarCamp Phnom Penh 2011
Introduction to Web APIs and the Google+ API - BarCamp Phnom Penh 2011traactivity
 
Leveraging Rails to Build Facebook Apps
Leveraging Rails to Build Facebook AppsLeveraging Rails to Build Facebook Apps
Leveraging Rails to Build Facebook AppsDavid Keener
 
Designing and Implementing a Multiuser Apps Platform
Designing and Implementing a Multiuser Apps PlatformDesigning and Implementing a Multiuser Apps Platform
Designing and Implementing a Multiuser Apps PlatformApigee | Google Cloud
 
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliGetting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliRebecca Eloise Hogg
 
OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial IntroPamela Fox
 
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST FrameworkEasy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST FrameworkInexture Solutions
 
Web driver selenium simplified
Web driver selenium simplifiedWeb driver selenium simplified
Web driver selenium simplifiedVikas Singh
 
Finding things on the web with BOSS
Finding things on the web with BOSSFinding things on the web with BOSS
Finding things on the web with BOSSChristian Heilmann
 
Developing WordPress Plugins : For Begineers
Developing WordPress Plugins :  For BegineersDeveloping WordPress Plugins :  For Begineers
Developing WordPress Plugins : For BegineersM A Hossain Tonu
 
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...GITS Indonesia
 
Customer Automation Masterclass - Workshop 1: Data Enrichment using Clearbit
Customer Automation Masterclass - Workshop 1: Data Enrichment using ClearbitCustomer Automation Masterclass - Workshop 1: Data Enrichment using Clearbit
Customer Automation Masterclass - Workshop 1: Data Enrichment using ClearbitJanBogaert8
 
Improving LibGuides Editors Access to Use Data Using the Google Analytics API
Improving LibGuides Editors Access to Use Data Using the Google Analytics APIImproving LibGuides Editors Access to Use Data Using the Google Analytics API
Improving LibGuides Editors Access to Use Data Using the Google Analytics APITabby Farney
 
Google analytics reporting using api
Google analytics reporting using apiGoogle analytics reporting using api
Google analytics reporting using apiSankar Ponnusamy
 

Similar to More than a side salad: behaviour driven testing and test driven design in Django with Lettuce (20)

Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web Framework
 
Controller Testing: You're Doing It Wrong
Controller Testing: You're Doing It WrongController Testing: You're Doing It Wrong
Controller Testing: You're Doing It Wrong
 
Introduction to Web APIs and the Google+ API - BarCamp Phnom Penh 2011
Introduction to Web APIs and the Google+ API - BarCamp Phnom Penh 2011Introduction to Web APIs and the Google+ API - BarCamp Phnom Penh 2011
Introduction to Web APIs and the Google+ API - BarCamp Phnom Penh 2011
 
Leveraging Rails to Build Facebook Apps
Leveraging Rails to Build Facebook AppsLeveraging Rails to Build Facebook Apps
Leveraging Rails to Build Facebook Apps
 
Designing and Implementing a Multiuser Apps Platform
Designing and Implementing a Multiuser Apps PlatformDesigning and Implementing a Multiuser Apps Platform
Designing and Implementing a Multiuser Apps Platform
 
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliGetting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
 
Google App Engine tutorial
Google App Engine tutorialGoogle App Engine tutorial
Google App Engine tutorial
 
OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial Intro
 
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST FrameworkEasy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
 
Web driver selenium simplified
Web driver selenium simplifiedWeb driver selenium simplified
Web driver selenium simplified
 
Finding things on the web with BOSS
Finding things on the web with BOSSFinding things on the web with BOSS
Finding things on the web with BOSS
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Developing WordPress Plugins : For Begineers
Developing WordPress Plugins :  For BegineersDeveloping WordPress Plugins :  For Begineers
Developing WordPress Plugins : For Begineers
 
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
Gits class #22: [ONLINE] Analyze Your User's Activities Using BigQuery and Da...
 
CiviCRM API v3
CiviCRM API v3CiviCRM API v3
CiviCRM API v3
 
Customer Automation Masterclass - Workshop 1: Data Enrichment using Clearbit
Customer Automation Masterclass - Workshop 1: Data Enrichment using ClearbitCustomer Automation Masterclass - Workshop 1: Data Enrichment using Clearbit
Customer Automation Masterclass - Workshop 1: Data Enrichment using Clearbit
 
Hacking For Innovation
Hacking For InnovationHacking For Innovation
Hacking For Innovation
 
Improving LibGuides Editors Access to Use Data Using the Google Analytics API
Improving LibGuides Editors Access to Use Data Using the Google Analytics APIImproving LibGuides Editors Access to Use Data Using the Google Analytics API
Improving LibGuides Editors Access to Use Data Using the Google Analytics API
 
Google analytics reporting using api
Google analytics reporting using apiGoogle analytics reporting using api
Google analytics reporting using api
 

Recently uploaded

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Recently uploaded (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

More than a side salad: behaviour driven testing and test driven design in Django with Lettuce

  • 1. more than a side salad: behaviour driven testing and test driven design in Django with Lettuce Danielle Madeley  blogs.gnome.org/danni  dannipenguin
  • 2. Just what is test driven development?
  • 3.
  • 6. But how do we write tests when we don't know what the code looks like?
  • 8.
  • 9. As a visitor to the site I want to create an account using my Google login So that I can log in without needing another password
  • 10. GivenI have a valid Google account WhenI visit the siteAnd I click create account ThenI am redirected to Google http://www.flickr.com/photos/27369469@N08/2660160225
  • 12. Feature: Authenticate to API As a searcher/API user I want to authenticate to the API So that I can make queries Scenario: I am not authenticated to the API When I get the resource "/api/v3/hello/" Then I get the response code 401
  • 13.
  • 15. from lettuce import step, world @step(r'I get the resource "([^"]*)"') def get_resource(step, url): """ Make a GET request to the given URL """ world.response = world.client.get(url)
  • 17. from django.test.client import Client from lettuce import before, step, world from nose.tools import assert_equals @before.each_scenario def set_default_client(scenario): world.client = Client() @step(r'I get the resource "([^"]*)"') def get_resource(step, url): world.response = world.client.get(url) @step(r'I get the response code (d+)') def check_response_code(step, code): code = int(code) assert_equals(world.response.status_code, code)
  • 19. # settings.py INSTALLED_APPS = ( ... 'lettuce.django', 'myapp', ) LETTUCE_APPS = ( 'myapp', ) LETTUCE_USE_TEST_DATABASE = True
  • 21. from lettuce import before, world # import external lettuce steps import lettuce_webdriver.webdriver @before.all def set_browser(): """ Create a browser instance for use in tests. """ world.browser = webdriver.PhantomJS(...) world.browser.set_window_size(1200, 800)
  • 22. def site_url(url): base_url = 'http://%s' % socket.gethostname() if server.port is not 80: base_url += ':%d' % server.port return urlparse.urljoin(base_url, url) @step("I visit the site") def open_site(step): step.given('I visit "%s"' % site_url('/'))
  • 23. Scenario: Add consumer with blank Contact name When I log in to admin with username "admin" and And I click "Consumers" And I click "Add consumer" And I fill in "Organisation" with "OOOO" And I fill in "Contact name" with "" And I fill in "Contact number" with "0399999999" And I fill in "Website" with "www.test.com" And I press "Save" Then I should see "This field is required" And there should be 0 consumers in the database
  • 25. Feature: Create new API key As an administrator I want to create a new API key So that I can enable others to query API Background: Given I have users in the database: | username | password | is_superuser | | admin | secret | true |
  • 26. Built in steps using Django's model introspection Given I have users in the database: ... Then there should be 1 consumer in the database And consumer should be present in the database: ...
  • 27. Which are extendable @creates_models(User) def create_user(step): data = hashes_data(step) for hash_ in data: is_superuser = hash_.pop('is_superuser', Fals if is_superuser: user = User.objects.create_superuser(**ha else: user = User.objects.create_user(**hash_) user.save() reset_sequence(User)
  • 29.
  • 30. Given I have items in my cart When I go to checkout And I pay for the items Then everything worked
  • 32. write reusable scenarios Scenario Outline: I edit a user to add a team Given users have permissions: | user | organisation | permission | | peon@org.org | OrgCorp | organisation_user | And I log in with email "<email>" through the profile serve When I visit site page "organisation/1/admin/user/4/edit" And I select option "Team 1" from selector "Team" And I press "Save" Then there should be 1 organisation member metadata in the Then organisation member metadata should be present in the | organisation__name | user__email | team | | OrgCorp | peon@org.org | Team 1 | Examples: | email | | god@god.org | | superuser@org.org | | poweruser@org.org |
  • 33. tie each feature file to a single story
  • 36. fin ;-P questions? colophon This presentation was done in reveal.js using Junction, Cantarell and Source Code Pro with photography from the Creative Commons. Infoxchange is hiring. Come and chat to me!  blogs.gnome.org/danni  dannipenguin http://www.flickr.com/photos/mau3ry/3763640652/