Review: Tests in Django

52 views
Skip to first unread message

Anthony Fox

unread,
Feb 6, 2017, 7:31:29 PM2/6/17
to Penny University
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, Scott Burns, Chris Graffagnino, Nicole Dominguez, and myself 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. 


`importapp/tests.py, utils.py, and views.py`
are of interest in regards to today's topic.

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

Overall:
  • Discussion: 10/10
  • Company: 10/10
  • Dumpster Fire: 10/10

Chad Upjohn

unread,
Feb 6, 2017, 7:44:40 PM2/6/17
to Penny University
I'll need to add my lessons learned or takeaways.  But two things first:

1) the dumpster fire is real.  It happened when a truck's cab that was parked next to the building caught on fire and subsequently jumped to the dumpster.  Lesson learned: when you have the chance to take a picture of an actual dumpster fire you should so that you can add a real picture in your next presentation.  It would be so much better than a hand-drawn picture.

2) I have seen the Corolla Sport in real life.  I can not vouch to it's zero to sixty time because I didn't pull out the stopwatch on my iphone quickly enough, but it did move fast.

Anthony Fox

unread,
Feb 6, 2017, 7:51:02 PM2/6/17
to Penny University

From Twitter:

Chad Upjohn

unread,
Feb 7, 2017, 8:34:19 AM2/7/17
to Penny University
In the process of asking about testing, Anthony introduced me to TDD and a book called TDD with Python.  The author follows a strict process of write the test and then write code until the test pass.

  • My first question is how strictly does one adhere
    • Scott Burn's opinion is that until you have thought through how to solve the problem, you don't know what you need to test for.  Additionally, he pointed out that writing code is 'expensive' so taking the time to define the solution and then write the tests around that solution is more valuable.
  • Second question was about trade off because there is always a trade off
    • The response to this question was level of importance.
    • For instance:
      • login page for all users vs. an internal app that 4 people use.
      • For the internal app you can say 'hey, sorry.  I know how to fix that'

In a separate conversation at PyTN, we were discussing using float vs decimal for money.  Eric Appelt said he was working on an old code base and had to use float to get older unit tests to pass.  He couldn't get an answer from the business on the reason behind the tests.  Eric's example showed the long-term value of unit tests.

mattm.eternal

unread,
Feb 10, 2017, 10:33:29 AM2/10/17
to Penny University
Damn! I stumbled upon this post a little too late. I'm currently a student at Nashville Software School with about 6 weeks until graduation. My cohort is working with Python and Django in the back end of things. I'd love to get in on another meet up about testing and TDD if it anyone is interesting in doing another.

Alex Simonian

unread,
Feb 10, 2017, 10:37:05 AM2/10/17
to Penny University
I echo what Matt said!  He is a classmate in my cohort at Nashville Software School.  I would be interested in doing another TDD meeting.  It helps me to gain new perspectives and learn through different modalities.  TDD is a beast to grok!

Chad Upjohn

unread,
Feb 17, 2017, 4:53:49 PM2/17/17
to Penny University
Had another discussion on testing in Python.  The one major takeaway is to test the function's intended behavior.  In the example we worked through this came out as testing the different decision points.  The best way to understand it is the different directions of if statements.  In other words, what is the intended behavior from `if len(string) > 10:`, test that happens.  The other thing to put a test on is third party responses.  I am finding it hard to explain but it is testing what your code will do if certain responses from a third party happen.  So if the third party doesn't respond in x-time or just isn't available.

Talked also about mocks, stub, and fakes.  Note the slides in the presentation: https://github.com/jasonamyers/pyohio2016-for-those-about-to-mock/blob/master/presentation.pdf

Side note: somehow talking to triple-cookie expands my knowledge and understanding of the subject and subsequently reveals something that I should add to my list of things to learn.
Reply all
Reply to author
Forward
0 new messages