Obey the Testing Goat - Part I
It aligns so well with what I am teaching my first year computer science students this year, that we just began using it in class. I had started going through it for the first time back over the Winter break, where I made it to Chapter 9: Testing Deployment Using a Staging Site. I will need to adapt our classroom environment to make this work, including setting up our own in-class DNS server using dnsmasq and using a KVM server to provide each student with their own Nginx server in our lab.
At a rate of one chapter each time the class meets, we will reach chapter 9 in mid March, so I have a bit of time to get the needed infrastructure working. In the mean time, I started the book over to better understand it, and today I will start it over again for a third time to keep pace with the students.
Setting Up the Development Environment
To each of the following to create the Python virtual environment and install the needed software:
Make a directory that will host the project, change into it, and create and then activate the virtual environment. I will use python-tdd-book this time to distinguish this as my third pass at this:
$ mkdir python-tdd-book $ cd python-tdd-book $ python3 -m venv virtualenv $ source virtualenv/bin/activate (virtualenv) $
Install the Selenium driver for Firefox, Gecko Driver, from https://github.com/mozilla/geckodriver/releases. We are going to put it in our virtual environment's bin subdirectory (virtualenv/bin), since students won't have access to administrative privileges. Assuming we still have the virtual environment activated, and that downloading Gecko put it in the user's Downloads directory, we will:
(virtualenv) $ mv ~/Downloads/geckodriver-v0.24.0-linux64.tar.gz . (virtualenv) $ tar xzvf geckodriver-v0.24.0-linux64.tar.gz (virtualenv) $ rm geckodriver-v0.24.0-linux64.tar.gz (virtualenv) $ mv geckodriver virtualenv/bin/ (virtualenv) $ geckodriver --version geckodriver 0.24.0 ( 2019-01-28) The source code of this program is available from testing/geckodriver in https://hg.mozilla.org/mozilla-central. This program is subject to the terms of the Mozilla Public License 2.0. You can obtain a copy of the license at https://mozilla.org/MPL/2.0/. (virtualenv) $
Finally, install the versions of Django and Selenium we will be using with the text:
(virtualenv) $ pip install "django<1.12" "selenium<4"
That's it. We are ready to start TDD!
Setting Up the GitLab Repository
Since I am mainly writing this post as a resource for my students, I'll now provide assistance getting our GitLab repos setup. I am assuming we have followed all instructions in Chapter 1: Getting Django Set Up Using a Functional Test up to and including the commit of the .gitignore file. What follows will create a project on GitLab:
(virtualenv) $ git commit -m "Make initial commit" *** Please tell me who you are. Run git config --global user.email "email@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. (virtualenv) $ git config --global user.email "firstname.lastname@example.org" (virtualenv) $ git config --global user.name "Jose Ejemplo" (virutalenv) $ git commit -m "Make initial commit" [master (root-commit) fabfdef] Make initial commit 7 files changed, 190 insertions(+) create mode 100644 .gitignore create mode 100644 functional_tests.py create mode 100755 manage.py create mode 100644 superlists/__init__.py create mode 100644 superlists/settings.py create mode 100644 superlists/urls.py create mode 100644 superlists/wsgi.py (virutalenv) $
You will of course have to substitute your real name and email for the example ones. Assuming you already have your ssh key on GitLab, you can use Push to create a new project to guide you through creating your repo:
(virutalenv) $ git push --set-upstream email@example.com:jejemplo/python-tdd-book.git master
Again, you will need to substitute your actual GitLab user name for jejemplo. So there we have it. I hope this post will help my students over some of the rough spots in the process.
Time to start testing!