~ubuntu-branches/ubuntu/oneiric/ubuntuone-client/oneiric

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_sync.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-23 18:34:09 UTC
  • mfrom: (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110223183409-535o7yo165wbjmca
Tags: 1.5.5-0ubuntu1
* New upstream release.
  - Subscribing to a RO share will not download content (LP: #712528)
  - Can't synchronize "~/Ubuntu One Music" (LP: #714976)
  - Syncdaemon needs to show progress in Unity launcher (LP: #702116)
  - Notifications say "your cloud" (LP: #715887)
  - No longer requires python-libproxy
  - Recommend unity and indicator libs by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from __future__ import with_statement
22
22
 
 
23
import contextlib
23
24
import copy
24
25
from inspect import getmembers, getargspec, ismethod
25
26
import logging
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)
341
 
        
 
342
 
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
345
 
        
 
346
 
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')
353
354
        # send the event with no content and check
354
355
        mdobj = self.fsm.get_by_mdid(mdid)
355
356
        self.sync._handle_SV_HASH_NEW(mdobj.share_id, mdobj.node_id, '')
356
 
        
 
357
 
357
358
    def test_AQ_FILE_NEW_OK_with_md_in_none(self):
358
359
        """Created the file, and MD says it's in NONE."""
359
360
        # fake method
643
644
        self.handler.setLevel(logging.DEBUG)
644
645
        self.ssmr.log.addHandler(self.handler)
645
646
 
646
 
 
647
647
    def tearDown(self):
648
648
        """Clean up."""
649
649
        self.ssmr.log.removeHandler(self.handler)
698
698
        self.assertEqual(mdobj.size, 'size')
699
699
        self.assertEqual(mdobj.stat, 'stt')
700
700
 
 
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."""
 
704
        if with_upload_id:
 
705
            self.fsm.set_by_mdid(self.mdid, upload_id='hola')
 
706
        else:
 
707
            self.fsm.set_by_mdid(self.mdid, upload_id=None)
 
708
        called = []
 
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)
 
713
        yield
 
714
        self.assertEqual(len(called), 1)
 
715
        kwargs = called[0][1]
 
716
        if with_upload_id:
 
717
            self.assertEqual(kwargs['upload_id'], 'hola')
 
718
        else:
 
719
            self.assertEqual(kwargs['upload_id'], None)
 
720
 
 
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')
 
729
 
 
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')
 
738
 
 
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, '')
 
748
 
 
749
 
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!