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

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Recently uploaded (20)

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

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/