~sbaldassin/autopilot/fix_mir

« back to all changes in this revision

Viewing changes to autopilot/tests/unit/test_fixtures.py

  • Committer: Tarmac
  • Author(s): Christopher Lee, Ken VanDine
  • Date: 2015-07-23 10:08:23 UTC
  • mfrom: (565.1.6 depends_for_gsettings)
  • Revision ID: tarmac-20150723100823-t3dn12d0ypl0kvfd
Resolves dependencies that not everyone cares about. Using Gio API instead of gsettings binary. . Fixes: https://bugs.launchpad.net/bugs/1477233.

Approved by Iain Lane, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
 
21
21
from testtools import TestCase
22
 
from testtools.matchers import (
23
 
    Not,
24
 
    Raises,
25
 
)
26
 
from unittest.mock import patch
 
22
from testtools.matchers import raises
 
23
from unittest.mock import patch, Mock
27
24
import autopilot._fixtures as ap_fixtures
28
25
 
29
26
 
40
37
 
41
38
class GSettingsAccessTests(TestCase):
42
39
 
43
 
    def test_incorrect_schema_doesnt_raise_exception(self):
44
 
        self.assertThat(
45
 
            lambda: ap_fixtures.get_gsettings_value('foo', 'bar'),
46
 
            Not(Raises())
 
40
    def test_incorrect_schema_raises_exception(self):
 
41
        self.assertThat(
 
42
            lambda: ap_fixtures._gsetting_get_setting('com.foo.', 'baz'),
 
43
            raises(ValueError)
 
44
        )
 
45
 
 
46
    def test_incorrect_key_raises_exception(self):
 
47
        self.assertThat(
 
48
            lambda: ap_fixtures._gsetting_get_setting(
 
49
                'org.gnome.system.locale',
 
50
                'baz'
 
51
            ),
 
52
            raises(ValueError)
47
53
        )
48
54
 
49
55
    def test_get_value_returns_expected_value(self):
50
 
        with patch.object(ap_fixtures.subprocess, 'check_output') as check_out:
51
 
            check_out.return_value = 'buzz'
52
 
            self.assertEqual(
53
 
                ap_fixtures.get_gsettings_value('foo', 'bar'),
54
 
                'buzz'
55
 
            )
56
 
 
57
 
    def test_get_value_strips_newline(self):
58
 
        with patch.object(ap_fixtures.subprocess, 'check_output') as check_out:
59
 
            check_out.return_value = 'buzz\n'
60
 
            self.assertEqual(
61
 
                ap_fixtures.get_gsettings_value('foo', 'bar'),
62
 
                'buzz'
 
56
        with patch.object(ap_fixtures, '_gsetting_get_setting') as get_setting:
 
57
            setting = Mock()
 
58
            setting.get_boolean.return_value = True
 
59
            get_setting.return_value = setting
 
60
            self.assertEqual(
 
61
                ap_fixtures.get_bool_gsettings_value('foo', 'bar'),
 
62
                True
63
63
            )
64
64
 
65
65
 
66
66
class OSKAlwaysEnabledTests(TestCase):
67
67
 
68
 
    def test_sets_stayhidden_to_false(self):
69
 
        with patch.object(ap_fixtures, 'set_gsettings_value') as set_gsetting:
 
68
    @patch.object(ap_fixtures, '_gsetting_get_setting')
 
69
    def test_sets_stayhidden_to_False(self, gs):
 
70
        with patch.object(ap_fixtures, 'set_bool_gsettings_value') as set_gs:
70
71
            with ap_fixtures.OSKAlwaysEnabled():
71
 
                set_gsetting.assert_called_once_with(
 
72
                set_gs.assert_called_once_with(
72
73
                    'com.canonical.keyboard.maliit',
73
74
                    'stay-hidden',
74
 
                    'false'
 
75
                    False
75
76
                )
76
77
 
77
78
    def test_resets_value_to_original(self):
78
 
        with patch.object(ap_fixtures, 'set_gsettings_value') as set_gset:
79
 
            with patch.object(ap_fixtures, 'get_gsettings_value') as get_gset:
80
 
                get_gset.return_value = 'foo'
 
79
        with patch.object(ap_fixtures, 'set_bool_gsettings_value') as set_gs:
 
80
            with patch.object(ap_fixtures, 'get_bool_gsettings_value') as get_gs:  # NOQA
 
81
                get_gs.return_value = 'foo'
81
82
                with ap_fixtures.OSKAlwaysEnabled():
82
83
                    pass
83
 
                set_gset.assert_called_with(
 
84
                set_gs.assert_called_with(
84
85
                    'com.canonical.keyboard.maliit',
85
86
                    'stay-hidden',
86
87
                    'foo'