~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise-201112142106

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_config.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-08-09 12:47:56 UTC
  • mfrom: (1.1.53 upstream)
  • Revision ID: james.westby@ubuntu.com-20110809124756-7nzilp3oix0a1yl9
Tags: 1.7.1-0ubuntu1
* New upstream release.
* debian/*:
  - Removed obsolete pycompat file
  - Removed ubuntuone-client-gnome deps and binary packaging, as it was
    moved out to separate project upstream.
  - Updated copyright to remove obsolete file reference
* debian/patches:
  - Removed patches which have been included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import logging
21
21
import os
 
22
 
22
23
from ConfigParser import ConfigParser
23
 
from xdg.BaseDirectory import (
 
24
from twisted.internet import defer
 
25
 
 
26
from ubuntuone.platform.xdg_base_directory import (
24
27
    xdg_data_home,
25
28
    xdg_cache_home,
26
29
)
27
 
 
28
30
from ubuntuone.syncdaemon import config
29
31
from contrib.testing.testcase import (
30
32
    BaseTwistedTestCase,
36
38
class TestConfigBasic(BaseTwistedTestCase):
37
39
    """Basic _Config object tests"""
38
40
 
 
41
    @defer.inlineCallbacks
39
42
    def setUp(self):
40
 
        BaseTwistedTestCase.setUp(self)
 
43
        yield super(TestConfigBasic, self).setUp()
41
44
        self.test_root = self.mktemp()
42
45
 
43
46
    def assertThrottlingSection(self, expected, current, on, read, write):
468
471
 
469
472
 
470
473
class ConfigglueParsersTests(BaseTwistedTestCase):
471
 
    """Tests for our custom configglue parsers"""
 
474
    """Tests for our custom configglue parsers."""
472
475
 
473
476
    def test_throttling_limit_parser(self):
474
477
        """Test throttling_limit_parser"""
494
497
        self.assertEqual(logging.DEBUG, parser(bad_value))
495
498
        self.assertEqual(logging.DEBUG, parser(invalid_value))
496
499
 
497
 
    def test_home_dir_parser(self):
498
 
        """Test home_dir_parser"""
499
 
        good_value = '~/hola'
500
 
        bad_value = 'hola'
501
 
        invalid_value = None
502
 
        parser = config.home_dir_parser
503
 
        with environ('HOME', '/home/fake'):
504
 
            self.assertEquals('/home/fake/hola', parser(good_value))
505
 
        self.assertEquals('hola', parser(bad_value))
506
 
        self.assertRaises(AttributeError, parser, invalid_value)
507
 
 
508
 
    def test_xdg_cache_dir_parser(self):
509
 
        """Test xdg_cache_dir_parser"""
510
 
        good_value = 'hola'
511
 
        bad_value = '/hola'
512
 
        invalid_value = None
513
 
        parser = config.xdg_cache_dir_parser
514
 
        self.assertEquals(os.path.join(xdg_cache_home, 'hola'),
515
 
                          parser(good_value))
516
 
        self.assertEquals('/hola', parser(bad_value))
517
 
        self.assertRaises(AttributeError, parser, invalid_value)
518
 
 
519
 
    def test_xdg_data_dir_parser(self):
520
 
        """Test xdg_data_dir_parser"""
521
 
        good_value = 'hola'
522
 
        bad_value = '/hola'
523
 
        invalid_value = None
524
 
        parser = config.xdg_data_dir_parser
525
 
        self.assertEquals(os.path.join(xdg_data_home, 'hola'),
526
 
                          parser(good_value))
527
 
        self.assertEquals('/hola', parser(bad_value))
528
 
        self.assertRaises(AttributeError, parser, invalid_value)
 
500
 
 
501
class XdgHomeParsersTests(BaseTwistedTestCase):
 
502
    """Tests for our custom xdg parsers."""
 
503
 
 
504
    good_value = '~/hola/mundo'
 
505
    name = 'home'
 
506
    xdg_dir = os.path.join('', 'home', 'fake')
 
507
 
 
508
    @defer.inlineCallbacks
 
509
    def setUp(self):
 
510
        yield super(XdgHomeParsersTests, self).setUp()
 
511
        self.parser = getattr(config, '%s_dir_parser' % self.name)
 
512
 
 
513
    def test_good_value(self):
 
514
        """Test the parser using a good value."""
 
515
        homedir = os.path.join('', 'home', 'fake')
 
516
        with environ('HOME', homedir):
 
517
            expected = os.path.join(self.xdg_dir, 'hola', 'mundo')
 
518
            actual = self.parser(self.good_value)
 
519
            self.assertEqual(expected, actual)
 
520
            self.assertIsInstance(actual, str)
 
521
            self.assertNotIsInstance(actual, unicode)
 
522
 
 
523
    def test_bad_value(self):
 
524
        """Test the parser using a bad value."""
 
525
        bad_value = '/hola'
 
526
        self.assertEqual(config.path_from_unix(bad_value),
 
527
                         self.parser(bad_value))
 
528
 
 
529
    def test_invalid_value(self):
 
530
        """Test the parser using an invalid value."""
 
531
        invalid_value = None
 
532
        self.assertRaises(AttributeError, self.parser, invalid_value)
 
533
 
 
534
 
 
535
class XdgCacheParsersTests(XdgHomeParsersTests):
 
536
    """Tests for our custom xdg parsers."""
 
537
 
 
538
    good_value = 'hola/mundo'
 
539
    name = 'xdg_cache'
 
540
    xdg_dir = xdg_cache_home
 
541
 
 
542
 
 
543
class XdgDataParsersTests(XdgCacheParsersTests):
 
544
    """Tests for our custom xdg parsers."""
 
545
 
 
546
    good_value = 'hola/mundo'
 
547
    name = 'xdg_data'
 
548
    xdg_dir = xdg_data_home
529
549
 
530
550
 
531
551
class SyncDaemonConfigParserTests(BaseTwistedTestCase):
532
552
    """Tests for SyncDaemonConfigParser"""
533
553
 
 
554
    @defer.inlineCallbacks
534
555
    def setUp(self):
535
 
        BaseTwistedTestCase.setUp(self)
 
556
        yield super(SyncDaemonConfigParserTests, self).setUp()
536
557
        self.test_root = self.mktemp()
537
558
        self.default_config = os.path.join(os.environ['ROOTDIR'], 'data',
538
559
                                           'syncdaemon.conf')