Skip to content
This repository has been archived by the owner on Apr 18, 2018. It is now read-only.

Correctly set port and scheme when behind proxy. #116

Merged
merged 9 commits into from
Sep 26, 2014
Prev Previous commit
Next Next commit
Updated tests and imports so tests pass. Updated send_notifications s…
…ig so logic is simpler
  • Loading branch information
kkellyy committed Sep 15, 2014
commit 56966b404c618858e02a5d2540de77be93b51afd
1 change: 0 additions & 1 deletion pushmanager/core/requesthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import urllib
import urlparse
import logging

import tornado.httpclient
import tornado.stack_context
Expand Down
5 changes: 1 addition & 4 deletions pushmanager/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

import urlparse

import tornado.httpserver
import tornado.web
from pushmanager.core.auth import authenticate
from pushmanager.core.requesthandler import RequestHandler
from pushmanager.core.settings import Settings


class NullRequestHandler(RequestHandler):
Expand Down Expand Up @@ -68,5 +65,5 @@ def get(self):

class RedirHandler(RequestHandler):
def get(self, path):
self.redirect(urlparse.urljoin(get_base_url(), path), permanent=True)
self.redirect(urlparse.urljoin(self.get_base_url(), path), permanent=True)
post = get
1 change: 0 additions & 1 deletion pushmanager/servlets/addrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pushmanager.core.db import InsertIgnore
from pushmanager.core.mail import MailQueue
from pushmanager.core.requesthandler import RequestHandler
from pushmanager.core.settings import Settings
from pushmanager.core.xmppclient import XMPPQueue


Expand Down
1 change: 0 additions & 1 deletion pushmanager/servlets/deploypush.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pushmanager.core.util
from pushmanager.core.mail import MailQueue
from pushmanager.core.requesthandler import RequestHandler
from pushmanager.core.settings import Settings
from pushmanager.core.xmppclient import XMPPQueue


Expand Down
7 changes: 3 additions & 4 deletions pushmanager/servlets/newpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
from pushmanager.core.util import send_people_msg_in_groups


def send_notifications(people, pushtype, pushurl, request):
def send_notifications(people, pushtype, pushmanager_url):
pushmanager_servername = Settings['main_app']['servername']
pushmanager_url = request.get_base_url() + pushurl


if people:
msg = '%s: %s push starting! %s' % (', '.join(people), pushtype, pushmanager_url)
Expand Down Expand Up @@ -72,6 +70,7 @@ def on_db_complete(self, success, db_results):

insert_results, select_results = db_results
pushurl = '/push?id=%s' % insert_results.lastrowid
pushmanager_url = self.get_base_url() + pushurl

def users_involved(request):
if request['watchers']:
Expand All @@ -85,6 +84,6 @@ def users_involved(request):
else:
people = set(user for x in select_results for user in users_involved(x))

send_notifications(people, self.pushtype, pushurl, self)
send_notifications(people, self.pushtype, pushmanager_url)

return self.redirect(pushurl)
1 change: 0 additions & 1 deletion pushmanager/servlets/verifyrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pushmanager.core.db as db
import pushmanager.core.util
from pushmanager.core.requesthandler import RequestHandler
from pushmanager.core.settings import Settings
from pushmanager.core.xmppclient import XMPPQueue


Expand Down
14 changes: 7 additions & 7 deletions pushmanager/tests/test_servlet_newpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def call_on_db_complete(self, urgent=False):
mocked_self.check_db_results = mock.Mock(return_value=None)
mocked_self.redirect = mock.Mock(return_value=None)
mocked_self.pushtype = 'normal'
mocked_self.get_base_url = mock.Mock(return_value="http://fakeurl.com")

mocked_self.on_db_complete = types.MethodType(NewPushServlet.on_db_complete.im_func, mocked_self)

Expand Down Expand Up @@ -123,14 +124,13 @@ def mocked_notifications(self):
def test_send_notifications(self):
"""New push sends notifications via IRC, XMPP and emails."""
self.people = ["fake_user1", "fake_user2"]
self.pushurl = "/fake_push_url?id=123"
self.pushmanager_url = "https://example.com/fake_push_url?id=123"
self.pushtype = "fake_puth_type"

with self.mocked_notifications() as (mocked_call, mocked_mail, mocked_xmpp):
send_notifications(self.people, self.pushtype, self.pushurl)
send_notifications(self.people, self.pushtype, self.pushmanager_url)

url = "https://%s%s" % (Settings['main_app']['servername'], self.pushurl)
msg = "%s: %s push starting! %s" % (', '.join(self.people), self.pushtype, url)
msg = "%s: %s push starting! %s" % (', '.join(self.people), self.pushtype, self.pushmanager_url)
mocked_call.assert_called_once_with([
'/nail/sys/bin/nodebot',
'-i',
Expand All @@ -145,18 +145,18 @@ def test_send_notifications(self):
)
mocked_xmpp.assert_called_once_with(
self.people,
"Push starting! %s" % url
"Push starting! %s" % self.pushmanager_url
)

def test_send_notifications_empty_user_list(self):
"""If there is no pending push request we'll only send IRC and
email notifications, but not XMPP messages."""
self.people = []
self.pushurl = "fake_push_url"
self.pushmanager_url = "fake_push_url"
self.pushtype = "fake_puth_type"

with self.mocked_notifications() as (mocked_call, mocked_mail, mocked_xmpp):
send_notifications(self.people, self.pushtype, self.pushurl)
send_notifications(self.people, self.pushtype, self.pushmanager_url)
mocked_call.assert_called_once_with([
'/nail/sys/bin/nodebot',
'-i',
Expand Down