How to use create_route method in localstack

Best Python code snippet using localstack_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...1798 metadata: Any,1799 redirect_to_prefix: Optional[str] = None1800 ) -> List[Union[Route, Include]]:1801 pass1802def _create_route(1803 template: str,1804 handler: Callable[..., Any],1805 method: str = 'GET',1806 name_prefix: str = ''1807) -> Route:1808 """1809 Create a single route for given parameters.1810 Since Molten does not allow multiple routes with the same name, and since the name is created from1811 the handler name, we need to provide custom name for each route that shares the handler. We do that1812 by prefixing the handler name with an arbitrary prefix, which is specified by route generator calling1813 this helper.1814 Without this Molten requirement, we could just use `Route(...)` and be done with it.1815 """1816 return Route(template, handler, method=method, name=f'{name_prefix}{handler.__name__}')1817def route_generator(fn: RouteGeneratorType) -> RouteGeneratorOuterType:1818 """1819 Decorator for route generators, providing shared functionality.1820 Decorates function with signature matching :py:class:`RouteGeneratorType`, which does the actual work,1821 and wraps it to provide some shared functionality, presenting :py:class:`RouteGeneratorOuterType` signature1822 to API server code. This signature demands more parameters, but the wrapped function doesn't have to be1823 concerned with these are consumed by the wrapper.1824 """1825 @functools.wraps(fn)1826 def wrapper(1827 url_prefix: str,1828 name_prefix: str,1829 metadata: Any,1830 redirect_to_prefix: Optional[str] = None1831 ) -> List[Union[Route, Include]]:1832 if redirect_to_prefix:1833 # Keeping the same API as `_create_route`, to make the structure below easier to handle. But we will ignore1834 # the given handler, and use a custom one.1835 def create_route(1836 template: str,1837 handler: Callable[..., Any],1838 method: str = 'GET'1839 ) -> Route:1840 def real_handler(request: Request) -> Any:1841 assert redirect_to_prefix is not None1842 # Replace just once, no more - doesn't metter with regular versions, but the pseudo "top-level"1843 # version means an empty string as a prefix, and that would insert the `redirect_to_prefix` between1844 # each and every character of the path.1845 return molten.redirect(1846 request.path.replace(url_prefix, redirect_to_prefix, 1),1847 redirect_type=molten.RedirectType.PERMANENT1848 )1849 return Route(template, real_handler, method=method, name=f'{name_prefix}{handler.__name__}')1850 else:1851 def create_route(1852 template: str,1853 handler: Callable[..., Any],1854 method: str = 'GET'1855 ) -> Route:1856 return _create_route(template, handler, method=method, name_prefix=name_prefix)1857 return [1858 Include(url_prefix, fn(create_route, name_prefix, metadata))1859 ]1860 return wrapper1861# NEW: added hostname HW constraint1862@route_generator1863def generate_routes_v0_0_38(1864 create_route: CreateRouteCallbackType,1865 name_prefix: str,1866 metadata: Any1867) -> List[Union[Route, Include]]:1868 return [1869 Include('/guests', [1870 create_route('/', get_guest_requests, method='GET'),1871 create_route('/', create_guest_request_v0_0_38, method='POST'),1872 create_route('/{guestname}', get_guest_request), # noqa: FS0031873 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0031874 create_route('/events', get_events),1875 create_route('/{guestname}/events', get_guest_events), # noqa: FS0031876 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0031877 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0031878 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0031879 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5011880 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5011881 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5011882 ]),1883 Include('/knobs', [1884 create_route('/', KnobManager.entry_get_knobs, method='GET'),1885 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0031886 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0031887 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0031888 ]),1889 Include('/users', [1890 create_route('/', UserManager.entry_get_users, method='GET'),1891 create_route('/{username}', UserManager.entry_get_user, method='GET'), # noqa: FS0031892 create_route('/{username}', UserManager.entry_create_user, method='POST'), # noqa: FS0031893 create_route('/{username}', UserManager.entry_delete_user, method='DELETE'), # noqa: FS0031894 create_route('/{username}/tokens/{tokentype}/reset', UserManager.entry_reset_token, method='POST') # noqa: FS003,E5011895 ]),1896 create_route('/metrics', get_metrics),1897 create_route('/about', get_about),1898 Include('/_cache', [1899 Include('/pools/{poolname}', [ # noqa: FS0031900 create_route('/image-info', CacheManager.entry_pool_image_info),1901 create_route('/flavor-info', CacheManager.entry_pool_flavor_info),1902 create_route('/image-info', CacheManager.entry_refresh_pool_image_info, method='POST'),1903 create_route('/flavor-info', CacheManager.entry_refresh_pool_flavor_info, method='POST')1904 ])1905 ]),1906 Include('/_status', [1907 Include('/workers', [1908 create_route('/traffic', StatusManager.entry_workers_traffic)1909 ])1910 ]),1911 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),1912 create_route('/_schema', OpenAPIHandler(metadata=metadata))1913 ]1914# NEW: virtualization HW constraint1915@route_generator1916def generate_routes_v0_0_37(1917 create_route: CreateRouteCallbackType,1918 name_prefix: str,1919 metadata: Any1920) -> List[Union[Route, Include]]:1921 return [1922 Include('/guests', [1923 create_route('/', get_guest_requests, method='GET'),1924 create_route('/', create_guest_request_v0_0_37, method='POST'),1925 create_route('/{guestname}', get_guest_request), # noqa: FS0031926 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0031927 create_route('/events', get_events),1928 create_route('/{guestname}/events', get_guest_events), # noqa: FS0031929 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0031930 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0031931 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0031932 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5011933 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5011934 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5011935 ]),1936 Include('/knobs', [1937 create_route('/', KnobManager.entry_get_knobs, method='GET'),1938 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0031939 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0031940 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0031941 ]),1942 Include('/users', [1943 create_route('/', UserManager.entry_get_users, method='GET'),1944 create_route('/{username}', UserManager.entry_get_user, method='GET'), # noqa: FS0031945 create_route('/{username}', UserManager.entry_create_user, method='POST'), # noqa: FS0031946 create_route('/{username}', UserManager.entry_delete_user, method='DELETE'), # noqa: FS0031947 create_route('/{username}/tokens/{tokentype}/reset', UserManager.entry_reset_token, method='POST') # noqa: FS003,E5011948 ]),1949 create_route('/metrics', get_metrics),1950 create_route('/about', get_about),1951 Include('/_cache', [1952 Include('/pools/{poolname}', [ # noqa: FS0031953 create_route('/image-info', CacheManager.entry_pool_image_info),1954 create_route('/flavor-info', CacheManager.entry_pool_flavor_info),1955 create_route('/image-info', CacheManager.entry_refresh_pool_image_info, method='POST'),1956 create_route('/flavor-info', CacheManager.entry_refresh_pool_flavor_info, method='POST')1957 ])1958 ]),1959 Include('/_status', [1960 Include('/workers', [1961 create_route('/traffic', StatusManager.entry_workers_traffic)1962 ])1963 ]),1964 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),1965 create_route('/_schema', OpenAPIHandler(metadata=metadata))1966 ]1967# NEW: current worker tasks1968# NEW: boot.method HW constraint1969@route_generator1970def generate_routes_v0_0_32(1971 create_route: CreateRouteCallbackType,1972 name_prefix: str,1973 metadata: Any1974) -> List[Union[Route, Include]]:1975 return [1976 Include('/guests', [1977 create_route('/', get_guest_requests, method='GET'),1978 create_route('/', create_guest_request_v0_0_32, method='POST'),1979 create_route('/{guestname}', get_guest_request), # noqa: FS0031980 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0031981 create_route('/events', get_events),1982 create_route('/{guestname}/events', get_guest_events), # noqa: FS0031983 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0031984 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0031985 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0031986 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5011987 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5011988 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5011989 ]),1990 Include('/knobs', [1991 create_route('/', KnobManager.entry_get_knobs, method='GET'),1992 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0031993 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0031994 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0031995 ]),1996 Include('/users', [1997 create_route('/', UserManager.entry_get_users, method='GET'),1998 create_route('/{username}', UserManager.entry_get_user, method='GET'), # noqa: FS0031999 create_route('/{username}', UserManager.entry_create_user, method='POST'), # noqa: FS0032000 create_route('/{username}', UserManager.entry_delete_user, method='DELETE'), # noqa: FS0032001 create_route('/{username}/tokens/{tokentype}/reset', UserManager.entry_reset_token, method='POST') # noqa: FS003,E5012002 ]),2003 create_route('/metrics', get_metrics),2004 create_route('/about', get_about),2005 Include('/_cache', [2006 Include('/pools/{poolname}', [ # noqa: FS0032007 create_route('/image-info', CacheManager.entry_pool_image_info),2008 create_route('/flavor-info', CacheManager.entry_pool_flavor_info),2009 create_route('/image-info', CacheManager.entry_refresh_pool_image_info, method='POST'),2010 create_route('/flavor-info', CacheManager.entry_refresh_pool_flavor_info, method='POST')2011 ])2012 ]),2013 Include('/_status', [2014 Include('/workers', [2015 create_route('/traffic', StatusManager.entry_workers_traffic)2016 ])2017 ]),2018 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2019 create_route('/_schema', OpenAPIHandler(metadata=metadata))2020 ]2021# NEW: trigger pool info refresh2022# NEW: HW requirement changes - added `network`2023@route_generator2024def generate_routes_v0_0_28(2025 create_route: CreateRouteCallbackType,2026 name_prefix: str,2027 metadata: Any2028) -> List[Union[Route, Include]]:2029 return [2030 Include('/guests', [2031 create_route('/', get_guest_requests, method='GET'),2032 create_route('/', create_guest_request_v0_0_28, method='POST'),2033 create_route('/{guestname}', get_guest_request), # noqa: FS0032034 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032035 create_route('/events', get_events),2036 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032037 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032038 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032039 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032040 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5012041 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5012042 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5012043 ]),2044 Include('/knobs', [2045 create_route('/', KnobManager.entry_get_knobs, method='GET'),2046 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032047 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032048 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032049 ]),2050 Include('/users', [2051 create_route('/', UserManager.entry_get_users, method='GET'),2052 create_route('/{username}', UserManager.entry_get_user, method='GET'), # noqa: FS0032053 create_route('/{username}', UserManager.entry_create_user, method='POST'), # noqa: FS0032054 create_route('/{username}', UserManager.entry_delete_user, method='DELETE'), # noqa: FS0032055 create_route('/{username}/tokens/{tokentype}/reset', UserManager.entry_reset_token, method='POST') # noqa: FS003,E5012056 ]),2057 create_route('/metrics', get_metrics),2058 create_route('/about', get_about),2059 Include('/_cache', [2060 Include('/pools/{poolname}', [ # noqa: FS0032061 create_route('/image-info', CacheManager.entry_pool_image_info),2062 create_route('/flavor-info', CacheManager.entry_pool_flavor_info),2063 create_route('/image-info', CacheManager.entry_refresh_pool_image_info, method='POST'),2064 create_route('/flavor-info', CacheManager.entry_refresh_pool_flavor_info, method='POST')2065 ])2066 ]),2067 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2068 create_route('/_schema', OpenAPIHandler(metadata=metadata))2069 ]2070# NEW: HW requirement changes - refactored `disk`2071@route_generator2072def generate_routes_v0_0_27(2073 create_route: CreateRouteCallbackType,2074 name_prefix: str,2075 metadata: Any2076) -> List[Union[Route, Include]]:2077 return [2078 Include('/guests', [2079 create_route('/', get_guest_requests, method='GET'),2080 create_route('/', create_guest_request_v0_0_27, method='POST'),2081 create_route('/{guestname}', get_guest_request), # noqa: FS0032082 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032083 create_route('/events', get_events),2084 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032085 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032086 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032087 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032088 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5012089 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5012090 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5012091 ]),2092 Include('/knobs', [2093 create_route('/', KnobManager.entry_get_knobs, method='GET'),2094 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032095 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032096 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032097 ]),2098 Include('/users', [2099 create_route('/', UserManager.entry_get_users, method='GET'),2100 create_route('/{username}', UserManager.entry_get_user, method='GET'), # noqa: FS0032101 create_route('/{username}', UserManager.entry_create_user, method='POST'), # noqa: FS0032102 create_route('/{username}', UserManager.entry_delete_user, method='DELETE'), # noqa: FS0032103 create_route('/{username}/tokens/{tokentype}/reset', UserManager.entry_reset_token, method='POST') # noqa: FS003,E5012104 ]),2105 create_route('/metrics', get_metrics),2106 create_route('/about', get_about),2107 Include('/_cache', [2108 Include('/pools/{poolname}', [ # noqa: FS0032109 create_route('/image-info', CacheManager.entry_pool_image_info),2110 create_route('/flavor-info', CacheManager.entry_pool_flavor_info),2111 create_route('/image-info', CacheManager.entry_refresh_pool_image_info, method='POST'),2112 create_route('/flavor-info', CacheManager.entry_refresh_pool_flavor_info, method='POST')2113 ])2114 ]),2115 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2116 create_route('/_schema', OpenAPIHandler(metadata=metadata))2117 ]2118# NEW: allow log-types to be specified in guest request2119@route_generator2120def generate_routes_v0_0_26(2121 create_route: CreateRouteCallbackType,2122 name_prefix: str,2123 metadata: Any2124) -> List[Union[Route, Include]]:2125 return [2126 Include('/guests', [2127 create_route('/', get_guest_requests, method='GET'),2128 create_route('/', create_guest_request_v0_0_26, method='POST'),2129 create_route('/{guestname}', get_guest_request), # noqa: FS0032130 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032131 create_route('/events', get_events),2132 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032133 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032134 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032135 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032136 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5012137 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5012138 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5012139 ]),2140 Include('/knobs', [2141 create_route('/', KnobManager.entry_get_knobs, method='GET'),2142 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032143 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032144 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032145 ]),2146 Include('/users', [2147 create_route('/', UserManager.entry_get_users, method='GET'),2148 create_route('/{username}', UserManager.entry_get_user, method='GET'), # noqa: FS0032149 create_route('/{username}', UserManager.entry_create_user, method='POST'), # noqa: FS0032150 create_route('/{username}', UserManager.entry_delete_user, method='DELETE'), # noqa: FS0032151 create_route('/{username}/tokens/{tokentype}/reset', UserManager.entry_reset_token, method='POST') # noqa: FS003,E5012152 ]),2153 create_route('/metrics', get_metrics),2154 create_route('/about', get_about),2155 Include('/_cache', [2156 Include('/pools/{poolname}', [ # noqa: FS0032157 create_route('/image-info', CacheManager.entry_pool_image_info),2158 create_route('/flavor-info', CacheManager.entry_pool_flavor_info)2159 ])2160 ]),2161 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2162 create_route('/_schema', OpenAPIHandler(metadata=metadata))2163 ]2164# NEW: allow skipping verify-ssh steps2165@route_generator2166def generate_routes_v0_0_24(2167 create_route: CreateRouteCallbackType,2168 name_prefix: str,2169 metadata: Any2170) -> List[Union[Route, Include]]:2171 return [2172 Include('/guests', [2173 create_route('/', get_guest_requests, method='GET'),2174 create_route('/', create_guest_request_v0_0_24, method='POST'),2175 create_route('/{guestname}', get_guest_request), # noqa: FS0032176 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032177 create_route('/events', get_events),2178 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032179 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032180 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032181 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032182 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5012183 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5012184 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5012185 ]),2186 Include('/knobs', [2187 create_route('/', KnobManager.entry_get_knobs, method='GET'),2188 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032189 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032190 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032191 ]),2192 Include('/users', [2193 create_route('/', UserManager.entry_get_users, method='GET'),2194 create_route('/{username}', UserManager.entry_get_user, method='GET'), # noqa: FS0032195 create_route('/{username}', UserManager.entry_create_user, method='POST'), # noqa: FS0032196 create_route('/{username}', UserManager.entry_delete_user, method='DELETE'), # noqa: FS0032197 create_route('/{username}/tokens/{tokentype}/reset', UserManager.entry_reset_token, method='POST') # noqa: FS003,E5012198 ]),2199 create_route('/metrics', get_metrics),2200 create_route('/about', get_about),2201 Include('/_cache', [2202 Include('/pools/{poolname}', [ # noqa: FS0032203 create_route('/image-info', CacheManager.entry_pool_image_info),2204 create_route('/flavor-info', CacheManager.entry_pool_flavor_info)2205 ])2206 ]),2207 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2208 create_route('/_schema', OpenAPIHandler(metadata=metadata))2209 ]2210# NEW: user management2211@route_generator2212def generate_routes_v0_0_21(2213 create_route: CreateRouteCallbackType,2214 name_prefix: str,2215 metadata: Any2216) -> List[Union[Route, Include]]:2217 return [2218 Include('/guests', [2219 create_route('/', get_guest_requests, method='GET'),2220 create_route('/', create_guest_request_v0_0_20, method='POST'),2221 create_route('/{guestname}', get_guest_request), # noqa: FS0032222 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032223 create_route('/events', get_events),2224 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032225 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032226 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032227 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032228 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5012229 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5012230 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5012231 ]),2232 Include('/knobs', [2233 create_route('/', KnobManager.entry_get_knobs, method='GET'),2234 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032235 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032236 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032237 ]),2238 Include('/users', [2239 create_route('/', UserManager.entry_get_users, method='GET'),2240 create_route('/{username}', UserManager.entry_get_user, method='GET'), # noqa: FS0032241 create_route('/{username}', UserManager.entry_create_user, method='POST'), # noqa: FS0032242 create_route('/{username}', UserManager.entry_delete_user, method='DELETE'), # noqa: FS0032243 create_route('/{username}/tokens/{tokentype}/reset', UserManager.entry_reset_token, method='POST') # noqa: FS003,E5012244 ]),2245 create_route('/metrics', get_metrics),2246 create_route('/about', get_about),2247 Include('/_cache', [2248 Include('/pools/{poolname}', [ # noqa: FS0032249 create_route('/image-info', CacheManager.entry_pool_image_info),2250 create_route('/flavor-info', CacheManager.entry_pool_flavor_info)2251 ])2252 ]),2253 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2254 create_route('/_schema', OpenAPIHandler(metadata=metadata))2255 ]2256# NEW: guest logs2257@route_generator2258def generate_routes_v0_0_20(2259 create_route: CreateRouteCallbackType,2260 name_prefix: str,2261 metadata: Any2262) -> List[Union[Route, Include]]:2263 return [2264 Include('/guests', [2265 create_route('/', get_guest_requests, method='GET'),2266 create_route('/', create_guest_request_v0_0_20, method='POST'),2267 create_route('/{guestname}', get_guest_request), # noqa: FS0032268 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032269 create_route('/events', get_events),2270 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032271 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032272 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032273 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032274 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5012275 create_route('/{guestname}/logs/{logname}/{contenttype}', get_guest_request_log, method='GET'), # noqa: FS003,E5012276 create_route('/{guestname}/logs/{logname}/{contenttype}', create_guest_request_log, method='POST') # noqa: FS003,E5012277 ]),2278 Include('/knobs', [2279 create_route('/', KnobManager.entry_get_knobs, method='GET'),2280 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032281 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032282 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032283 ]),2284 create_route('/metrics', get_metrics),2285 create_route('/about', get_about),2286 Include('/_cache', [2287 Include('/pools/{poolname}', [ # noqa: FS0032288 create_route('/image-info', CacheManager.entry_pool_image_info),2289 create_route('/flavor-info', CacheManager.entry_pool_flavor_info)2290 ])2291 ]),2292 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2293 create_route('/_schema', OpenAPIHandler(metadata=metadata))2294 ]2295# NEW: HW requirements2296@route_generator2297def generate_routes_v0_0_19(2298 create_route: CreateRouteCallbackType,2299 name_prefix: str,2300 metadata: Any2301) -> List[Union[Route, Include]]:2302 return [2303 Include('/guests', [2304 create_route('/', get_guest_requests, method='GET'),2305 create_route('/', create_guest_request_v0_0_19, method='POST'),2306 create_route('/{guestname}', get_guest_request), # noqa: FS0032307 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032308 create_route('/events', get_events),2309 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032310 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032311 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032312 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032313 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5012314 create_route('/{guestname}/console/url', acquire_guest_console_url, method='GET') # noqa: FS0032315 ]),2316 Include('/knobs', [2317 create_route('/', KnobManager.entry_get_knobs, method='GET'),2318 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032319 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032320 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032321 ]),2322 create_route('/metrics', get_metrics),2323 create_route('/about', get_about),2324 Include('/_cache', [2325 Include('/pools/{poolname}', [ # noqa: FS0032326 create_route('/image-info', CacheManager.entry_pool_image_info),2327 create_route('/flavor-info', CacheManager.entry_pool_flavor_info)2328 ])2329 ]),2330 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2331 create_route('/_schema', OpenAPIHandler(metadata=metadata))2332 ]2333# NEW: /{guestname}/console/url2334@route_generator2335def generate_routes_v0_0_18(2336 create_route: CreateRouteCallbackType,2337 name_prefix: str,2338 metadata: Any2339) -> List[Union[Route, Include]]:2340 return [2341 Include('/guests', [2342 create_route('/', get_guest_requests, method='GET'),2343 create_route('/', create_guest_request_v0_0_18, method='POST'),2344 create_route('/{guestname}', get_guest_request), # noqa: FS0032345 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032346 create_route('/events', get_events),2347 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032348 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032349 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032350 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032351 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST'), # noqa: FS003,E5012352 create_route('/{guestname}/console/url', acquire_guest_console_url, method='GET') # noqa: FS0032353 ]),2354 Include('/knobs', [2355 create_route('/', KnobManager.entry_get_knobs, method='GET'),2356 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032357 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032358 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032359 ]),2360 create_route('/metrics', get_metrics),2361 create_route('/about', get_about),2362 Include('/_cache', [2363 Include('/pools/{poolname}', [ # noqa: FS0032364 create_route('/image-info', CacheManager.entry_pool_image_info),2365 create_route('/flavor-info', CacheManager.entry_pool_flavor_info)2366 ])2367 ]),2368 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2369 create_route('/_schema', OpenAPIHandler(metadata=metadata))2370 ]2371@route_generator2372def generate_routes_v0_0_17(2373 create_route: CreateRouteCallbackType,2374 name_prefix: str,2375 metadata: Any2376) -> List[Union[Route, Include]]:2377 return [2378 Include('/guests', [2379 create_route('/', get_guest_requests, method='GET'),2380 create_route('/', create_guest_request_v0_0_17, method='POST'),2381 create_route('/{guestname}', get_guest_request), # noqa: FS0032382 create_route('/{guestname}', delete_guest, method='DELETE'), # noqa: FS0032383 create_route('/events', get_events),2384 create_route('/{guestname}/events', get_guest_events), # noqa: FS0032385 create_route('/{guestname}/snapshots', create_snapshot_request, method='POST'), # noqa: FS0032386 create_route('/{guestname}/snapshots/{snapshotname}', get_snapshot_request, method='GET'), # noqa: FS0032387 create_route('/{guestname}/snapshots/{snapshotname}', delete_snapshot, method='DELETE'), # noqa: FS0032388 create_route('/{guestname}/snapshots/{snapshotname}/restore', restore_snapshot_request, method='POST') # noqa: FS003,E5012389 ]),2390 Include('/knobs', [2391 create_route('/', KnobManager.entry_get_knobs, method='GET'),2392 create_route('/{knobname}', KnobManager.entry_get_knob, method='GET'), # noqa: FS0032393 create_route('/{knobname}', KnobManager.entry_set_knob, method='PUT'), # noqa: FS0032394 create_route('/{knobname}', KnobManager.entry_delete_knob, method='DELETE') # noqa: FS0032395 ]),2396 create_route('/metrics', get_metrics),2397 create_route('/about', get_about),2398 Include('/_cache', [2399 Include('/pools/{poolname}', [ # noqa: FS0032400 create_route('/image-info', CacheManager.entry_pool_image_info),2401 create_route('/flavor-info', CacheManager.entry_pool_flavor_info)2402 ])2403 ]),2404 create_route('/_docs', OpenAPIUIHandler(schema_route_name=f'{name_prefix}OpenAPIUIHandler')),2405 create_route('/_schema', OpenAPIHandler(metadata=metadata))2406 ]2407#: API milestones: describes milestone API version, its route generator, and optionally also compatible2408#: API versions. Based on this list, routes are created with proper endpoints, and possibly redirected2409#: when necessary.2410API_MILESTONES: List[Tuple[str, RouteGeneratorOuterType, List[str]]] = [2411 # NEW: added hostname HW constraint2412 ('v0.0.38', generate_routes_v0_0_38, [2413 # For lazy clients who don't care about the version, our most current API version should add2414 # `/current` redirected to itself.2415 'current',2416 # For clients that did not switch to versioned API yet, keep top-level endpoints.2417 # TODO: this one's supposed to disappear once everyone switches to versioned API endpoints2418 'toplevel'2419 ]),...

