-
Notifications
You must be signed in to change notification settings - Fork 12
/
tests.py
43 lines (33 loc) · 1.1 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import unicode_literals, print_function, generators, division
from collections import Iterable
import wsgiref.util
import wsgiref.validate
import sys
__author__ = 'pahaz'
PY3 = sys.version_info[0] == 3
# MOCK environ
mock_environ = {}
wsgiref.util.setup_testing_defaults(mock_environ)
# MOCK start_response
is_start_response_call = False
start_response_status = None
start_response_headers = None
def mock_start_response(status, headers):
global is_start_response_call
global start_response_headers, start_response_status
is_start_response_call = True
start_response_status = status
start_response_headers = headers
# IMPORT APP
from main import application
# INITIALIZE
if PY3:
application = wsgiref.validate.validator(application)
result = application(mock_environ, mock_start_response)
# ASSERTS
assert isinstance(result, Iterable), "application() return isn't iterable obj"
assert is_start_response_call, "start_response isn't called"
assert start_response_status == "200 OK", "start_response status != '200 OK'"
# tearDown
if hasattr(result, 'close'):
result.close()