def includeme(config): """ Setup Routes """ config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') router = ViewSetRouter(config, trailing_slash=False) router.register('api/v1/board', BoardAPIView, 'board')
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('lookup', '/api/v1/lookup/{zip_code}') router = ViewSetRouter(config) router.register('api/v1/location', WeatherLocationAPIView, 'location')
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') router = ViewSetRouter(config) router.register('api/v1/weather', WeatherAPIView, 'weather') # router.register('api/v1/auth', AuthAPIView, 'auth')
def includeme(config): '''This is the main routes page. This utilizes pyramid restful routes to link the requests to the corresponding API class views. ''' config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('lookup', '/api/v1/lookup/{symbol}') config.add_route('visual', '/api/v1/visuals/{symbol}') router = ViewSetRouter(config, trailing_slash=False) router.register('api/v1/stock', StocksAPIView, 'stock') router.register('api/v1/company', CompanyAPIView, 'company', permission='admin') router.register('api/v1/portfolio', PortfolioAPIView, 'portfolio') router.register('api/v1/auth/{auth}', AuthAPIView, 'auth')
def includeme(config): # config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') router = ViewSetRouter(config, trailing_slash=False) # router.register('api/v1/location', WeatherLocationAPIView, 'location', permission='admin') router.register('api/v1/location', WeatherLocationAPIView, 'location') router.register('api/v1/lookup/{zip_code}', LookupAPIView, 'lookup') router.register('api/v1/auth/{auth}', AuthAPIView, 'auth')
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('lookup', 'api/v1/lookup/{symbol}') router = ViewSetRouter(config) router.register('api/v1/company', CompanyAPIViewset, 'company') router.register('api/v1/stock', StockAPIViewset, 'stock') router.register('api/v1/auth/{auth}', AuthAPIViewset, 'auth')
def includeme(config): """Route adding and configuration """ config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') # TODO: Go into default.py and change homeview. router = ViewSetRouter(config) router.register('api/v1/auth/{auth}', AuthAPIView, 'auth') # TODO: Add in permissions for preferences. router.register('api/v1/preferences', PreferencesAPIView, 'preferences', permission='admin') # TODO: Add in permissions for feed. router.register('api/v1/feed', FeedAPIView, 'feed', permission='admin') router.register('api/v1/visuals', VisualizationAPIViewset, 'visuals')
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('auth', '/api/v1/auth/') config.add_route('portfolio', '/api/v1/portfolio/') config.add_route('stock', '/api/v1/stock/') config.add_route('company', '/api/v1/company/') router = ViewSetRouter(config)
def includeme(config): config.add_route('home', '/') router = ViewSetRouter(config, trailing_slash=False) router.register('api/v1/auth/{auth}', AuthAPIViewset, 'auth') router.register('api/v1/location', WeatherLocationAPIView, 'location', permission='admin') router.register('api/v1/lookup/{zip_code}', LocationLookupAPIView, 'lookup')
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') # config.add_route('lookup', '/api/v1/lookup/{symbol}') router = ViewSetRouter(config, trailing_slash=False) # router.register('api/v1/company/{symbol}', CompanyAPIView, 'company') router.register('api/v1/stocks/{portfolio_id}', StockAPIView, 'stocks') router.register('api/v1/portfolio', PortfolioAPIView, 'portfolio') router.register('api/v1/visuals/{symbol}', VisualAPIView, 'visualization')
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') router = ViewSetRouter(config) router.register('api/v1/company', CompanyAPIViewset, 'company') router.register('api/v1/stocks', StockAPIViewset, 'stocks')
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('lookup', '/api/v1/lookup/{zip}') router = ViewSetRouter(config) # NOTE: Discuss permissions on location route and parameter to auth route (optionally add permissions to auth) router.register('api/v1/location', WeatherLocationAPIView, 'location') router.register('api/v1/auth/{auth}', AuthAPIView, 'auth')
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') router = ViewSetRouter(config, trailing_slash=False) # This is where user gets authorization. router.register('api/v1/auth/{auth}', AuthAPIView, 'auth') router.register('api/v1/passwords', PasswordsAPIView, 'passwords')
def includeme(config): """ routes to APIView by request """ config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') # config.add_route('lookup', '/api/v1/lookup/{symbol}') router = ViewSetRouter(config) router.register('api/v1/stock/{symbol}', StockAPIView, 'stock', permission='admin') router.register('api/v1/company/{symbol}', CompanyAPIView, 'company', permission='admin') router.register('api/v1/portfolio', PortfolioAPIView, 'portfolio', permission='admin') router.register('api/v1/auth/{auth}', AuthAPIView, 'auth') router.register('api/v1/visual/{symbol}', VisualAPIView, 'visual')
def includeme(config): """ Binds the routes. The name 'includeme' has significance in pyramid as this function is scanned for and when found, does its job. All of the endpoints for view-controllers. """ config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') router = ViewSetRouter(config, trailing_slash=False) router.register( 'api/v1/portfolio', PortfolioAPIViewset, 'portfolio', # permission='admin', ) router.register( 'api/v1/company', CompanyAPIViewset, 'company', # permission='view', ) router.register( 'api/v1/stock', StocksAPIViewset, 'stock', # permission='admin', ) router.register( 'api/v1/auth/{auth}', AuthAPIViewset, 'auth', ) router.register( 'api/v1/visuals', VisualizationAPIViewset, 'visuals', # permission='admin', )
class ViewSetRouterTests(TestCase): def setUp(self): self.config = MagicMock(spec=Configurator) self.router = ViewSetRouter(self.config) def test_get_routes(self): viewset = MyCRUDViewSet() # add mock detail_route and list_route methods def detail_route(): pass viewset.detail_route = detail_route viewset.detail_route.bind_to_methods = ['GET'] viewset.detail_route.kwargs = {} viewset.detail_route.detail = True def list_route(): pass viewset.list_route = list_route viewset.list_route.bind_to_methods = ['GET'] viewset.list_route.kwargs = {} viewset.list_route.detail = False routes = self.router.get_routes(viewset) expected = [ Route(url='/{prefix}{trailing_slash}', mapping={'get': 'list', 'post': 'create'}, name='{basename}-list', initkwargs={}), Route(url='/{prefix}/list_route{trailing_slash}', mapping={'get': 'list_route'}, name='{basename}-list-route', initkwargs={}), Route(url='/{prefix}/{lookup}{trailing_slash}', mapping={'get': 'retrieve', 'put': 'update', 'patch': 'partial_update', 'delete': 'destroy'}, name='{basename}-detail', initkwargs={}), Route(url='/{prefix}/{lookup}/detail_route{trailing_slash}', mapping={'get': 'detail_route'}, name='{basename}-detail-route', initkwargs={})] assert routes == expected def test_improperly_configured_dynamic_route(self): viewset = MyCRUDViewSet() # add mock detail_route and list_route methods def retrieve(): pass viewset.retrieve = retrieve viewset.retrieve.bind_to_methods = ['GET'] viewset.retrieve.kwargs = {} viewset.retrieve.detail = True self.assertRaises(ImproperlyConfigured, self.router.get_routes, viewset) def test_get_lookup(self): viewset = MyCRUDViewSet() lookup = self.router.get_lookup(viewset) assert lookup == '{id}' viewset = MyCRUDViewSet() viewset.lookup_field = 'id' lookup = self.router.get_lookup(viewset) assert lookup == '{id}' viewset = MyCRUDViewSet() viewset.lookup_url_kwargs = {'uuid': 1} lookup = self.router.get_lookup(viewset) assert lookup == '{uuid}' def test_nested_route(self): viewset = MyCRUDViewSet() viewset.lookup_url_kwargs = {'uuid': 1, 'parent_id': 2} self.assertRaises(ImproperlyConfigured, self.router.get_lookup, viewset) def test_get_method_map(self): viewset = ReadOnlyViewSet() mapping = self.router.get_method_map(viewset, {'get': 'list', 'post': 'create', 'put': 'update'}) assert mapping == {'get': 'list'} def test_register(self): viewset = ModelCRUDViewSet() self.config.reset_mock() self.router.register('users', viewset, 'user') self.config.add_route.assert_any_call('user-list', '/users/') self.config.add_route.assert_any_call('user-detail', '/users/{id}/') assert self.config.add_view.call_count == 2 def test_empty_register(self): viewset = APIViewSet() self.config.reset_mock() self.router.register('users', viewset, 'user') self.config.add_route.assert_not_called() self.config.add_route.assert_not_called()
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.add_route('portfolio', '/portfolio') router = ViewSetRouter(config) router.register('api/v1/stocks', StocksAPIView, 'stocks')
def includeme(config): """Connects the controllers, models, and templates if applicable """ config.add_static_view('static', 'static', cache_max_age=3600) # for nginx, to distribute # Vanilla pyramid, using base name (routename on view config decorator) binds route name to path config.add_route('home', '/') config.add_route('lookup', '/api/v1/lookup/{symbol}') # This is pyramid restful framework router = ViewSetRouter(config, trailing_slash=False) # Reference the link with aliases router.register('api/v1/company', CompanyAPIViewset, 'company') router.register('api/v1/stocks', StockAPIViewset, 'stocks', permission='admin') router.register('api/v1/auth/{auth}', AuthAPIViewset, 'auth') router.register('api/v1/portfolio', PortfolioAPIViewset, 'portfolio') router.register('api/v1/visuals', VisualAPIViewset, 'visuals')
def setUp(self): self.config = MagicMock(spec=Configurator) self.router = ViewSetRouter(self.config)
def includeme(config): config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') router = ViewSetRouter(config, trailing_slash=False) router.register('api/v1/auth/{auth}', AuthAPIView, 'auth') router.register('api/v1/analysis', NLTKAPIView, 'analysis') router.register('api/v1/users', GetAPIUsers, 'users_list') router.register('api/v1/charts/{graph_type}', NLTKAPICharts, 'charts') router.register('api/v1/admin/delete/{user_id}', NLTKAPIAdmin, 'user_delete') router.register('api/v1/admin/{graph_type}', NLTKAPIAdmin, 'admin_visuals')