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
|
# -* encoding: utf-8 *-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from typing import Any
from unittest.case import TestCase
import requests_mock
from aptly_api.base import AptlyAPIException
from aptly_api.parts.misc import MiscAPISection
@requests_mock.Mocker(kw='rmock')
class MiscAPISectionTests(TestCase):
def __init__(self, *args: Any) -> None:
super().__init__(*args)
self.mapi = MiscAPISection("http://test/")
def test_version(self, *, rmock: requests_mock.Mocker) -> None:
rmock.get("http://test/api/version", text='{"Version":"1.0.1"}')
self.assertEqual(self.mapi.version(), "1.0.1")
def test_graph(self, *, rmock: requests_mock.Mocker) -> None:
with self.assertRaises(NotImplementedError):
self.mapi.graph("png")
def test_version_error(self, *, rmock: requests_mock.Mocker) -> None:
rmock.get("http://test/api/version", text='{"droenk": "blah"}')
with self.assertRaises(AptlyAPIException):
self.mapi.version()
|