Coverage for tests/test_pipproxy.py: 100%
26 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 18:52 -0500
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 18:52 -0500
1"""Unit tests for Pip Proxy"""
2import os
3import sys
4import unittest
5import tempfile
6from unittest.mock import patch
8from urllib3._collections import HTTPHeaderDict
10from mocks import MockedLogger, MockedPoolManager
12sys.path.insert(0, os.path.abspath(
13 os.path.join(os.path.dirname(__file__), "../creepo")))
14from creepo.pipproxy import PipProxy # pylint: disable=wrong-import-position
17class TestPipProxy(unittest.TestCase):
18 """Unit tests for pipproxy"""
20 def test_pip(self):
21 """Test pip proxy"""
23 def start_ok_response(status, headers): # pylint: disable=unused-argument
24 self.assertEqual(status, '200 OK')
25 content = 'text'
26 request = {
27 'REQUEST_URI': '/m2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom',
28 'log': []
29 }
31 config = {
32 'log': [],
33 }
35 config['logger'] = MockedLogger(request['log'])
37 with patch('urllib3.PoolManager') as mock_poolmanager:
39 with tempfile.TemporaryDirectory() as tmpdirname:
40 with unittest.mock.patch.dict('os.environ', {'HOME': tmpdirname}):
42 mock_poolmanager.return_value = MockedPoolManager(
43 status_code=200, response_headers=HTTPHeaderDict(), content=content)
45 proxy = PipProxy(config)
47 result = list(proxy.proxy(request, start_ok_response))
48 print(
49 f" Actual type: {type(result)}: value: {result}")
50 print(
51 f"Leave this in place to capture MockedLogger output\n{request}")
53 self.assertEqual(
54 content, "".join(result), "Expected the mocked response")