예제 #1
0
    def test_download_file(self):
        content = 'Some content'
        fake_src = StringIO(content)
        fake_file = FakeFile('')
        file_mock = mock.MagicMock(return_value=fake_file)

        src_path = 'http://0.0.0.0:80/tmp/file'
        dst_path = '/tmp/file'

        with mock.patch('urllib2.urlopen', return_value=fake_src) as url_fake:
            with mock.patch('__builtin__.open', file_mock):
                download_file(src_path, dst_path)

        file_mock.assert_called_once_with(dst_path, 'wb')
        url_fake.assert_called_once_with(src_path)
        self.assertEqual(fake_file.getvalue(), content)
예제 #2
0
 def run(self):
     """Run downloading and checkings
     """
     self._check_free_space()
     download_file(self.src_path, self.dst_path)
     self._check_checksum()