When Chad posted about wanting to know more about Test Driven Development in Django, I said to myself.. “hey, I’m not completely clueless in this area. I think I can help.” Max and Scott saw the topic and joined in as well. Then Chris and Nicole did too! We talked a bit over the weekend while at PyTn (great conference) and ultimately decided to meet up at Cinco De Mayo Monday (today) at 11 am.

Come 10:45, all of us loaded into my incredibly fast 2010 Toyota Corolla Sport (0 - 60 in less than a minute, probably) and drove to Cummins station. We had a few issues finding parking. Mostly due to a massive dumpster fire and the entirety of Cummins Station being EVACUATED. We agreed to go to Whiskey Kitchen instead…

At Whiskey Kitchen, we had a great discussion involving fundamental principles of TDD. Where to draw the lines. How to convince the nonbelievers. And common techniques to make it easy to obey the testing goat. I also lent Chad my Test Driven Development book. Thanks to Chad providing a useful scenario I was also able to write up a quick Django app that shows a very simple implementation of testing import functionality.

My PennyU Github Repo

The files to note are:

TDD
  • py
  • py
  • py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# tests.py

from io import StringIO

from django.test import TestCase

from importapp.utils import handle_upload


class ImportViewTestCase(TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_view_loads_correctly(self):
        resp = self.client.get('/')
        self.assertTrue(resp.status_code, 200)


class ImportUtilsTestCase(TestCase):
    def setUp(self):
        self.test_csv = StringIO('12,waffles,anthony,food\n25,cookies,chad,food')

    def tearDown(self):
        pass

    def test_only_add_quatities_above_13(self):
        valid, invalid = handle_upload(self.test_csv)
        self.assertEqual(valid, [['25', 'cookies', 'chad', 'food']])
        self.assertEqual(invalid, [['12', 'waffles', 'anthony', 'food']])

    def test_none_added_if_none_over_13(self):
        self.test_csv = StringIO('12,waffles,anthony,food\n8,cookies,chad,food')
        valid, _ = handle_upload(self.test_csv)
        self.assertEqual(valid, [])

This and any future PennyU projects will be stored in a public repo on my GitHub profile named PennyU.

Overall:

  • Discussion: 1010
  • Company: 1010
  • Dumpster Fire: 1010

Bonus Pic of :fire:

Truck-Fire