Well I suppose it's files.exists, and in fact adding the other mock works

def files_exists():

        m = Mock()

m.exists = lambda x: True

return m

@patch('fabfile.files', new=files_exists())
It would be nice to avoid mocking all the calls though..
And maybe another useful thing would be to make something that should run
on different servers run locally, I suppose I could simply do a
run -> local
translation, right?

On 30 Jan 2013 12:58, "Jasper van den Bosch" <[email protected]> wrote:

> Hi andrea,
>
> I regularly unit-test fabric code. If you are mocking out run() etc, and
> using the regular python executable, not fab, to start the tests, I don't
> see why it would try to connect. Can you post more code, i.e. as a Gist?
>
> Jasper
>
> On 30 January 2013 13:30, andrea crotti <[email protected]> wrote:
>
>> 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 mailing list
>> [email protected]
>> https://lists.nongnu.org/mailman/listinfo/fab-user
>>
>
>
>
> --
> Jasper van den Bosch
> ilogue.com/jasper
>
> I'd love to see your attachment, but please use OpenDocument, not a
> proprietary format like docx. It's an international standard, endorsed by
> the EU, and implemented in many office suites, such as LibreOffice, and
> commercial products from Oracle, Sun, IBM and Microsoft (from 2007).
>
_______________________________________________
Fab-user mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to