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

« back to all changes in this revision

Viewing changes to contrib/testing/testcase.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2010-06-08 17:31:18 UTC
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100608173118-o8s897ll11rtne99
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import logging
24
24
import os
25
25
import shutil
 
26
import itertools
26
27
 
27
28
from ubuntuone.oauthdesktop.main import Login, LoginProcessor
28
29
from ubuntuone.syncdaemon import (
451
452
        """ Just add the record to self.records. """
452
453
        self.records.append(record)
453
454
 
 
455
    def check(self, level, *msgs):
 
456
        """Verifies that the msgs are logged in the specified level."""
 
457
        for rec in self.records:
 
458
            if rec.levelno == level and all(m in rec.message for m in msgs):
 
459
                return True
 
460
        return False
 
461
 
 
462
    def check_debug(self, *msgs):
 
463
        """Shortcut for checking in DEBUG."""
 
464
        return self.check(logging.DEBUG, *msgs)
 
465
 
 
466
    def check_info(self, *msgs):
 
467
        """Shortcut for checking in INFO."""
 
468
        return self.check(logging.INFO, *msgs)
 
469
 
 
470
    def check_warning(self, *msgs):
 
471
        """Shortcut for checking in WARNING."""
 
472
        return self.check(logging.WARNING, *msgs)
 
473
 
 
474
    def check_error(self, *msgs):
 
475
        """Shortcut for checking in ERROR."""
 
476
        return self.check(logging.ERROR, *msgs)
 
477
 
454
478
 
455
479
class FakeNetworkManager(DBusExposedObject):
456
480
    """ A fake NetworkManager that only emits StatusChanged signal. """
508
532
 
509
533
    def __init__(self, root_path):
510
534
        """ Creates the instance"""
511
 
        self.root = volume_manager.Share(path=root_path, access_level='Modify')
 
535
        self.root = volume_manager.Root(node_id="root_node_id", path=root_path)
512
536
        self.shares = {'':self.root}
513
537
        self.udfs = {}
514
538
        self.log = logging.getLogger('ubuntuone.SyncDaemon.VM-test')
540
564
        except KeyError:
541
565
            return self.udfs[id]
542
566
 
543
 
    def get_volumes(self, access_level='Modify', all_volumes=False):
 
567
    def get_volumes(self, all_volumes=False):
544
568
        """Simple get_volumes for FakeVolumeManager."""
545
 
        for share in self.shares.values():
546
 
            if all_volumes or share.access_level == access_level:
547
 
                yield share
548
 
        for udf in self.udfs.values():
549
 
            if all_volumes or udf.subscribed:
550
 
                yield udf
 
569
        volumes = itertools.chain(self.shares.values(), self.udfs.values())
 
570
        for volume in volumes:
 
571
            if all_volumes or volume.active:
 
572
                yield volume
551
573
 
552
574
    def unsubscribe_udf(self, udf_id):
553
575
        """Mark the UDF with udf_id as unsubscribed."""