Introduction to patching in Python
If you want to use it in a version earlier than python3.3, you need yo install it:
sudo pip install mock
Simple example
Code to test:
import time def do_something(): if time.sleep(100): print 'ok' else: print 'ko'
Actual test:
from mock import patch @patch('time.sleep') def test_do_something1(mock_sleep): mock_sleep.return_value = True do_something() @patch('time.sleep') def test_do_something2(mock_sleep): mock_sleep.return_value = False do_something()
Results:
>>> test_do_something1() ok >>> test_do_something2() ko
Source:
Python tips
Ignore escaping characters such as "\"
>>> print r""" This is '\myfolder\'""" >>> This is '\myfolder\'
For more see:
http://sahandsaba.com/thirty-python-language-features-and-tricks-you-may-not-know.html#id1
Put an emoji icon in your Github commit message
Example:
git commit -m 'Fixed whatever, time for :beers:'
See list of emoji here: http://scotch.io/bar-talk/emoji-icons-in-github-commit-messages
Port in use
Logs
The configuration and especially right permissions will be done in /etc/rsyslog.conf
Bitmask is going to be used so use this doc http://www.cyberciti.biz/faq/unix-linux-bsd-chmod-numeric-permissions-notation-command/
It will be taken into account for the new log files only when we reload rsylog with this commend:
/etc/init.d/rsyslog reload
The old files are still on the old configuration. So, you need to change the right access directly for them with chown and chmod.
Example for vagrant user:
root@openerp-development:/var/log/openerp# chown vagrant:vagrant /var/log/openerp/ -R root@openerp-development:/var/log/openerp# chmod a+r /var/log/openerp/ -R
Source: http://www.rsyslog.com/
Screen monitoring
You can use this chrome plugin if you want to monitor different screen with a slideshow: https://chrome.google.com/webstore/detail/tabcarousel/ddldimidiliclngjipajmjjiakhbcohn?hl=en
For instance, if you want to have a view on your Kanban and on the state of the continuous integration for monitoring if the tests are passing.
Execute sql from file
Agile testing
The best book I ever read about testing and best practices in an Agile project is: Agile Testing: A Practical Guide for Testers and Agile Teams (Addison-Wesley Signature)
The main idea of Agility is constantly giving and receiving feedback in order to keep improving the process and the output of the project.
Copy records from postgresql to csv file
COPY(QUERY) TO 'FILENAME' WITH CSV HEADER;
For the other way around see: Copy records from csv file to postgres DB