Skip to content

Commit

Permalink
Add tests for pubbot.trac
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc2k committed Aug 24, 2014
1 parent 0d1cd60 commit aec26b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pubbot/trac/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@chat_receiver(r'^newticket: (?P<ticket>.*)$')
def raise_ticket(sender, ticket, **kwargs):
def raise_ticket(sender, ticket, user, **kwargs):
instance = "http://localhost/sometrac"
username = "username"
password = "password"
Expand All @@ -43,7 +43,7 @@ def raise_ticket(sender, ticket, **kwargs):
"__FORM_TOKEN": token,
"field_summary": ticket,
"field_status": "new",
"field_reporter": kwargs['source'],
"field_reporter": user,
"field_owner": "",
})

Expand Down
22 changes: 22 additions & 0 deletions pubbot/trac/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import mock
import unittest

from pubbot.trac import receivers


DUMMY_FORM = """
<html><head><title>Trac</title></head><body>
<input type="hidden" name="__FORM_TOKEN" value="FOOBAR" />
</body></html>
"""


class TestRaiseTicket(unittest.TestCase):

def test_raise_ticket(self):
with mock.patch("requests.Session") as Session:
Session.return_value.get.return_value.text = DUMMY_FORM
Session.return_value.post.return_value.url = 'http://localhost/sometrac/ticket/1'

r = receivers.raise_ticket(None, user='fred', content="newticket: Raise a ticket")
self.assertEqual(r['content'], 'http://localhost/sometrac/ticket/1')

0 comments on commit aec26b4

Please sign in to comment.