Skip to content

Commit

Permalink
added response provider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed May 10, 2018
1 parent 28afb7d commit 83bb61a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/providers/test_start_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from masonite.providers.StartResponseProvider import StartResponseProvider
from masonite.request import Request
from masonite.testsuite.TestSuite import WSGI_REQUEST
from masonite.app import App
from masonite.exceptions import ResponseError
import pytest

class TestResponseProvider:

def setup_method(self):
self.app = App()
self.provider = StartResponseProvider()

self.app.bind('Response', None)
self.app.bind('Request', Request(WSGI_REQUEST))
self.app.bind('Headers', [])

self.provider.app = self.app

def test_response_boot_throws_response_exception(self):
with pytest.raises(ResponseError):
self.provider.boot(self.app.make('Request'), self.app.make('Response'), self.app.make('Headers'))

def test_response_encodes_header_response_to_bytes(self):
encoded_bytes = bytes('test', 'utf-8')
self.app.bind('Response', 'test')

self.provider.boot(self.app.make('Request'), self.app.make('Response'), self.app.make('Headers'))

assert self.app.make('Headers')[0] == ("Content-Length", str(len(encoded_bytes)))

def test_redirect_sets_redirection_headers(self):
self.app.make('Request').redirect_url = '/redirection'
self.provider.boot(self.app.make('Request'), self.app.make('Response'), self.app.make('Headers'))
assert self.app.make('StatusCode') == '302 OK'
assert ('Location', '/redirection') in self.app.make('Headers')

0 comments on commit 83bb61a

Please sign in to comment.