Skip to content

Instantly share code, notes, and snippets.

@hassek
hassek / Testing.md
Created March 14, 2018 16:50
Testing

Automated testing

Fixtures vs Factories

  • Anything that may be modified is not a good choice for fixtures but for factories instead
  • Fixtures hide the testing logic, don't use it for building use cases, instead use it for easing the testing process.
  • Fixtures still has some use cases to ease big data representations and objects that should never change (emails, user metrics, etc).

Saving vs not saving in the DB

I like to save everything on the DB until it becomes a problem, this avoids a

python << endpython
def run_current_test(level='test', on_terminal=False):
import vim
command = "./manage.py test %"
cb = vim.current.buffer
cw = vim.current.window
original_position = vim.current.window.cursor
set nobackup
set nowritebackup
"make the yank use the system clipboard
"set clipboard=unnamed
set tabstop=2 softtabstop=2 shiftwidth=2 textwidth=0
au BufRead,BufNewFile *.html set filetype=htmldjango
set tags+=./tags;$HOME
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/Cellar/ruby/1.9.3-p194/bin:/usr/local/share/npm/bin:$PATH
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
export PYTHONPATH=${PYTHONPATH}:$HOME/gsutil/boto:$HOME/gsutil:/usr/local/Cellar/xapian/1.2.7/bin:/usr/local/Cellar/readline/6.2.2/:
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/Cellar/ruby/1.9.3-p194/bin:/usr/local/share/npm/bin:$PATH
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/Cellar/python26/2.6.7/bin:/usr/local/Cellar/python/2.7.3/bin:/usr/local/share/python:$PATH
export PYTHONPATH=${PYTHONPATH}:$HOME/gsutil/boto:$HOME/gsutil:/usr/local/Cellar/xapian/1.2.7/bin:/usr/local/Cellar/readline/6.2.2/:
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
@hassek
hassek / gist:4080169
Created November 15, 2012 18:05
Get rabbit enqueued tasks and if rabbit is up
def get_rabbit_status():
try:
conn = BrokerConnection(
userid=settings.BROKER_USER,
password=settings.BROKER_PASSWORD,
hostname=settings.BROKER_HOST,
port=settings.BROKER_PORT,
virtual_host=settings.BROKER_VHOST
)
conn.connect()
"""
WSGI config for fitvaina project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
@hassek
hassek / nginx.conf
Created July 18, 2012 15:30
nginx configuration
#user nobody;
worker_processes 1;
error_log /var/log/nginx/error.log;
#access_log /var/log/nginx/access.log;
pid /var/run/nginx.pid;
events {
worker_connections 300;
#To be able to use this, please do a symbolic link into project root:
#cd yourproject
#ln -s environments/my_own_fabfile.py fabfile.py
from fabric.api import env, local, run, cd, sudo
from fabric.decorators import hosts
env.project_root = '~/WebSites/PROJECT'
#from fabric.contrib import django
env.user = "USER"
@hassek
hassek / hook.sh
Created June 6, 2012 16:01 — forked from anonymous/hook.sh
#!/bin/sh
if test "$(git diff --name-only HEAD@{1} | ack '500|404|home.html|static-content')"
then
echo "running ./manage.py generatemedia to update files"
python myproject/manage.py generatemedia --nodebug
git add -A myproject/_generated_media/*
git add -A static-content/*
git commit -m "updating media (automatic update by git merge hook)"
fi