~asac/phablet-tools/remove-chmod666-uinput-hack

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (C) 2013 Canonical Ltd.
# Author: Sergio Schvezov <sergio.schvezov@canonical.com>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Unit tests for phabletutils.environment."""

from mock import patch
from phabletutils import ubuntuimage
from testtools import TestCase
from testtools.matchers import Equals
from testtools.matchers import HasLength


@patch('phabletutils.downloads.get_content')
class TestUbuntuImage(TestCase):

    def setUp(self):
        super(TestUbuntuImage, self).setUp()
        self.device = 'mako'
        with open('tests/index.json', 'r') as f:
            self.json_content = f.read()

    def testGetLatestIndex(self, get_content_mock):
        # given
        get_content_mock.return_value = self.json_content
        # when
        json_dict = ubuntuimage.get_json_from_index(self.device, 0)
        # then
        self.assertThat(json_dict['version'], Equals(20130808))
        self.assertThat(json_dict['description'], Equals('20130807'))
        self.assertThat(json_dict['type'], Equals('full'))
        self.assertThat(json_dict['files'], HasLength(3))

    def testGetPreviousIndex(self, get_content_mock):
        # given
        get_content_mock.return_value = self.json_content
        # when
        json_dict = ubuntuimage.get_json_from_index(self.device, -1)
        # then
        self.assertThat(json_dict['version'], Equals(20130807))
        self.assertThat(json_dict['description'], Equals('20130806.1'))
        self.assertThat(json_dict['type'], Equals('full'))
        self.assertThat(json_dict['files'], HasLength(3))