Skip to content

Commit ffb2229

Browse files
committed
tests skel
1 parent 506661a commit ffb2229

File tree

7 files changed

+108
-3
lines changed

7 files changed

+108
-3
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ python:
33
- "2.6"
44
- "2.7"
55
install:
6-
- pip install pep8 --use-mirrors
7-
- pip install https://github.com/dcramer/pyflakes/tarball/master
86
- pip install -r requirements.txt --use-mirrors
7+
before_script:
8+
- pip install -r test_requirements.txt --use-mirrors
99
script:
1010
- pep8 --ignore=E501 rtkit || exit 1
1111
- pyflakes -x W rtkit || exit 1
12-
- nosetests --with-doctest
12+
- py.test --doctest-modules rtkit -v

conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def pytest_collect_file(path, parent):
2+
if path.ext == ".py":
3+
return parent.Module(path, parent)

rtkit/tests/__init__.py

Whitespace-only changes.

rtkit/tests/common.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from multiprocessing import Process
2+
import unittest2 as unittest
3+
import time
4+
5+
class TestCaseWithFlask(unittest.TestCase):
6+
application = NotImplemented
7+
8+
@classmethod
9+
def setUpClass(cls):
10+
cls.server = Process(target=cls.application.run)
11+
cls.server.start()
12+
time.sleep(0.1)
13+
14+
@classmethod
15+
def tearDownClass(cls):
16+
cls.server.terminate()
17+
cls.server.join()

rtkit/tests/mock.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import logging
2+
from flask.app import Flask
3+
from flask.globals import request
4+
from flask.helpers import make_response
5+
from rtkit.parser import RTParser
6+
7+
class NullHandler(logging.Handler):
8+
def emit(self, record):
9+
pass
10+
logging.root.addHandler(NullHandler())
11+
12+
app = Flask(__name__)
13+
14+
@app.route('/ticket/new', methods=['POST'])
15+
def create_tkt():
16+
form = dict(RTParser.parse(request.form.get('content', ''), RTParser.decode)[0])
17+
if form['Queue'] == 'ERR':
18+
body = 'RT/3.8.10 200 Ok\n\n# Could not create ticket.\n# Could not create ticket. Queue not set\n\n'
19+
elif form['Queue'] == 'NOPERM':
20+
body = "RT/3.8.10 200 Ok\n\n# Could not create ticket.\n# No permission to create tickets in the queue '___Admin'\n\n"
21+
else:
22+
body = 'RT/3.8.10 200 Ok\n\n# Ticket 1 created.\n\n'
23+
response = make_response(body, 200)
24+
return response

rtkit/tests/ticket.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from rtkit.tests.common import TestCaseWithFlask
2+
from rtkit.tests.mock import app
3+
from rtkit.resource import RTResource
4+
from rtkit.authenticators import AbstractAuthenticator
5+
6+
7+
class TestCaseRT(TestCaseWithFlask):
8+
application = app
9+
10+
@classmethod
11+
def setUpClass(cls):
12+
super(TestCaseRT, cls).setUpClass()
13+
cls.resource = RTResource('http://localhost:5000/', None, None, AbstractAuthenticator)
14+
15+
def test_create_tkt(self):
16+
message = 'My useless\ntext on\nthree lines.'
17+
content = {
18+
'content': {
19+
'Queue': 1,
20+
'Subject' : 'New Ticket',
21+
'Text' : message.replace('\n', '\n '),
22+
}
23+
}
24+
response = self.resource.post(path='ticket/new', payload=content,)
25+
self.assertEqual(response.parsed, [[('id', 'ticket/1')]])
26+
self.assertEqual(response.status_int, 200)
27+
self.assertEqual(response.status, '200 Ok')
28+
29+
def test_create_tkt_noqueue(self):
30+
message = 'My useless\ntext on\nthree lines.'
31+
content = {
32+
'content': {
33+
'Queue': 'ERR',
34+
'Subject' : 'New Ticket',
35+
'Text' : message.replace('\n', '\n '),
36+
}
37+
}
38+
response = self.resource.post(path='ticket/new', payload=content,)
39+
self.assertEqual(response.parsed, [])
40+
self.assertEqual(response.status_int, 400)
41+
self.assertEqual(response.status, '400 Could not create ticket. Queue not set')
42+
43+
def test_create_tkt_noperm(self):
44+
message = 'My useless\ntext on\nthree lines.'
45+
content = {
46+
'content': {
47+
'Queue': 'NOPERM',
48+
'Subject' : 'New Ticket',
49+
'Text' : message.replace('\n', '\n '),
50+
}
51+
}
52+
response = self.resource.post(path='ticket/new', payload=content,)
53+
self.assertEqual(response.parsed, [])
54+
self.assertEqual(response.status_int, 400)
55+
self.assertEqual(response.status, "400 No permission to create tickets in the queue '___Admin'")
56+

test_requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pep8
2+
https://github.com/dcramer/pyflakes/tarball/master
3+
flask
4+
unittest2
5+
pytest

0 commit comments

Comments
 (0)