Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _make_namespace(ns_name="accounts"):
# type: (typing.Text) -> ApiNamespace
ns = ApiNamespace(ns_name)
struct = _make_struct('User', 'exists', ns)
ns.add_data_type(struct)
return ns
def _make_namespace_with_route_name_conflict():
# type: (...) -> ApiNamespace
ns = ApiNamespace("_make_namespace_with_route()")
mock_ast_node = Mock()
route_one = ApiRoute(
name="route_one_v2",
version=1,
ast_node=mock_ast_node,
)
route_two = ApiRoute(
name="route_one",
version=2,
ast_node=mock_ast_node,
)
ns.add_route(route_one)
ns.add_route(route_two)
return ns
def test_api_namespace(self):
ns = ApiNamespace('files')
a1 = Struct('A1', None, ns)
a1.set_attributes(None, [StructField('f1', Boolean(), None, None)])
a2 = Struct('A2', None, ns)
a2.set_attributes(None, [StructField('f2', Boolean(), None, None)])
l1 = List(a1)
s = String()
route = ApiRoute('test/route', 1, None)
route.set_attributes(None, None, l1, a2, s, None)
ns.add_route(route)
# Test that only user-defined types are returned.
route_io = ns.get_route_io_data_types()
self.assertIn(a1, route_io)
self.assertIn(a2, route_io)
self.assertNotIn(l1, route_io)
self.assertNotIn(s, route_io)
def _mk_route_schema(self):
s = Struct('Route', ApiNamespace('stone_cfg'), None)
s.set_attributes(None, [], None)
return s
def _make_namespace_with_route():
# type: (...) -> ApiNamespace
ns = ApiNamespace("_make_namespace_with_route()")
mock_ast_node = Mock()
route_one = ApiRoute(
name="route_one",
version=1,
ast_node=mock_ast_node,
)
route_two = ApiRoute(
name="route_one",
version=2,
ast_node=mock_ast_node,
)
ns.add_route(route_one)
ns.add_route(route_two)
return ns
def test_route_with_auth_mode1(self):
# type: () -> None
route1 = ApiRoute('get_metadata', 1, None)
route1.set_attributes(None, ':route:`get_metadata:2`', Void(), Void(), Void(),
{'auth': 'app'})
route2 = ApiRoute('get_metadata', 2, None)
route2.set_attributes(None, None, Void(), Int32(), Void(),
{'auth': 'user, app'})
ns = ApiNamespace('files')
ns.add_route(route1)
ns.add_route(route2)
result = self._evaluate_namespace_with_auth_mode(ns, 'user')
expected = textwrap.dedent('''\
# ------------------------------------------
# Routes in files namespace
def files_get_metadata_v2(self):
arg = None
r = self.request(
files.get_metadata_v2,
'files',
arg,
None,
def test_union(self):
ns = ApiNamespace('files')
update_parent_rev = Struct(
'UpdateParentRev',
None,
ns,
)
update_parent_rev.set_attributes(
"Overwrite existing file if the parent rev matches.",
[
StructField('parent_rev', String(), 'The revision to be updated.', None)
],
)
update_parent_rev._add_example(
AstExample(
path=None,
lineno=None,
def _get_api(self):
# type () -> Api
api = Api(version='0.1b1')
api.route_schema = Struct(u'Route', 'stone_cfg', None)
route1 = ApiRoute('get_metadata', 1, None)
route1.set_attributes(None, ':route:`get_metadata`', Void(), Void(), Void(), {})
route2 = ApiRoute('get_metadata', 2, None)
route2.set_attributes(None, ':route:`get_metadata:2`', Void(), Int32(), Void(), {})
ns = ApiNamespace('files')
ns.add_route(route1)
ns.add_route(route2)
api.namespaces[ns.name] = ns
return api, ns
def _make_namespace_with_alias():
# type: (...) -> ApiNamespace
ns = ApiNamespace('ns_with_alias')
struct1 = Struct(name='Struct1', namespace=ns, ast_node=None)
struct1.set_attributes(None, [StructField('f1', Boolean(), None, None)])
ns.add_data_type(struct1)
alias = Alias(name='AliasToStruct1', namespace=ns, ast_node=None)
alias.set_attributes(doc=None, data_type=struct1)
ns.add_alias(alias)
str_type = String(min_length=3)
str_alias = Alias(name='NotUserDefinedAlias', namespace=ns, ast_node=None)
str_alias.set_attributes(doc=None, data_type=str_type)
ns.add_alias(str_alias)
return ns