-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
37 lines (28 loc) · 1.34 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
"""
html-pdf-webservice
Copyright 2014 Nathan Jones
See LICENSE for more details
"""
from unittest.case import TestCase
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
from app import application
class AppTest(TestCase):
def setUp(self):
self.client = Client(application, BaseResponse)
def test_post_html_file_should_produce_pdf_response(self):
response = self.client.post('/', data={'html': open('sample.html')})
self.assertEquals(200, response.status_code)
self.assertEquals('application/pdf', response.headers['Content-Type'])
def test_post_html_file_as_form_param_should_produce_pdf_response(self):
response = self.client.post('/', data={'html': '<html><body><p>Hello</p></body></html>'})
self.assertEquals(200, response.status_code)
self.assertEquals('application/pdf', response.headers['Content-Type'])
def test_get_request_should_produce_method_not_allowed_response(self):
response = self.client.get('/')
self.assertEquals(405, response.status_code)
self.assertEquals('POST', response.headers['Allow'])
def test_request_without_file_should_produce_bad_request(self):
response = self.client.post('/')
self.assertEquals(400, response.status_code)
self.assertIn('html is required', response.data)