Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Add 100% test coverage to main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bbangert committed Jun 11, 2015
1 parent be4a40c commit d667b3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 1 addition & 5 deletions autopush/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cyclone.web
from autobahn.twisted.websocket import WebSocketServerFactory, listenWS
from twisted.internet import reactor, task
from twisted.python import log

from autopush.endpoint import (EndpointHandler, RegistrationHandler)
from autopush.health import (HealthHandler, StatusHandler)
Expand Down Expand Up @@ -304,10 +303,7 @@ def connection_main(sysargs=None):

l = task.LoopingCall(periodic_reporter, settings)
l.start(1.0)
try:
reactor.run()
except KeyboardInterrupt:
log.debug('Bye')
reactor.run()


def endpoint_main(sysargs=None):
Expand Down
15 changes: 11 additions & 4 deletions autopush/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import unittest

from mock import patch
from mock import Mock, patch
from moto import mock_dynamodb2
from nose.tools import eq_

from autopush.main import (
connection_main,
endpoint_main,
make_settings
make_settings,
skip_request_logging,
)
from autopush.utils import str2bool, resolve_ip
from autopush.settings import AutopushSettings
Expand Down Expand Up @@ -48,7 +49,6 @@ def test_resolve_host_no_interface(self, mock_socket):
class ConnectionMainTestCase(unittest.TestCase):
def setUp(self):
patchers = [
"autopush.main.log",
"autopush.main.task",
"autopush.main.reactor",
"autopush.main.listenWS",
Expand All @@ -68,17 +68,23 @@ def test_basic(self):

def test_ssl(self):
connection_main([
"--ssl_dh_param=keys/dhparam.pem",
"--ssl_cert=keys/server.crt",
"--ssl_key=keys/server.key",
"--router_ssl_cert=keys/server.crt",
"--router_ssl_key=keys/server.key",
])

def test_skip_logging(self):
# Should skip setting up logging on the handler
mock_handler = Mock()
skip_request_logging(mock_handler)
eq_(len(mock_handler.mock_calls), 0)


class EndpointMainTestCase(unittest.TestCase):
def setUp(self):
patchers = [
"autopush.main.log",
"autopush.main.task",
"autopush.main.reactor",
"autopush.settings.TwistedMetrics",
Expand All @@ -98,6 +104,7 @@ def test_basic(self):

def test_ssl(self):
endpoint_main([
"--ssl_dh_param=keys/dhparam.pem",
"--ssl_cert=keys/server.crt",
"--ssl_key=keys/server.key",
])
Expand Down
5 changes: 5 additions & 0 deletions keys/dhparam.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN DH PARAMETERS-----
MIGHAoGBAOs/LnwcCWNMjuUbB0H1uIWZc7nSi63mQhpYRHWd7MysuBL7CxDpuz9R
SKMUhrLlIdlC154/lT15JXnJ//yfDWeI4smZfk9rVe7j5OKmPkvnzLv2mPU3LWhz
M6zXSbGnwpWSnKbGFAQg2cZWUBkQXJFnYjA8fVme8H7JMnqGSXmjAgEC
-----END DH PARAMETERS-----

0 comments on commit d667b3c

Please sign in to comment.