Skip to content

Commit

Permalink
Merge 9371094 into 2dfa090
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Sep 14, 2018
2 parents 2dfa090 + 9371094 commit d4a1eba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
11 changes: 6 additions & 5 deletions masonite/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import tldextract
from cryptography.fernet import InvalidToken

from config import application
from masonite.auth.Sign import Sign
from masonite.helpers import dot
from masonite.helpers.Extendable import Extendable
from masonite.helpers.routes import compile_route_to_regex
from masonite.helpers.time import cookie_expire_time
from masonite.helpers import dot


class Request(Extendable):
Expand Down Expand Up @@ -533,8 +534,6 @@ def redirect_to(self, route_name, params={}):
self
"""

web_routes = self.container.make('WebRoutes')

self.redirect_url = self._get_named_route(route_name, params)

return self
Expand Down Expand Up @@ -600,20 +599,22 @@ def url_from_controller(self, controller, params={}):

return self.compile_route_to_url(self._get_route_from_controller(controller).route_url, params)

def route(self, name, params={}):
def route(self, name, params={}, full=False):
"""Gets a route URI by its name.
Arguments:
name {string} -- Name of the route.
Keyword Arguments:
params {dict} -- Dictionary of parameters to pass to the route for compilation. (default: {{}})
full {bool} -- Specifies whether the full application url should be returned or not. (default: {False})
Returns:
masonite.routes.Route|None -- Returns None if the route cannot be found.
"""

web_routes = self.container.make('WebRoutes')
if full:
return application.URL + self._get_named_route(name, params)

return self._get_named_route(name, params)

Expand Down
9 changes: 4 additions & 5 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ def test_get_cache(self):
cache_driver = self.app.make('Cache')

cache_driver.store('key', 'value')
cache_driver.store_for('key_time', 'key value', 2, 'seconds')

assert cache_driver.get('key') == 'value'
assert cache_driver.get('key_time') == 'key value'

cache_driver.store_for('key_time', 'key value', 4, 'seconds')
assert cache_driver.get('key_time') == 'key value'

for cache_file in glob.glob('bootstrap/cache/key*'):
os.remove(cache_file)
cache_driver.delete('key')
cache_driver.delete('key_time')

def test_cache_expired_before_get(self):
cache_driver = self.app.make('Cache')
Expand Down
11 changes: 11 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ def test_request_route_returns_url(self):
assert request.route('test.url') == '/test/url'
assert request.route('test.id', {'id': 1}) == '/test/url/1'

def test_request_route_returns_full_url(self):
app = App()
app.bind('Request', self.request)
app.bind('WebRoutes', [
get('/test/url', None).name('test.url'),
get('/test/url/@id', None).name('test.id')
])
request = app.make('Request').load_app(app)

assert request.route('test.url', full=True) == 'http://localhost/test/url'

def test_redirect_compiles_url_with_multiple_slashes(self):
app = App()
app.bind('Request', self.request)
Expand Down

0 comments on commit d4a1eba

Please sign in to comment.