{"id":506,"date":"2014-05-17T09:18:21","date_gmt":"2014-05-17T15:18:21","guid":{"rendered":"http:\/\/www.crccheck.com\/blog\/?p=506"},"modified":"2015-10-11T22:23:04","modified_gmt":"2015-10-12T04:23:04","slug":"using-travis-ci-with-your-geodjango-project","status":"publish","type":"post","link":"https:\/\/www.crccheck.com\/blog\/using-travis-ci-with-your-geodjango-project\/","title":{"rendered":"Using Travis CI with your GeoDjango project"},"content":{"rendered":"<p><a href=\"http:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2014\/05\/travis-fail.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-513 size-full\" src=\"http:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2014\/05\/travis-fail.png\" alt=\"travis fail\" width=\"830\" height=\"209\" srcset=\"https:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2014\/05\/travis-fail.png 830w, https:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2014\/05\/travis-fail-300x75.png 300w\" sizes=\"auto, (max-width: 830px) 100vw, 830px\" \/><\/a><\/p>\n<p>I&#8217;m usually <a href=\"http:\/\/www.crccheck.com\/blog\/we-dont-need-no-stinkin-geo\/\" target=\"_blank\">very hesitant<\/a> to use PostGIS because it makes testing more difficult. Instead of an in-memory sqlite database, you have to spin up and down a database instead. I decided to do it anyways, and then I forgot I had Travis CI on this project and every commit emailed me a reminder of my failure.<\/p>\n<p>Luckily, a cursory search uncovered that Travis CI has support for PostGIS. And even luckier for me, it wasn&#8217;t that hard to do. I started with <a href=\"http:\/\/mattmakesmaps.com\/blog\/2014\/01\/11\/configure-postgis-with-travis-ci\/\" target=\"_blank\">this blog post<\/a>, and ended up with this as my .travis.yml:<\/p>\n<pre>language: python\r\naddons:\r\n  postgresql: \"9.3\"\r\nenv:\r\n  PYTHONPATH='.'\r\ninstall: \"pip install -r requirements-dev.txt\"\r\nbefore_script:\r\n  - psql -U postgres -c 'CREATE DATABASE tx_lobbying;'\r\n  - psql -U postgres -c \"CREATE EXTENSION postgis\" -d tx_lobbying\r\n  - psql -U postgres -c \"CREATE EXTENSION postgis_topology\" -d tx_lobbying\r\nscript: make test<\/pre>\n<p>The <code>postgresql: \"9.3\"<\/code> line wasn&#8217;t even necessary, but according to <a href=\"http:\/\/docs.travis-ci.com\/user\/using-postgresql\/\" target=\"_blank\">their docs<\/a>, Travis CI uses Postgres 9.1 by default, and I&#8217;m using 9.3. The only other change I had to make was tangential: I still had my settings set to use a SQLite database by default, but I should have made it default to a PostGIS instead.<\/p>\n<p>I feel like I should mention more about what I did in my settings.py since I&#8217;m writing this specifically about GeoDjango, but I don&#8217;t think the changes I made really had much to do getting it to run of Travis CI.<\/p>\n<p>According to the <a href=\"https:\/\/docs.djangoproject.com\/en\/1.7\/ref\/contrib\/gis\/testing\/\" target=\"_blank\">Testing GeoDjango docs<\/a>, the Django test runner would have created a <code> test_tx_lobbying<\/code> database based off a\u00c2\u00a0 <code>template_postgis<\/code> Postgres template, but I short-circuited that logic on Travis CI and ended up with a solution that did not involve messing with Postgres templates.<\/p>\n<p>Now that I&#8217;ve done it once, and it wasn&#8217;t horrible, I plan on doing more things with GeoDjango that I&#8217;ve hesitated to do before. Now to find a cheap way to host toy PostGIS projects.<\/p>\n<p>Reference: https:\/\/github.com\/texastribune\/tx_lobbying\/commit\/b7119580e4cd4b6c61fc992cc5a4fc6222c6483e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m usually very hesitant to use PostGIS because it makes testing more difficult. Instead of an in-memory sqlite database, you have to spin up and down a database instead. I decided to do it anyways, and then I forgot I had Travis CI on this project and every commit emailed me a reminder of my&hellip;<\/p>\n <a href=\"https:\/\/www.crccheck.com\/blog\/using-travis-ci-with-your-geodjango-project\/\" title=\"Using Travis CI with your GeoDjango project\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">Using Travis CI with your GeoDjango project<\/span><\/a>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4],"tags":[51,66,65,64,67],"class_list":["entry","author-showmewhatyougot","post-506","post","type-post","status-publish","format-standard","category-technical","tag-django","tag-geodjango","tag-postgis","tag-postgres","tag-travis-ci"],"_links":{"self":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/comments?post=506"}],"version-history":[{"count":6,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/506\/revisions"}],"predecessor-version":[{"id":517,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/506\/revisions\/517"}],"wp:attachment":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/media?parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/categories?post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/tags?post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}