338
339
mdobj = self.fsm.get_by_mdid(mdid)
339
340
self.sync._handle_SV_HASH_NEW(mdobj.share_id, mdobj.node_id, '')
340
341
self.assertTrue(self.called)
342
343
def test_SV_HASH_NEW_with_file_uploadinterrupted_coverage(self):
343
344
"""A SV_HASH_NEW is received after upload interrupted."""
344
345
self.called = False
346
347
# create a file and put it in local, without server_hash, as
347
348
# if the upload was cut in the middle after the make file
348
349
somepath = os.path.join(self.root, 'somepath')
698
698
self.assertEqual(mdobj.size, 'size')
699
699
self.assertEqual(mdobj.stat, 'stt')
701
@contextlib.contextmanager
702
def _test_putcontent_upload_id(self, with_upload_id=False):
703
"""Generic code to setup and check upload_id in put_content."""
705
self.fsm.set_by_mdid(self.mdid, upload_id='hola')
707
self.fsm.set_by_mdid(self.mdid, upload_id=None)
709
def my_upload(*args, **kwargs):
710
"""AQ.upload method that only collect the arguments."""
711
called.append((args, kwargs))
712
self.patch(self.aq, 'upload', my_upload)
714
self.assertEqual(len(called), 1)
715
kwargs = called[0][1]
717
self.assertEqual(kwargs['upload_id'], 'hola')
719
self.assertEqual(kwargs['upload_id'], None)
721
def test_put_file_use_upload_id(self):
722
"""Test that sync calls put_file with the correct args."""
723
with self._test_putcontent_upload_id():
724
self.ssmr.put_file('HQ_HASH_NEW', None, 'hash',
725
'crc', 'size', 'stt')
726
with self._test_putcontent_upload_id(with_upload_id=False):
727
self.ssmr.put_file('HQ_HASH_NEW', None, 'hash',
728
'crc', 'size', 'stt')
730
def test_reput_file_use_upload_id(self):
731
"""Test that sync calls reput_file with the correct args."""
732
with self._test_putcontent_upload_id():
733
self.ssmr.reput_file('HQ_HASH_NEW', None, 'hash',
734
'crc', 'size', 'stt')
735
with self._test_putcontent_upload_id(with_upload_id=False):
736
self.ssmr.reput_file('HQ_HASH_NEW', None, 'hash',
737
'crc', 'size', 'stt')
739
def test_reput_file_from_local_use_upload_id(self):
740
"""Test that sync calls reput_file_from_local with the correct args."""
741
self.fsm.set_by_mdid(self.mdid, local_hash='somehash', crc32='crc32',
742
stat='stat', size='size')
743
# send the event with no content and check
744
with self._test_putcontent_upload_id():
745
self.ssmr.reput_file_from_local("SV_HASH_NEW", None, '')
746
with self._test_putcontent_upload_id(with_upload_id=False):
747
self.ssmr.reput_file_from_local("SV_HASH_NEW", None, '')
701
750
def test_commit_file_without_partial(self):
702
751
"""The .partial is lost when commiting the file."""
703
752
# create the partial correctly, and break it!