[Tutorial][Trello][API] Test Driven Development (setting up)

I’m going to have to do more reading on Test Driven Development, but I did mess around with it today.

First get the libraries (nose helps you test individual test cases as opposed to running all the tests again which is helpful).

import unittest
import nose

trello_auto is a separate .py file where I put all of my methods/functions that I am testing here.

import trello_auto
import trello

Setting up a class for testing. I don’t understand python classes entirely or understand when you want different testing classes, though I think it might have something to do with the setUp().

setUp() and tearDown() are two unittest methods that run before and after every test. That started to get really burdensome for my system, so my boss actually changed them to class methods (initially they were just regular setUp(self) functions) by adding @classmethod and changing “self” to “cls”.

The net result is that the setUp() now runs for the class (so once for all the contained test cases).

class TestMethods(unittest.TestCase):

    def setUpClass(cls):
        test_lists = {}
        for list in test_master_lists:
            test_lists[list] = test_master_board.add_list(list)
            for card in test_master_lists[list]:

setUpClass(cls) finds the test_master_board which is initialized later in the file, then strips out the default lists that are on the board, then creates boards with cards match the specifications I put in test_master_lists.

This test_master_board is only torn down (by tearDownClass(cls) after the class is done.

    def tearDownClass(cls):
        for board in return_list_open_boards(client, 'test_master_board'):

This is the tearDown that cleans out created boards after every test. This helps keep trello from being flooded with test boards.

    def tearDown(self):
        for board in return_list_open_boards(client):
            if board.name == "System 0" or board.name == "System 1" or board.name == "System 2" or board.name == "System 3":

I’m creating a test_master_board so that I can then perform all kinds of trello actions. Creating the test_master_board allows me to know what specifically should exist, so I figured it was a good first step.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s