示例#1
0
    def test_save(self, isdir_mock, isfile_mock, access_mock):
        obj = repos.BaseYumRepo("foo", "bar", "url", True, False)

        isdir_mock.return_value = True
        isfile_mock.retun_value = False
        access_mock.return_value = True
        with mock.patch("builtins.open", mock.mock_open()) as file_mock:
            obj.save()
            calls = [
                mock.call("/etc/yum.repos.d/foo.repo", "w"),
                mock.call().__enter__(),
                mock.call().write(str(obj)),
                mock.call().__exit__(None, None, None),
            ]
            self.assertEqual(file_mock.mock_calls, calls)

        isdir_mock.return_value = False
        isfile_mock.retun_value = False
        access_mock.return_value = True
        with mock.patch("builtins.open", mock.mock_open()) as file_mock:
            self.assertRaises(FileNotFoundError, obj.save)

        isdir_mock.return_value = True
        isfile_mock.retun_value = False
        access_mock.return_value = False
        with mock.patch("builtins.open", mock.mock_open()) as file_mock:
            self.assertRaises(PermissionError, obj.save)

        isdir_mock.return_value = True
        isfile_mock.retun_value = True
        access_mock.side_effect = [True, False]
        with mock.patch("builtins.open", mock.mock_open()) as file_mock:
            self.assertRaises(PermissionError, obj.save)
示例#2
0
 def test_base_to_string(self):
     obj = repos.BaseYumRepo("foo", "bar", "url", True, False, "mirror",
                             "meta", "gpg")
     expected = "\n".join([
         "[foo]",
         "name=bar",
         "baseurl=url",
         "mirrorlist=mirror",
         "metalink=meta",
         "enabled=1",
         "gpgcheck=0",
         "gpgkey=gpg",
         "",
     ])
     self.assertEqual(str(obj), expected)
示例#3
0
    def test_base(self):
        obj = repos.BaseYumRepo("foo", "bar", "url", True, False)
        self.assertEqual(obj.name, "foo")
        self.assertEqual(obj.description, "bar")
        self.assertEqual(obj.baseurl, "url")
        self.assertTrue(obj.enabled)
        self.assertEqual(obj._enabled, 1)
        self.assertFalse(obj.gpgcheck)
        self.assertFalse(obj._gpgcheck, 0)
        self.assertEqual(obj.mirrorlist, None)
        self.assertEqual(obj.metalink, None)
        self.assertEqual(obj.gpgkey, None)

        obj.enabled = False
        self.assertFalse(obj.enabled)
        self.assertEqual(obj._enabled, 0)

        obj.gpgcheck = True
        self.assertTrue(obj.gpgcheck)
        self.assertEqual(obj._gpgcheck, 1)