Full Screen

Full Screen

test_create.py

Source:test_create.py Github

copy

Full Screen

1from datetime import datetime2from unittest.mock import patch, MagicMock3import pytest4from eternal_guesses.model.data.game import Game5from eternal_guesses.model.discord.discord_event import DiscordEvent, DiscordCommand6from eternal_guesses.model.discord.discord_member import DiscordMember7from eternal_guesses.repositories.games_repository import GamesRepositoryImpl, GamesRepository8from eternal_guesses.routes import create9from eternal_guesses.routes.create import CreateRoute10from eternal_guesses.util.discord_messaging import DiscordMessaging11from eternal_guesses.util.message_provider import MessageProvider12from tests.fakes import FakeDiscordMessaging, FakeGamesRepository13pytestmark = pytest.mark.asyncio14GAME_CREATED_MESSAGE = "Game created."15DUPLICATE_GAME_ID = "Duplicate game id."16@patch.object(create, 'datetime', autospec=True)17@patch.object(create, 'id_generator', autospec=True)18async def test_create_generated_id(mock_id_generator, mock_datetime):19 # Given20 guild_id = 100121 create_datetime = datetime.now()22 mock_datetime.now.return_value = create_datetime23 mock_games_repository = MagicMock(GamesRepositoryImpl, autospec=True)24 mock_games_repository.get.return_value = None25 mock_id_generator.game_id.return_value = "potatoific-tomatopuss"26 create_route = _route(games_repository=mock_games_repository)27 # When28 event = DiscordEvent(29 command=DiscordCommand(30 command_name="create",31 options={}32 ),33 guild_id=guild_id,34 member=DiscordMember()35 )36 response = await create_route.call(event)37 # Then38 mock_games_repository.save.assert_called()39 args = mock_games_repository.save.call_args40 game = args[0][0]41 assert game.guild_id == guild_id42 assert game.game_id == "potatoific-tomatopuss"43 assert game.create_datetime == create_datetime44 assert game.close_datetime is None45 assert game.closed is False46 assert response.is_ephemeral47 assert response.content == GAME_CREATED_MESSAGE48@patch.object(create, 'datetime', autospec=True)49async def test_create_given_id(mock_datetime):50 # Given51 guild_id = 100252 game_id = 'prolific-platypus'53 create_datetime = datetime.now()54 mock_datetime.now.return_value = create_datetime55 mock_games_repository = MagicMock(GamesRepositoryImpl, autospec=True)56 mock_games_repository.get.return_value = None57 create_route = _route(games_repository=mock_games_repository)58 # When59 event = DiscordEvent(60 command=DiscordCommand(61 command_name="create",62 options={63 'game-id': game_id64 }65 ),66 guild_id=guild_id,67 member=DiscordMember()68 )69 response = await create_route.call(event)70 # Then71 mock_games_repository.get.assert_called_with(guild_id, game_id)72 mock_games_repository.save.assert_called()73 args = mock_games_repository.save.call_args74 game = args[0][0]75 assert game.guild_id == guild_id76 assert game.game_id == game_id77 assert game.create_datetime == create_datetime78 assert game.close_datetime is None79 assert game.closed is False80 assert response.is_ephemeral81 assert response.content == GAME_CREATED_MESSAGE82async def test_create_duplicate_given_id():83 # Given: the games_repository will find a game for the given id84 guild_id = 100385 game_id = 'boonful-boonanza'86 existing_game = Game()87 existing_game.game_id = game_id88 mock_games_repository = MagicMock(GamesRepositoryImpl, autospec=True)89 mock_games_repository.get.return_value = existing_game90 create_route = _route(games_repository=mock_games_repository)91 # When92 event = DiscordEvent(93 command=DiscordCommand(94 command_name="create",95 options={96 'game-id': game_id97 }98 ),99 guild_id=guild_id100 )101 response = await create_route.call(event)102 # Then103 mock_games_repository.get.assert_called_with(guild_id, game_id)104 mock_games_repository.save.assert_not_called()105 assert response.is_ephemeral106 assert response.content == DUPLICATE_GAME_ID107async def test_create_sets_created_by_to_calling_user():108 # Given109 calling_user_id = 500110 mock_games_repository = MagicMock(GamesRepositoryImpl, autospec=True)111 mock_games_repository.get.return_value = None112 event = DiscordEvent(113 command=DiscordCommand(114 command_name="create",115 options={116 'game-id': 'game-id'117 }118 ),119 guild_id=1000,120 member=DiscordMember(121 user_id=calling_user_id122 )123 )124 # When125 create_route = _route(games_repository=mock_games_repository)126 await create_route.call(event)127 # Then128 args = mock_games_repository.save.call_args129 game = args[0][0]130 assert game.created_by == calling_user_id131async def test_create_sets_title_and_description():132 # Given133 title = "This is the title"134 description = "This is the description"135 mock_games_repository = MagicMock(GamesRepositoryImpl, autospec=True)136 mock_games_repository.get.return_value = None137 event = _make_event(description=description, title=title)138 # When139 create_route = _route(games_repository=mock_games_repository)140 response = await create_route.call(event)141 # Then142 args = mock_games_repository.save.call_args143 game = args[0][0]144 assert game.title == title145 assert game.description == description146 assert response.is_ephemeral147 assert response.content == GAME_CREATED_MESSAGE148async def test_create_with_min_max():149 # Given150 min_guess = 1151 max_guess = 20152 guild_id = 1153 game_id = 'game-with-min-max'154 games_repository = FakeGamesRepository()155 event = _make_event(guild_id=guild_id, game_id=game_id, min_guess=min_guess,156 max_guess=max_guess)157 # When158 create_route = _route(games_repository=games_repository)159 response = await create_route.call(event)160 # Then161 saved_game = games_repository.get(guild_id, game_id)162 assert saved_game.min_guess == min_guess163 assert saved_game.max_guess == max_guess164 assert response.is_ephemeral165 assert response.content == GAME_CREATED_MESSAGE166def _make_event(167 game_id: str = 'game-id',168 guild_id: int = -1,169 description: str = None,170 title: str = None,171 min_guess: int = None,172 max_guess: int = None,173):174 return DiscordEvent(175 command=DiscordCommand(176 command_name="create",177 options={178 'game-id': game_id,179 'min': min_guess,180 'max': max_guess,181 'title': title,182 'description': description,183 }184 ),185 guild_id=guild_id,186 member=DiscordMember(),187 )188def _route(games_repository: GamesRepository = None,189 discord_messaging: DiscordMessaging = None,190 message_provider: MessageProvider = None):191 if games_repository is None:192 games_repository = GamesRepository()193 if discord_messaging is None:194 discord_messaging = FakeDiscordMessaging()195 if message_provider is None:196 message_provider = MagicMock(MessageProvider)197 message_provider.game_created.return_value = GAME_CREATED_MESSAGE198 message_provider.duplicate_game_id.return_value = DUPLICATE_GAME_ID199 return CreateRoute(200 games_repository=games_repository,201 discord_messaging=discord_messaging,202 message_provider=message_provider,...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1from datetime import date, datetime2import calendar3from django.apps import apps4from django.http import HttpResponseRedirect, HttpResponse5from django.shortcuts import render6from django.urls import reverse7from customers.models import Customer8from .models import Employee9def index(request):10 Customer = apps.get_model('customers.Customer')11 customer = Customer.objects.all()12 context = {13 'customer': customer14 }15 return render(request, 'employees/index.html', context)16def registration(request):17 request.user18 try:19 new_employee = Employee.objects.get(user_id=user.id)20 context = {21 'new_employee' : new_employee22 }23 print("Employee.name has already been registered.")24 return render(request, 'employee/index.html', context)25 except:26 if request.method == 'POST':27 name = request.POST.get('name')28 route = request.POST.get('route')29 user = request.user30 new_employee = Employee(name=name, route=route, user=user)31 new_employee.save()32 return HttpResponseRedirect(reverse('employees:index'))33 else:34 return render(request, 'employees/register.html')35def daily_filter(request, does_pickup=None):36 user = request.user37 employee = Employee.objects.get(user_id=user.id)38 Customer = apps.get_model('customers.Customer')39 customers = Customer.objects.filter(zip_code=employee.route)40 my_date = date.today()41 now_calendar = date.today()42 create_route = []43 now_weekday = calendar.day_name[my_date.weekday()]44 int_weekday = date.today().weekday()45 for cust in customers:46 start_date = cust.start_suspension47 end_date = cust.end_suspension48 customer_weekday = cust.weekly_pickup_day49 if now_calendar.__lt__(start_date) and now_calendar.__gt__(end_date):50 if cust.onetime_pickup is not None:51 customer_onetime = datetime.weekday(cust.onetime_pickup)52 else:53 customer_onetime = None54 if customer_weekday == now_weekday or customer_onetime == int_weekday:55 create_route.append(cust)56 context = {57 'create_route': create_route58 }59 return render(request, 'employees/Daily Route.html', context)60def lookup(request, does_pickup=None):61 user = request.user62 employee = Employee.objects.get(user_id=user.id)63 Customer = apps.get_model('customers.Customer')64 customers = Customer.objects.filter(zip_code=employee.route)65 create_route = []66 context = {67 'create_route': create_route68 }69 if request.method == 'POST':70 my_date = request.POST.get('select date')71 # now_calendar = my_date72 # now_weekday = calendar.weekday(datetime.now())73 # int_weekday = my_date.weekday(my_date)74 for cust in customers:75 if cust.weekly_pickup_day == my_date:76 create_route.append(cust)77 # if my_date is not None:78 # datetimeobj = datetime.strptime(my_date, "%Y-%m-%d")79 # now_calendar = datetimeobj.date()80 # int_weekday = datetimeobj.weekday()81 # now_weekday = calendar.day_name[int_weekday]82 # for cust in customers:83 # start_date = cust.start_suspension84 # end_date = cust.end_suspension85 # customer_weekday = cust.weekly_pickup_day86 # if now_calendar.__lt__(start_date) and now_calendar.__gt__(end_date):87 # if cust.onetime_pickup is not None:88 # customer_onetime = datetime.weekday(cust.onetime_pickup)89 # else:90 # customer_onetime = None91 # if customer_weekday == now_weekday or customer_onetime == int_weekday:92 # create_route.append(cust)93 return render(request, 'employees/Daily Route.html', context)94 else:95 return render(request, 'employees/Route Lookup.html', context)96def confirm_pickup(request, user_id):97 charge_customer = Customer.objects.get(pk=user_id)98 context = {99 'charge_customer': charge_customer100 }101 if request.method == 'POST':102 charge_customer.balance += 10103 charge_customer.save()104 return HttpResponseRedirect(reverse('employees:daily'))105 else:106 return render(request, "employees/pickup_confirmation.html", context)107 # create format for onetime_pickup object108 # is_complete = False109 # try Customer.zip_code == .route:110 # is_complete = True111 # except Customer.zip_code += .route:112 # is_complete = False113 # return render(request, 'employees:confirm_pickup')114 pass115# utilizing boolean phrase is_complete116def charge_pickup(request):117 # if request.confirm_pickup == True:118 # Customer.balance += 5119 pass...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful