- Merge conflicts
- Bash
- Git
- Github
- Docker
- Docker Cloud
- Python Unit Testing
Born out of the "Extreme Programming" agile development method.
The basic idea:
-
Determine what you want your code to do.
-
Write a new test that checks for the desired functionality.
-
Run tests. (Should fail the first time.)
-
Edit/write the code for your new feature.
-
Re-run tests. If failures still exist, back to 4.
(We did this with the bash koans.)
Our next step is to start building a running flask server in our Docker container. We'll do this using a test-driven development approach.
Prep your local repository
- Make sure it is up to date with any merged pull requests on github.
git checkout master
git pull origin master- Cut a new branch off of master for your TDD flask work.
git checkout -b [branch name]Create the Test
- Alter your
run_test.shfile to look like the following:
#!/bin/bash
echo "Running Flask Unit Tests"
python3 unh698_test.py-
Create an empty
unh698.pyfile. -
Create a
unh698_test.pyfile with these contents:
import unittest
import unh698
class FlaskrTestCase(unittest.TestCase):
def setUp(self):
self.app = unh698.app.test_client()
def tearDown(self):
pass
def test_home_page(self):
# Render the / path of the website
rv = self.app.get('/')
# Chech that the page contians the desired phrase
assert b'UNH698 Website' in rv.data
if __name__ == '__main__':
unittest.main()Ensure the test runs, but fails
-
Commit the changes to
run_test.sh,unh698.py, andunh698_test.pyto your branch. -
Push your branch to your github, and start a pull request.
-
Add a comment on your pull request with the contents @MathYourLife so I can see how you're doing. Feel free to @mention other students in class to get their help as well. You can find the list here https://github.com/orgs/unh-comp-698-systems-software/people .
-
Verify that the build in docker cloud attempts to run the python unit tests but fails. You should see an error like
python3: command not found
Make the test pass
- Make changes to either
Dockerfileand/orunh698.pyto attempt to make the test pass.
Hints:
- The Dockerfile controls what in installed on the server.
- The app.py controls how the Flask website will run.
- Start with changing just the Dockerfile until you can get the python test to actually run.
- Then move on to setting up the unh698.py file correctly.
References:
- Search "how to build flask application in docker"
- Flask 0.12 documentation http://flask.pocoo.org/docs/0.12/
- Commit and push changes to the github branch. If the test passes, merge and submit a link to your pull request. If the test fails, return to step 4.