Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
'masonite.drivers.storage',
'masonite.drivers.upload',
'masonite.managers',
'masonite.testsuite',
'masonite.queues',
'masonite.contracts',
'masonite.contracts.managers',
Expand Down
8 changes: 3 additions & 5 deletions src/masonite/drivers/session/SessionCookieDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
from ...contracts import SessionContract
from ...drivers import BaseDriver
from ...request import Request
from ...app import App


class SessionCookieDriver(SessionContract, BaseDriver):
"""Cookie Session Driver."""

def __init__(self, request: Request, app: App):
def __init__(self, request: Request):
"""Cookie Session Constructor.

Arguments:
Environ {dict} -- The WSGI environment
Request {masonite.request.Request} -- The Request class.
"""
self.environ = app.make('Environ')
self.request = request

def get(self, key):
Expand Down Expand Up @@ -97,8 +95,8 @@ def __collect_data(self):
dict
"""
cookies = {}
if 'HTTP_COOKIE' in self.environ and self.environ['HTTP_COOKIE']:
cookies_original = self.environ['HTTP_COOKIE'].split(';')
if 'HTTP_COOKIE' in self.request.environ and self.request.environ['HTTP_COOKIE']:
cookies_original = self.request.environ['HTTP_COOKIE'].split(';')
for cookie in cookies_original:
if cookie.strip().startswith('s_') or cookie.strip().startswith('f_'):
data = cookie.split("=", 1)
Expand Down
12 changes: 6 additions & 6 deletions src/masonite/drivers/session/SessionMemoryDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ...contracts import SessionContract
from ...drivers import BaseDriver
from ...app import App
from ...request import Request


class SessionMemoryDriver(SessionContract, BaseDriver):
Expand All @@ -11,13 +11,13 @@ class SessionMemoryDriver(SessionContract, BaseDriver):
_session = {}
_flash = {}

def __init__(self, app: App):
def __init__(self, request: Request):
"""Cookie Session Constructor.

Arguments:
Environ {dict} -- The WSGI environment
"""
self.environ = app.make('Environ')
self.request = request

def get(self, key):
"""Get a value from the session.
Expand Down Expand Up @@ -117,10 +117,10 @@ def delete(self, key):

def __get_client_address(self):
"""Get ip from the client."""
if 'HTTP_X_FORWARDED_FOR' in self.environ:
return self.environ['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip()
if 'HTTP_X_FORWARDED_FOR' in self.request.environ:
return self.request.environ['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip()

return self.environ['REMOTE_ADDR']
return self.request.environ['REMOTE_ADDR']

def __collect_data(self, key=False):
"""Collect data from session and flash data.
Expand Down
2 changes: 1 addition & 1 deletion src/masonite/testing/MockRoute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ..request import Request
from ..testsuite import TestSuite, generate_wsgi
from .generate_wsgi import generate_wsgi
import json
from ..helpers import Dot

Expand Down
45 changes: 4 additions & 41 deletions src/masonite/testing/TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from ..exceptions import RouteNotFoundException
from ..helpers.migrations import Migrations
from ..helpers.routes import create_matchurl, flatten_routes
from ..testsuite import generate_wsgi
from .generate_wsgi import generate_wsgi
from .create_container import create_container
from orator.orm import Factory
from ..app import App

from .MockRoute import MockRoute

Expand All @@ -22,11 +22,11 @@ class TestCase(unittest.TestCase):
transactions = True
refreshes_database = False
_transaction = False
_with_subdomains = False

def setUp(self):
from wsgi import container
self.container = container
self._with_subdomains = False

self.acting_user = False
self.factory = Factory()
Expand Down Expand Up @@ -285,41 +285,4 @@ def withoutHttpMiddleware(self):
return self

def create_container(self):
container = App()
from config import providers

container.bind('WSGI', generate_wsgi())
# container.bind('Application', application)
container.bind('Container', container)

# container.bind('ProvidersConfig', providers)
container.bind('Providers', [])
container.bind('WSGIProviders', [])

"""Bind all service providers
Let's register everything into the Service Container. Once everything is
in the container we can run through all the boot methods. For reasons
some providers don't need to execute with every request and should
only run once when the server is started. Providers will be ran
once if the wsgi attribute on a provider is False.
"""

for provider in providers.PROVIDERS:
located_provider = provider()
located_provider.load_app(container).register()
if located_provider.wsgi:
container.make('WSGIProviders').append(located_provider)
else:
container.make('Providers').append(located_provider)

for provider in container.make('Providers'):
container.resolve(provider.boot)

"""Get the application from the container
Some providers may change the WSGI Server like wrapping the WSGI server
in a Whitenoise container for an example. Let's get a WSGI instance
from the container and pass it to the application variable. This
will allow WSGI servers to pick it up from the command line
"""

return container
return create_container()
2 changes: 2 additions & 0 deletions src/masonite/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .TestCase import TestCase
from .MockRoute import MockRoute
from .generate_wsgi import generate_wsgi
from .create_container import create_container
43 changes: 43 additions & 0 deletions src/masonite/testing/create_container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from ..app import App
import copy


def create_container():
container = copy.deepcopy(App())
from .generate_wsgi import generate_wsgi
from config import providers

container.bind('WSGI', generate_wsgi())
container.bind('Container', container)

# container.bind('ProvidersConfig', providers)
container.bind('Providers', [])
container.bind('WSGIProviders', [])

"""Bind all service providers
Let's register everything into the Service Container. Once everything is
in the container we can run through all the boot methods. For reasons
some providers don't need to execute with every request and should
only run once when the server is started. Providers will be ran
once if the wsgi attribute on a provider is False.
"""

for provider in providers.PROVIDERS:
located_provider = provider()
located_provider.load_app(container).register()
if located_provider.wsgi:
container.make('WSGIProviders').append(located_provider)
else:
container.make('Providers').append(located_provider)

for provider in container.make('Providers'):
container.resolve(provider.boot)

"""Get the application from the container
Some providers may change the WSGI Server like wrapping the WSGI server
in a Whitenoise container for an example. Let's get a WSGI instance
from the container and pass it to the application variable. This
will allow WSGI servers to pick it up from the command line
"""

return container
32 changes: 32 additions & 0 deletions src/masonite/testing/generate_wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import io


def generate_wsgi():
return {
'wsgi.version': (1, 0),
'wsgi.multithread': False,
'wsgi.multiprocess': True,
'wsgi.run_once': False,
'wsgi.input': io.BytesIO(),
'SERVER_SOFTWARE': 'gunicorn/19.7.1',
'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'application=Masonite',
'RAW_URI': '/',
'SERVER_PROTOCOL': 'HTTP/1.1',
'HTTP_HOST': '127.0.0.1:8000',
'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_UPGRADE_INSECURE_REQUESTS': '1',
'HTTP_COOKIE': 'setcookie=value',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7',
'HTTP_ACCEPT_LANGUAGE': 'en-us',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'HTTP_CONNECTION': 'keep-alive',
'wsgi.url_scheme': 'http',
'REMOTE_ADDR': '127.0.0.1',
'REMOTE_PORT': '62241',
'SERVER_NAME': '127.0.0.1',
'SERVER_PORT': '8000',
'PATH_INFO': '/',
'SCRIPT_NAME': ''
}
25 changes: 0 additions & 25 deletions src/masonite/testsuite/TestRequest.py

This file was deleted.

18 changes: 0 additions & 18 deletions src/masonite/testsuite/TestRoute.py

This file was deleted.

117 changes: 0 additions & 117 deletions src/masonite/testsuite/TestSuite.py

This file was deleted.

Loading