def test_shortener_create_1(self): from pyramid.testing import DummyRequest from pyramid.httpexceptions import HTTPFound from c2cgeoportal_geoportal.views.shortener import Shortener def route_url(name, *elements, **kw): return "https://example.com/short/" + kw["ref"] request = DummyRequest() request.user = None request.host = "example.com:443" request.server_name = "example.com" request.route_url = route_url request.registry.settings["shortener"] = { "base_url": "https://example.com/s/" } shortener = Shortener(request) request.params = {"url": "https://example.com/hi"} result = shortener.create() index = result["short_url"].rfind("/") self.assertEqual(result["short_url"][:index], "https://example.com/s") request.params = {} request.matchdict = {"ref": result["short_url"][index + 1:]} result = shortener.get() self.assertEqual(type(result), HTTPFound) self.assertEqual(result.location, "https://example.com/hi")
def test_shortener_dev(self): from tests import DummyRequest from c2cgeoportal_geoportal.views.shortener import Shortener def route_url(name, *elements, **kw): return "https://localhost:8484/s/" + kw["ref"] request = DummyRequest() request.user = None request.host = "localhost:8484" request.server_name = "0.0.0.0" request.route_url = route_url request.registry.settings["shortener"] = { "base_url": "https://localhost:8484/s/", "allowed_hosts": [ "localhost:8484", ], } shortener = Shortener(request) request.params = {"url": "https://localhost:8484/theme/Demo"} result = shortener.create() index = result["short_url"].rfind("/") self.assertEqual(result["short_url"][:index], "https://localhost:8484/s")
def test_shortener_create_1(self): from pyramid.testing import DummyRequest from pyramid.httpexceptions import HTTPFound from c2cgeoportal_geoportal.views.shortener import Shortener def route_url(name, *elements, **kw): return "https://example.com/short/" + kw["ref"] request = DummyRequest() request.user = None request.host = "example.com:443" request.server_name = "example.com" request.route_url = route_url request.registry.settings["shortener"] = { "base_url": "https://example.com/s/" } shortener = Shortener(request) request.params = { "url": "https://example.com/hi" } result = shortener.create() index = result["short_url"].rfind("/") self.assertEqual( result["short_url"][:index], "https://example.com/s" ) request.params = {} request.matchdict = { "ref": result["short_url"][index + 1:] } result = shortener.get() self.assertEqual(type(result), HTTPFound) self.assertEqual(result.location, "https://example.com/hi")
def test_shortener_baseurl(self): from pyramid.testing import DummyRequest from c2cgeoportal_geoportal.views.shortener import Shortener def route_url(name, *elements, **kw): return "https://example.com/short/" + kw["ref"] request = DummyRequest() request.user = None request.host = "example.com:443" request.server_name = "example.com" request.route_url = route_url request.registry.settings["shortener"] = { "base_url": "http://my_host/my_short/" } shortener = Shortener(request) request.params = { "url": "https://example.com/hi" } result = shortener.create() index = result["short_url"].rfind("/") self.assertEqual( result["short_url"][:index], "http://my_host/my_short" )
def test_shortener_noreplace_2(self): from pyramid.testing import DummyRequest from c2cgeoportal_geoportal.views.shortener import Shortener def route_url(name, *elements, **kw): return "https://example.com/short/" + kw["ref"] request = DummyRequest() request.user = None request.host = "example.com:443" request.server_name = "example.com" request.route_url = route_url request.registry.settings["shortener"] = { "base_url": "https://example.com/s/" } shortener = Shortener(request) request.params = {"url": "https://example.com/s/truite"} result = shortener.create() self.assertEqual(result["short_url"], "https://example.com/s/truite")
def test_shortener_baseurl(self): from tests import DummyRequest from c2cgeoportal_geoportal.views.shortener import Shortener def route_url(name, *elements, **kw): return "https://example.com/short/" + kw["ref"] request = DummyRequest() request.user = None request.host = "example.com:443" request.server_name = "example.com" request.route_url = route_url request.registry.settings["shortener"] = { "base_url": "http://my_host/my_short/" } shortener = Shortener(request) request.params = {"url": "https://example.com/hi"} result = shortener.create() index = result["short_url"].rfind("/") self.assertEqual(result["short_url"][:index], "http://my_host/my_short")