[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fab-user] unit testing
From: |
andrea crotti |
Subject: |
[Fab-user] unit testing |
Date: |
Wed, 30 Jan 2013 12:30:42 +0000 |
I'm trying to unit test my fabfile, what I would like to do is the following:
- set some conditions
- get a trail of commands that would be run
- check if that is correct
Now the problem is that for any command it still wants to connect, so
even if I mock out run, it still complains about the host missing for
some reason.
And then I have to find a way to record the sequence of commands
instead of simply printing them out, any ideas about that?
By the way, I was looking for documentation about unit testing and
fabric but didn't find anything useful, is noone doing it?
Test:
def fake_run(cmd):
return sys.stdout.write(cmd)
@patch('fabfile.env.hosts', new=['localhost'])
@patch('fabfile.WAZOKU_REPO', new='/tmp/wazoku')
@patch('fabfile.run', new=fake_run)
class TestNewDeploy(unittest.TestCase):
def test_first_run_works_file(self):
Function to test:
@parallel
def deploy_head_new_pull(branch='master'):
api_dir = "%s/company-api/api" % COMPANY_REPO
ve_dir = '%s/ve' % api_dir
if not files.exists(COMPANY_REPO):
run(CLONE.format(branch, COMPANY_REPO))
# create the symlink to make sure it points to the right place
run('ln -sf %s/company-api $HOME/api' % COMPANY_REPO)
run('virtualenv %s' % ve_dir)
else:
with cd(COMPANY_API):
run('git pull')
run('git clean -f')
with settings(user='company'):
with cd(COMPANY_REPO):
run('source %s/bin/activate && pip install -r
requirements.txt' % ve_dir)
run('cp production_settings.py settings.py')
restart_api()
- [Fab-user] unit testing,
andrea crotti <=