Skip to content

Commit

Permalink
Test cov (#721)
Browse files Browse the repository at this point in the history
* nocover for abstract classes

* Add event manager test

* Assert call args

* Sponsored by `Jaxl Innovations Private Limited`
  • Loading branch information
abhinavsingh authored Nov 10, 2021
1 parent df7f1c8 commit e38f1a8
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 16 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
[![Docker Pulls](https://img.shields.io/docker/pulls/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://hub.docker.com/r/abhinavsingh/proxy.py)
[![No Dependencies](https://img.shields.io/static/v1?label=dependencies&message=0&style=for-the-badge&color=darkgreen)](https://github.com/abhinavsingh/proxy.py)
[![Gitter](https://img.shields.io/gitter/room/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://gitter.im/proxy-py/community)
[![License](https://img.shields.io/github/license/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://opensource.org/licenses/BSD-3-Clause)
[![License](https://img.shields.io/github/license/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://github.com/abhinavsingh/proxy.py/blob/develop/LICENSE)

[![Tested With MacOS, Ubuntu, Windows, Android, Android Emulator, iOS, iOS Simulator](https://img.shields.io/static/v1?label=tested%20with&message=mac%20OS%20%F0%9F%92%BB%20%7C%20Ubuntu%20%F0%9F%96%A5%20%7C%20Windows%20%F0%9F%92%BB&color=darkgreen&style=for-the-badge)](https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/)
[![Android, Android Emulator](https://img.shields.io/static/v1?label=tested%20with&message=Android%20%F0%9F%93%B1%20%7C%20Android%20Emulator%20%F0%9F%93%B1&color=darkgreen&style=for-the-badge)](https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/)
[![iOS, iOS Simulator](https://img.shields.io/static/v1?label=tested%20with&message=iOS%20%F0%9F%93%B1%20%7C%20iOS%20Simulator%20%F0%9F%93%B1&color=darkgreen&style=for-the-badge)](https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/)

<!--
[![Maintenance](https://img.shields.io/static/v1?label=maintained%3F&message=yes&color=darkgreen)](https://github.com/abhinavsingh/proxy.py/graphs/commit-activity)
[![Ask Me Anything](https://img.shields.io/static/v1?label=need%20help%3F&message=ask&color=darkgreen)](https://twitter.com/imoracle)
[![Contributions Welcome](https://img.shields.io/static/v1?label=contributions&message=welcome%20%F0%9F%91%8D&color=darkgreen)](https://github.com/abhinavsingh/proxy.py/issues)
-->

[![lib](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-library.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-library.yml)
[![docker](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-docker.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-docker.yml)
[![dashboard](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-dashboard.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-dashboard.yml)
[![brew](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-brew.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-brew.yml)
[![CodeQL](https://github.com/abhinavsingh/proxy.py/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/codeql-analysis.yml)

[![Contributions Welcome](https://img.shields.io/static/v1?label=Contributions&message=Welcome%20%F0%9F%91%8D&color=darkgreen)](https://github.com/abhinavsingh/proxy.py/issues)
[![Need Help](https://img.shields.io/static/v1?label=Need%20Help%3F&message=Ask&color=darkgreen)](https://twitter.com/imoracle)
[![Sponsored by Jaxl Innovations Private Limited](https://img.shields.io/static/v1?label=Sponsored%20By&message=Jaxl%20Innovations%20Private%20Limited&color=darkgreen)](https://github.com/jaxl-innovations-private-limited)

[![pypi version](https://img.shields.io/pypi/v/proxy.py)](https://pypi.org/project/proxy.py/)
[![Python 3.x](https://img.shields.io/static/v1?label=Python&message=3.6%20%7C%203.7%20%7C%203.8%20%7C%203.9%20%7C%203.10&color=blue)](https://www.python.org/)
[![Checked with mypy](https://img.shields.io/static/v1?label=MyPy&message=checked&color=blue)](http://mypy-lang.org/)
Expand Down
2 changes: 1 addition & 1 deletion proxy/core/base/tcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BaseTcpServerHandler(Work):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.must_flush_before_shutdown = False
if self.flags.unix_socket_path:
if self.flags.unix_socket_path: # pragma: no cover
logger.debug(
'Connection accepted from {0}'.format(self.work.address),
)
Expand Down
8 changes: 4 additions & 4 deletions proxy/dashboard/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ def __init__(
@abstractmethod
def methods(self) -> List[str]:
"""Return list of methods that this plugin will handle."""
pass
pass # pragma: no cover

def connected(self) -> None:
"""Invoked when client websocket handshake finishes."""
pass
pass # pragma: no cover

@abstractmethod
def handle_message(self, message: Dict[str, Any]) -> None:
"""Handle messages for registered methods."""
pass
pass # pragma: no cover

def disconnected(self) -> None:
"""Invoked when client websocket connection gets closed."""
pass
pass # pragma: no cover

def reply(self, data: Dict[str, Any]) -> None:
self.client.queue(
Expand Down
4 changes: 2 additions & 2 deletions proxy/http/websocket/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def upgrade(self) -> None:
assert WebsocketFrame.key_to_accept(key) == accept

def ping(self, data: Optional[bytes] = None) -> None:
pass
pass # pragma: no cover

def pong(self, data: Optional[bytes] = None) -> None:
pass
pass # pragma: no cover

def shutdown(self, _data: Optional[bytes] = None) -> None:
"""Closes connection with the server."""
Expand Down
6 changes: 4 additions & 2 deletions proxy/plugin/cloudflare_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

try:
import httpx
except ImportError:
except ImportError: # pragma: no cover
pass

from typing import Optional, Tuple
Expand Down Expand Up @@ -75,7 +75,9 @@ def resolve_dns(self, host: str, port: int) -> Tuple[Optional[str], Optional[Tup
return answers[0]['data'], None
except Exception as e:
logger.info(
'Unable to resolve DNS-over-HTTPS for host {0} : {1}'.format(host, str(e)),
'Unable to resolve DNS-over-HTTPS for host {0} : {1}'.format(
host, str(e),
),
)
return None, None

Expand Down
46 changes: 46 additions & 0 deletions tests/core/test_event_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
Network monitoring, controls & Application development, testing, debugging.
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import unittest

from unittest import mock

from proxy.core.event import EventManager


class TestEventManager(unittest.TestCase):

@mock.patch('proxy.core.event.manager.EventQueue')
@mock.patch('proxy.core.event.manager.EventDispatcher')
@mock.patch('proxy.core.event.manager.multiprocessing.Queue')
@mock.patch('proxy.core.event.manager.threading.Event')
@mock.patch('proxy.core.event.manager.threading.Thread')
def test_setup_and_teardown(
self,
mock_thread: mock.Mock,
mock_event: mock.Mock,
mock_queue: mock.Mock,
mock_dispatcher: mock.Mock,
mock_event_queue: mock.Mock,
) -> None:
with EventManager() as _:
mock_queue.assert_called_once()
mock_event.assert_called_once()
mock_thread.assert_called_once_with(
target=mock_dispatcher.return_value.run,
)
mock_thread.return_value.start.assert_called_once()
mock_event_queue.assert_called_once_with(mock_queue.return_value)
mock_dispatcher.assert_called_once_with(
shutdown=mock_event.return_value,
event_queue=mock_event_queue.return_value,
)
mock_event.return_value.set.assert_called_once()
mock_thread.return_value.join.assert_called_once()

0 comments on commit e38f1a8

Please sign in to comment.