Beispiel #1
0
    def test_calculate_md5sum(self):
        open_mock = mock.MagicMock(return_value=FakeFile('fake file content'))
        file_path = '/tmp/file'

        with mock.patch('__builtin__.open', open_mock):
            self.assertEquals(calculate_md5sum(file_path),
                              '199df6f47108545693b5c9cb5344bf13')

        open_mock.assert_called_once_with(file_path, 'rb')
Beispiel #2
0
    def test_calculate_md5sum(self):
        open_mock = mock.MagicMock(return_value=FakeFile('fake file content'))
        file_path = '/tmp/file'

        with mock.patch('__builtin__.open', open_mock):
            self.assertEqual(
                calculate_md5sum(file_path),
                '199df6f47108545693b5c9cb5344bf13')

        open_mock.assert_called_once_with(file_path, 'rb')
Beispiel #3
0
    def _check_checksum(self):
        """Calculate checksum and compare it with `self.checksum`

        :raises: errors.WrongChecksum
        """
        calculated_checksum = calculate_md5sum(self.dst_path)
        if calculated_checksum != self.checksum:
            raise errors.WrongChecksum(
                u'File "{0}" has wrong checkum, actual '
                'checksum "{1}" expected checksum "{2}"'.format(
                    self.dst_path, calculated_checksum, self.checksum))