File: test_sp.py

package info (click to toggle)
software-properties 0.96.20.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,364 kB
  • ctags: 683
  • sloc: python: 5,125; makefile: 19; sh: 18
file content (45 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python
# -*- coding: utf-8 -*-

import logging
from mock import patch
import os
import shutil
import sys
import tempfile
import unittest

sys.path.insert(0, "../")
from softwareproperties.SoftwareProperties import (
    SoftwareProperties)

class SoftwarePropertiesTestCase(unittest.TestCase):

    def setUp(self):
        self.temp_dir = tempfile.mkdtemp()
        self.sp = SoftwareProperties()
        self.mock_key = os.path.join(self.temp_dir, u"määäp.asc")
        with open(self.mock_key, "wb") as fp:
            fp.write(u"bäää".encode("utf-8"))

    def tearDown(self):
        shutil.rmtree(self.temp_dir)

    def test_add_key_str(self):
        with patch.object(self.sp, "apt_key") as mock_apt_key:
            self.sp.add_key(self.mock_key)
        self.assertTrue(mock_apt_key.add.called)

    def test_add_key_bytes(self):
        with patch.object(self.sp, "apt_key") as mock_apt_key:
            mock_name_as_bytes = self.mock_key.encode("utf-8")
            self.sp.add_key(mock_name_as_bytes)
        self.assertTrue(mock_apt_key.add.called)


if __name__ == "__main__":
    if "-d" in sys.argv:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)
    unittest.main()