Travis-ci.org and Coveralls.io: Continuous Integration and QA made easy

Linux, Programmazione, Python No Comments »

Developing a large web application or before deploying some code is very important to verify the quality of the code itself, check if we have introduced any regression or bug and have something that tell us if we are increasing or decreasing the quality of the code.

Suppose we are in an organization or a company where the basic rule is: master branch is always ready/stable to be deployed. In a team usually people work on personal branches, then when the code is stable it's merged with master.

How do we check if the code is stable and ready to be merged? First of all we need to cover all our code with proper tests (I won't go in details about unit testing here, I assume that the reader knows what I'm talking about), then we need to actually run them, possibly in an isolated environment that is similar to the production one, and check if they all pass. If they do, we are quite safe to merge our code with master branch.

How can we ensure that all the developers remember to run tests when they push some new code? To make things a bit more real, let's take the example of a Python/Django product (or even a library) that currently supports Python 2.6, 2.7, 3.3 and Django 1.4.x, 1.5.x, 1.6.x. The whole matrix consists of 9 possible combinations. Do we have to manually run tests on 9 configurations? No, we don't.

Travis-ci.org

Travis is a continuous integration tool that, once configured, takes care of these tasks and let us save lot of time (that we can use to actually write code). Travis-ci.org is an online service that works with GitHub (it requires we use GitHub as repository for our code), and once we have connected the two accounts and configured a very simple file in our projects, it's automatically triggered when we push on our GitHub repository.

The configuration consists of adding a file named .travis.yml in the root of our project. A working example is available here https://github.com/andreagrandi/workshopvenues/blob/master/.travis.yml (all the env variables I set are not required normally, but that's where I save the values of my configuration, so they need to be initialized before I can run tests).

The service supports most of the languages that are commonly used and even a good number of PAAS, making it very easy to automatically deploy our code. If it should not be enough for your needs, they also expose a public API. I suggest you to give a look at the official documentation that will explain everything in details http://docs.travis-ci.com

Once everything is configured, we will have something like this on our console https://travis-ci.org/andreagrandi/workshopvenues/jobs/19882128

travis-ci-console

If something goes wrong (if tests don't pass for example) we receive a notification with all the informations about the failing build, and if we had configured an automatic deployment of course the code would not be deployed in case of a failing build.

Travis-ci.org is completly free for opensource projects and has also a paid version for private repositories.

Coveralls.io

There is a nice tool available for Python called coverage. Basically it runs tests and checks the percentage of the source code that is covered by tests, producing a nice report that shows us the percentage for every single file/module and even the lines of code that have been tested.

Thanks to Coveralls.io and the use of Travis, even these tasks are completly automatized and the results are available online like in this example https://coveralls.io/builds/560853

The configuration is quite easy. We need to connect our Coveralls.io profile with GitHub, like we did for Travis-ci.org and then enable the repository. To trigger Coveralls after a successful Travis build, we need to have these lines at the end of our .travis.yml file

after_success:

  - coveralls

coveralls-console
Even Coveralls.io is completly free for opensource projects and offers a paid version for private repositories.

Heroku

I use Heroku to host and run my web application. Normally to deploy on Heroku you so something like this: git push heroku master

Adding these settings to the .travis.yaml file, I can automatically deploy the application on Heroku, if the build was successful:


deploy:
provider: heroku
api_key:
secure: R4LFkVu1/io9wSb/FvVL6UEaKU7Y4vfen/gCDe0OnEwsH+VyOwcT5tyINAg05jWXhRhsgjYT9AuyB84uCuNZg+lO7HwV5Q4WnHo5IVcCrv0PUq/CbRPUS4C2kDD7zbA1ByCd224tcfBmUtu+DPzyouk23oJH+lUwa/FeUk0Yl+I=
app: workshopvenues
on:
repo: andreagrandi/workshopvenues
run:
- "python workshopvenues/manage.py syncdb"
- "python workshopvenues/manage.py migrate"

Not only the code is deployed, after deployment the South migrations are executed.

Conclusion

These two tools are saving me lot of time and are ensuring that the code I release for a project I'm working on (WorkshopVenues) is always tested when I push it on my repository.

Factoryboy: Creating data for unit tests in an easy way

Programmazione, Python No Comments »

I recently prepared a presentation about Factoryboy, a Python library that automates lot of the work when a developer needs to create some data for unit testing.

I've been using this library since a couple of months, both in the company where I work and on a personal open source project I'm working on. I will give a presentation about this library in an internal workshop in my company and I'm available to give it in any Python/Django related event around London, if anyone is interested.

The slides are already available:

How to fix encfs installation on OSX 10.9 (Mavericks) and brew

HowTo, OSX, Sicurezza 1 Comment »

After upgrading from OSX 10.8.x to 10.9 (Mavericks), encfs recipe is broken. First of all you have to fix a problem with a library header:

sudo ln -s /usr/include/sys/_endian.h /usr/include/sys/endian.h

then you can install encfs using this remote brew recipe:

brew reinstall https://gist.github.com/ghibble/7297078/raw/cae1ff000a5e1cfc670f5b7a611279ed494b63af/encfs.rb

It's also possible that you have to fix fuse4x installation before being able to use encfs (I had to do it):

sudo /bin/cp -rfX /usr/local/Cellar/fuse4x-kext/0.9.2/Library/Extensions/fuse4x.kext /Library/Extensions
sudo chmod +s /Library/Extensions/fuse4x.kext/Support/load_fuse4x

That's it! Please note that this is just a workaround (thanks to Giovanni Bajo for suggesting me the symlink fix). Please also note that this recipe uses fuse4x library and not the most updated osxfuse (but it works, anyway). Some other users reported me that there is a fix for the original brew recipe, and this one uses osxfuse. You can find it here https://gist.github.com/defunctzombie/7324625 but I haven't tested it yet.

Update: to fully integrate encfs with OSX, I also suggest to follow this nice guide http://www.maketecheasier.com/install-encfs-mac/

How to make subwoofer work in Ubuntu

HowTo, Linux, Ubuntu (EN) 1 Comment »

Using the same computer with Windows 8 and Ubuntu I noticed that the sound was worse in Ubuntu and I discovered why soon: subwoofer doesn't work out of the box!

How to fix it

The fix is quite easy to apply (but it was not easy to find the right one!). First of all edit /etc/pulse/default.pa and add this line at the end:

load-module module-combine channels=6 channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe

then edit /etc/pulse/daemon.conf, modify the line "enable-lfe-remixing: no" to "enable-lfe-remixing: yes", then uncomment it (remove the semicolon in front of it). Reboot your PC and enjoy the subwoofer!

References

How to fix a WordPress website hacked by “zend_framework” malware

HowTo, Linux, Sicurezza, Ubuntu (EN), WordPress 1 Comment »

I admit. This website, like thousands of others, has been hacked! I still have to identify the precise source of the attack, but I've found out that is very common. I was able to discover about the attack just because the dashboard of WordPress stopped working. I decided to investigate and I found this strind on top of every .php file http://pastebin.com/k0iQymRy

Just googling I discovered that I was not alone http://stackoverflow.com/questions/16963818/server-hacked-on-wordpress-files

How to fix this?

The best solution would be to restore the files with a valid backup, but sometimes this is not possible. Here comes an handy bash solution (note: you need to be able to access your hosting with a SSH shell to execute this command): http://pastebin.com/V3nFwwtZ

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in

Switch to our mobile site