~mvo/software-center/recagent-no-need-for-auth

« back to all changes in this revision

Viewing changes to tests/test_config.py

* lp:~mvo/software-center/improve-test-for-config:
  - additional unit tests for the config handling code 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
3
import os
4
 
import tempfile
 
4
from tempfile import NamedTemporaryFile
5
5
import unittest
6
6
 
7
7
from tests.utils import setup_test_env
8
8
setup_test_env()
9
 
from softwarecenter.config import get_config
 
9
from softwarecenter.config import (
 
10
    SoftwareCenterConfig, 
 
11
    get_config,
 
12
    )
10
13
 
11
14
 
12
15
class ConfigTestCase(unittest.TestCase):
13
16
    """ tests the config class """
14
17
 
15
 
    @classmethod
16
 
    def setUpClass(cls):
17
 
        # config is global so its fine to use a classmethod here
18
 
        cls.tempfile = tempfile.NamedTemporaryFile(prefix="sc-test-")
19
 
        cls.config = get_config(cls.tempfile.name)
 
18
    def setUp(self):
 
19
        self.tempfile = NamedTemporaryFile(prefix="sc-test-")
 
20
        self.config = SoftwareCenterConfig(self.tempfile.name)
20
21
 
21
22
    def test_properties_simple_bool(self):
22
23
        """ test a bool property """
26
27
            self.assertEqual(
27
28
                self.config.getboolean("general", "add_to_launcher"), value)
28
29
 
 
30
    def test_properties_default_bool(self):
 
31
        """ test default values for properties """
 
32
        self.assertTrue(self.config.add_to_unity_launcher)
 
33
        self.assertEqual(self.config.app_window_size, "-1, -1")
 
34
 
29
35
    def test_property_simple_string(self):
30
36
        """ test a string property """
31
37
        for value in [ "", "10, 10"]:
47
53
 
48
54
    def test_raise_on_unknown_property(self):
49
55
        """ test that we get a error for unknown properties """
50
 
        self.config = get_config()
51
56
        with self.assertRaises(AttributeError):
52
57
            self.config.unknown_propertiy
53
58
 
 
59
    def test_config_singleton(self):
 
60
        config1 = get_config()
 
61
        config2 = get_config()
 
62
        self.assertEqual(config1, config2)
54
63
 
55
64
if __name__ == "__main__":
56
65
    unittest.main()