As I mentioned in my previous article, I was looking to write some tests for my Pelican site deployment via CircleCi.
I wasn’t looking for anything in depth, just a kind of placeholder test while I wet my feet. I had never written any sort of testing, and in all fairness this isn’t a particularly useful test. I just wanted a proof of concept.
So my updated
circle.yml looks like this:
dependencies: override: - pip install pelican markdown s3cmd requests - git clone https://github.com/gilsondev/pelican-clean-blog.git && pelican-themes --install pelican-clean-blog - echo -e "[default] \naccess_key = $S3CFG_ACCESS_KEY \nsecret_key = $S3CFG_SECRET_KEY \n" > /home/ubuntu/.s3cfg test: post: - ./site_test.py deployment: aws: branch: master commands: - make html - make s3_upload
Notice, I have added
requests to the pip install, as the python script I have written requires it.
Next you will see the inclusion of
test: which specifies your tests and then the script
site_test.py that contains the test.
#!/usr/bin/env python import unittest import requests class TestSite(unittest.TestCase): def test_status(self): r = requests.get('http://www.havingatinker.uk/') self.assertEqual(r.status_code, 200) if __name__ == '__main__': unittest.main()
That is my extremely basic and pointless script that sees if the site
havingatinker.uk is returning a 200, if not it returns that the test failed. Fortunately it does, and the test passes successfully. You can see the output below:
./tests/site_test.py . ---------------------------------------------------------------------- Ran 1 tests in 0.001s OK
Considering the whole point of testing is to catch anything before the changes go out, the test above isn’t much use. The whole point of testing is to make sure your changes don’t break your live environment before deploying which the current one isn’t doing.
A more worth while test might be to bring up a local webserver and test the generated content is as expected, or something to that effect. The main thing is that I now have something working. All my ramblings above are just proof of concept, and has given me a platform to write more tests in the future.
Hopefully this acts as a gateway drug into the world of testing…but we’ll just have to wait and see.
Shall keep you updated on the improved tests soon.