[***"Smoke test"***](http://en.wikipedia.org/wiki/Smoke_testing_(electrical))
That's when we press the switch for a physical product to see if it starts or if there comes out smoke from it... no more, no less.

When it comes to software the equivalent is when we start a program, or exercise a feature etc. But we only look for obvious smoke coming out and arn't terribly concerned about the actual functionality.

So a few months ago we worked in my team on providing data from our database via a REST API.
Being the tester on the team I of course wanted to take the REST API for a spin as soon as possible when my team mates implemented it.
The reason for that so they could get fast feedback on their work, about what works, and what doesn't work.

I want to share what I did do very quickly, and did so without to much concern about the data.
I did it in order to test the first implementation of the api for rapid feedback to my developers.

Since I was more interested in seeing smoke than actually providing a lot of information I decided I just wanted to exercise the api:s that had been implemented, and the best way to do that would be to create a quick test harness in Python that excercised the api:s and summarized the results (smoke/no smoke).
By excercised the APIs I meant just sending the appropriate request (GET/POST/PUT/DELETE) to the APIs.

Python has the always so excellent library "Requests" that turns making http requests into a breeze, and my favorite editor of choice is easily sublime text 2. So let me get started showing you what I did.

When we designed the api one of my colleagues had summarized it all in a word document which I asked him to send me.
It basically contained all the REST api:s that you could call, and if the request was a GET, POST, PUT, or DELETE.


Full API document (data scrubbed)

So the first thing to do was to select it all and copy the text mass into sublime text, the reason of which will soon be obvious.
There is an outstanding feature in sublime text called "multiple cursors" where you can simultaneously select and have several cursors at the same time in the document.
If you mark a string of text and then use the short-cut "ALT+F3" Sublime Text will select all instances of this string for you and you have multiple cursors.

So what I wanted to do was find some unique string I could search for and then copy.

And voila I had now with minimal effort extracted all the GET url:s for our REST interface.
A little cleaning up and then into a Python list.
I recorded a short video that demonstrates what I'm doing.

If you're wondering about the keyboard commands in the video above then here is a summary of the first part, the second part of creating the Python list I'm leaving as an excercise to the reader:

["Select All" -> "Copy" -> "Paste" -> select "[GET]/bookdata/v1.0/" -> ALT+F3 -> HOME -> SHIFT + END -> "Copy" -> "New Document" -> "Paste"]

From here on out I wrote a very simple loop that traversed over all the URL:s, appended them onto the address of my local machine where I had deploy:ed the api, and then sent a http request (GET), checking the return code of it's succesful (200) or if something else happened (aka. smoke...).

It might not be the prettiest code I've written, but it got the job done, which was assisting me in exploring the API and being able to give feedback to my developers early.

I realise now that I spent more time writing this blog post than I spent writing the code that traversed the api:s exposed.

Oh and we did find some things that stood out in the results and I could then move on to investigating them myself. Some of those were errors in the api that my colleagues fixed after some quick feedback along with the python script. Providing them the Python script helped them verifying the fixes afterwards.

Later I quickly added some added smoke test coverage to the POST requests as well using JSON and Python, but thats another blog post to come.

Summary

So I just showed you how you can use Python and a good text editor to quickly cook up some code that will exercise your REST api looking for smoke.

Just remember we use this code to smoke test and find "interesting" stuff to investigate for ourselfes,
Automation should always help a tester so they can do more cognitive testing and focus on investigating anomalies by removing the heavy work.