SPRAT
Spreadsheet API Tester
Julian Higman
Julian Higman
●

Freelance developer

●

PHP/Ruby/Linux/etc

●

Agile (XP)

●

Tests
Sprat : Spreadsheet API Tester
●

Why

●

What

●

How

●

WTF?
Background
●

KnowMalaria

●

Prescription System

●

Antimalarials, and now vaccines
KnowMalaria
●

Data-centric app

●

Domain experts

●

People might die
Testing
●

Unit test

●

Integration test

●

Functional test

●

Live monitoring

●

...Exo-test?
Manual Test Scenarios
Manual Test Scenarios
Requirement
●

Non-programmers

●

Complex test scenarios

●

Running outside of the build

●

Scheduled or On Demand

●

...
Idea
●

Use spreadsheets as test input

●

Expose testable functions as APIs

●

“Run” button
Architecture
APIs
●

RESTful (well, GET, at least)

●

Return JSON
Github API

https://api.github.com/search/repositories?q=sprat
{
"total_count": 3,
"items": [
{
"id": 1898910,
"name": "sprat",
"full_name": "hinathan/sprat",
"html_url": "https://githu...
JSONPath
●

$.store.book[0].title

●

$['store']['book'][0]['title']

●

$.store.book[(@.length-1)].title

●

$.store.book...
Tests
id

q

$.total_count

1

sprat

3
Tests
id

q

$.total_count

$.items[0].description

1

sprat

3

A simple PHP+REST
API toolkit

2

mackerel

7

Object sto...
Sprat spreadsheet
Config
Menu
Simplification : Hashes
for API response
{ “key1” : “val1”, “key2” : “val2” }
expectation columns called
“key1”, “key2”
wi...
Special case : Arrays
id

country

1

Albania

2

Angola

3

Antartica

4

Aruba

Cholera

Diptheria

Hep A
Y

Y

Y

Y

Y
...
Array API

/api/diseases?country=Aruba
[“Diptheria”, “Hep A”]
Array spreadsheet
Sprat server
●

Ruby

●

Sinatra

●

Redis

●

Resque
Invoke Sprat
POST to /jobs
params:
spreadsheet = <spreadsheet name>
worksheet = <worksheet name>
host = <host name>
Read and write spreadsheets
Ruby Gem : https://github.com/gimite/google-drive-ruby
session = GoogleDrive.login("username@g...
In the spreadsheets..
●

Google Apps Script (basically Javascript)

●

Menus

●

URL Fetch Service

●

PDFs

●

Emails

●
...
Add menu items
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [
{name: "Run tests",...
Invoke test runner
var payload =
{
"spreadsheet" : “My Test Spreadsheet”,
"worksheet" : “Worksheet 1”,
"host" : “api.test....
Create PDF
var ss = SpreadsheetApp.getActiveSpreadsheet();
var file = DriveApp.getFileById(ss.getId())
var pdf = file.getA...
Send Email
MailApp.sendEmail(
“sprat-user@sprat.org”,
“Your latest Sprat report”,
“Please see attached”,
{attachments:[pdf...
Triggers
Demo
●

Github

●

Travis

●

Heroku

●

Redis Cloud
So how's it working for us?
●

10 spreadsheets

●

2000 tests

●

Nightly emails
Other benefits
●

Step-change in rate of data tests

●

TDD by users

●

Pair-programming data changes

●

Diagnosing prob...
Limitations
●

GET

●

JSON

●

No custom headers

●

Assumes HTTPS endpoint

●

JSONPath

●

Error responses

●

Setup/te...
Future
●

Matchers

●

OAuth

●

Standards

●

JSON Schema

●

Continuous Integration
Questions
●

Anyone similar problem?

●

Anything that already exists?

●

Any glaring problems?

●

Any suggestions for i...
KTHXBYE!

http://jhigman.github.io/sprat/
@jhigman
@staringskyward
SPRAT - Spreadsheet API Tester
Upcoming SlideShare
Loading in …5
×

SPRAT - Spreadsheet API Tester

1,645 views
1,479 views

Published on

SPRAT is a test tool, which uses spreadsheets to define tests and then runs those tests against specified APIS.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,645
On SlideShare
0
From Embeds
0
Number of Embeds
35
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • An example of a simple JSON API is github repo search
  • Give it a query param of a search term
  • And you get JSON (actually much more
    Btw – rate limited!
    )
  • Key/value pairs
    Define api, host
    Get back started/finished, status
    Parameters (comma sep)
    Ignore (comma sep)
    Aliases
    Colour coding (conditional formatting
  • SPRAT - Spreadsheet API Tester

    1. 1. SPRAT Spreadsheet API Tester Julian Higman
    2. 2. Julian Higman ● Freelance developer ● PHP/Ruby/Linux/etc ● Agile (XP) ● Tests
    3. 3. Sprat : Spreadsheet API Tester ● Why ● What ● How ● WTF?
    4. 4. Background ● KnowMalaria ● Prescription System ● Antimalarials, and now vaccines
    5. 5. KnowMalaria ● Data-centric app ● Domain experts ● People might die
    6. 6. Testing ● Unit test ● Integration test ● Functional test ● Live monitoring ● ...Exo-test?
    7. 7. Manual Test Scenarios
    8. 8. Manual Test Scenarios
    9. 9. Requirement ● Non-programmers ● Complex test scenarios ● Running outside of the build ● Scheduled or On Demand ● Feedback
    10. 10. Idea ● Use spreadsheets as test input ● Expose testable functions as APIs ● “Run” button
    11. 11. Architecture
    12. 12. APIs ● RESTful (well, GET, at least) ● Return JSON
    13. 13. Github API https://api.github.com/search/repositories?q=sprat
    14. 14. { "total_count": 3, "items": [ { "id": 1898910, "name": "sprat", "full_name": "hinathan/sprat", "html_url": "https://github.com/hinathan/sprat", "description": "A simple PHP+REST API toolkit" }, { "id": 9957180, "name": "sprat", "full_name": "jhigman/sprat", "html_url": "https://github.com/jhigman/sprat", "description": "Spreadsheet API Test Runner" }, { "id": 1840441, "name": "Spratly", "full_name": "rgv151/Spratly", "html_url": "https://github.com/rgv151/Spratly", "description": "Backend & Development Kit for Laravel 4" } ] }
    15. 15. JSONPath ● $.store.book[0].title ● $['store']['book'][0]['title'] ● $.store.book[(@.length-1)].title ● $.store.book[?(@.price < 10)].title http://goessner.net/articles/JsonPath/
    16. 16. Tests id q $.total_count 1 sprat 3
    17. 17. Tests id q $.total_count $.items[0].description 1 sprat 3 A simple PHP+REST API toolkit 2 mackerel 7 Object storage system 3 shark 511 Hive on Spark
    18. 18. Sprat spreadsheet
    19. 19. Config
    20. 20. Menu
    21. 21. Simplification : Hashes for API response { “key1” : “val1”, “key2” : “val2” } expectation columns called “key1”, “key2” will be interpreted as “$.key1”, “$.key2”
    22. 22. Special case : Arrays id country 1 Albania 2 Angola 3 Antartica 4 Aruba Cholera Diptheria Hep A Y Y Y Y Y Y
    23. 23. Array API /api/diseases?country=Aruba [“Diptheria”, “Hep A”]
    24. 24. Array spreadsheet
    25. 25. Sprat server ● Ruby ● Sinatra ● Redis ● Resque
    26. 26. Invoke Sprat POST to /jobs params: spreadsheet = <spreadsheet name> worksheet = <worksheet name> host = <host name>
    27. 27. Read and write spreadsheets Ruby Gem : https://github.com/gimite/google-drive-ruby session = GoogleDrive.login("username@gmail.com", "mypassword") ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0] ws[2, 1] = "foo" ws[2, 2] = "bar" ws.save()
    28. 28. In the spreadsheets.. ● Google Apps Script (basically Javascript) ● Menus ● URL Fetch Service ● PDFs ● Emails ● Triggers
    29. 29. Add menu items function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var menuEntries = [ {name: "Run tests", functionName: "runThisSheet" } ]; ss.addMenu("Test Runner", menuEntries); }
    30. 30. Invoke test runner var payload = { "spreadsheet" : “My Test Spreadsheet”, "worksheet" : “Worksheet 1”, "host" : “api.test.com” }; var options = { "method" : "POST", "payload" : payload }; var response= UrlFetchApp.fetch(“http://sprat.testrunner.org”, options); var content = response.getContentText();
    31. 31. Create PDF var ss = SpreadsheetApp.getActiveSpreadsheet(); var file = DriveApp.getFileById(ss.getId()) var pdf = file.getAs(MimeType.PDF); var folder = DocsList.getFolder(“SpratPDFs”); var file = folder.createFile(pdf);
    32. 32. Send Email MailApp.sendEmail( “sprat-user@sprat.org”, “Your latest Sprat report”, “Please see attached”, {attachments:[pdf]} );
    33. 33. Triggers
    34. 34. Demo ● Github ● Travis ● Heroku ● Redis Cloud
    35. 35. So how's it working for us? ● 10 spreadsheets ● 2000 tests ● Nightly emails
    36. 36. Other benefits ● Step-change in rate of data tests ● TDD by users ● Pair-programming data changes ● Diagnosing problems ● Versioning ● Authentication ● API-first design
    37. 37. Limitations ● GET ● JSON ● No custom headers ● Assumes HTTPS endpoint ● JSONPath ● Error responses ● Setup/teardown
    38. 38. Future ● Matchers ● OAuth ● Standards ● JSON Schema ● Continuous Integration
    39. 39. Questions ● Anyone similar problem? ● Anything that already exists? ● Any glaring problems? ● Any suggestions for improvements? ● Anyone want to try it?
    40. 40. KTHXBYE! http://jhigman.github.io/sprat/ @jhigman @staringskyward

    ×