当前位置: 首页>>代码示例>>Python>>正文


Python helpers.FakeArgs类代码示例

本文整理汇总了Python中helpers.FakeArgs的典型用法代码示例。如果您正苦于以下问题:Python FakeArgs类的具体用法?Python FakeArgs怎么用?Python FakeArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FakeArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_singularize

    def test_singularize(self):
        proto = \
"""
  message TestSingularize {
      // The following field has an explicitly specified singular
      required int many = 1 [singular = "one"];
      // The following fields have automatically computed singulars
      required int sheep = 2;
      required int radii = 2;
      required int slices = 2;
      required int networks = 2;
      required int omf_friendlies = 2;
  }
"""

        target = XProtoTestHelpers.write_tmp_target(
"""
{% for m in proto.messages.0.fields -%}
{{ xproto_singularize(m) }},
{%- endfor %}
""")
        args = FakeArgs()
        args.inputs = proto
        args.target = target
        output = XOSGenerator.generate(args)
        self.assertEqual("one,sheep,radius,slice,network,omf_friendly", output.lstrip().rstrip().rstrip(','))
开发者ID:vpramo,项目名称:xos-1,代码行数:26,代码来源:target_test.py

示例2: test_pluralize

    def test_pluralize(self):
        proto = \
"""
  message TestPluralize {
      // The following field has an explicitly specified plural
      required int anecdote = 1 [plural = "data"];
      // The following fields have automatically computed plurals
      required int sheep = 2;
      required int radius = 2;
      required int slice = 2;
      required int network = 2;
      required int omf_friendly = 2;
  }
"""

        target = XProtoTestHelpers.write_tmp_target(
"""
{% for m in proto.messages.0.fields -%}
{{ xproto_pluralize(m) }},
{%- endfor %}
""")
        args = FakeArgs()
        args.inputs = proto
        args.target = target
        output = XOSGenerator.generate(args)
        self.assertEqual("data,sheep,radii,slices,networks,omf_friendlies", output.lstrip().rstrip().rstrip(','))
开发者ID:vpramo,项目名称:xos-1,代码行数:26,代码来源:target_test.py

示例3: test_user_policy

    def test_user_policy(self):
        xproto = \
"""
    policy test_policy <
         ctx.user.is_admin
         | ctx.user.id = obj.id
         | (exists Privilege: 
             Privilege.accessor_id = ctx.user.id
             & Privilege.accessor_type = "User"
             & Privilege.permission = "role:admin"
             & Privilege.object_type = "Site"
             & Privilege.object_id = ctx.user.site.id) >
"""
        args = FakeArgs()
        args.inputs = xproto
        args.target = self.target

        output = XOSGenerator.generate(args)

        exec(output) # This loads the generated function, which should look like this:

        """
        def policy_output_enforcer(obj, ctx):
            i2 = ctx.user.is_admin
            i4 = (ctx.user.id == obj.id)
            i5 = Privilege.objects.filter(Q(accessor_id=ctx.user.id), Q(accessor_type='User'), Q(permission='role:admin'), Q(object_type='Site'), Q(object_id=ctx.user.site.id))[0]
            i3 = (i4 or i5)
            i1 = (i2 or i3)
            return i1
        """

        # FIXME: Test this policy by executing it
        self.assertTrue(policy_output_enforcer is not None)
开发者ID:vpramo,项目名称:xos-1,代码行数:33,代码来源:xos_security_test.py

示例4: test_basic_proto

    def test_basic_proto(self):
        xtarget = XProtoTestHelpers.write_tmp_target("{{ proto }}")

        xproto = \
"""
message Person {
  required string name = 1;
  required int32 id = 2;  // Unique ID number for this person.
  optional string email = 3 [symphony = "da da da dum"];

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  required  string number = 1;
  optional PhoneType type = 2;

  repeated PhoneNumber phones = 4;
}
"""
        args = FakeArgs()
        args.inputs = xproto
        args.target = xtarget
        output = XOSGenerator.generate(args)
        self.assertIn("PhoneNumber", output)
开发者ID:vpramo,项目名称:xos-1,代码行数:27,代码来源:parse_test.py

示例5: test_one_to_many_in_modeldef

    def test_one_to_many_in_modeldef(self):
        xproto = \
"""
option app_label = "test";

message ServiceDependency {
    required manytoone provider_service->Service:provided_dependencies = 1;
    required manytoone subscriber_service->Service:subscribed_dependencies = 2;
}

message Service {
    required string name = 1;
}
"""

        args = FakeArgs()
        args.inputs = xproto
        args.target = 'modeldefs.xtarget'
        output = XOSGenerator.generate(args)
        # Service deps model
        self.assertIn('{model: Service, type: manytoone, on_field: provider_service}', output)
        self.assertIn('{model: Service, type: manytoone, on_field: provider_service}', output)

        # Service model
        self.assertIn('{model: ServiceDependency, type: onetomany, on_field: provider_service}', output)
        self.assertIn('{model: ServiceDependency, type: onetomany, on_field: provider_service}', output)
开发者ID:vpramo,项目名称:xos-1,代码行数:26,代码来源:translator_test.py

示例6: test_field_graph

    def test_field_graph(self):
        xproto = \
"""
message VRouterDevice (PlCoreBase){
     optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True, unique_with="openflow_id"];
     required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False, unique_with="name"];
     required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False, unique_with="driver"];
     required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False, unique_with="vrouter_service"];
     required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False];
     required string A = 6 [unique_with="B"];
     required string B = 7 [unique_with="C"];
     required string C = 8 [unique_with="A"];
     required string D = 9;
     required string E = 10 [unique_with="F,G"];
     required string F = 11;
     required string G = 12;
}
"""
	target = XProtoTestHelpers.write_tmp_target(
"""
{{ xproto_field_graph_components(proto.messages.0.fields) }}
""")

        args = FakeArgs()
        args.inputs = xproto
        args.target = target
        output = XOSGenerator.generate(args)
        output =  eval(output)
        self.assertIn({'A','B','C'}, output)
        self.assertIn({'openflow_id','name'}, output)
        self.assertIn({'config_key','vrouter_service','driver'}, output)
        self.assertIn({'E','F','G'}, output)
        
        union = reduce(lambda acc,x: acc | x, output)
        self.assertNotIn('D', union) 
开发者ID:vpramo,项目名称:xos-1,代码行数:35,代码来源:field_graph_test.py

示例7: test_xproto_lib

    def test_xproto_lib(self):
        target = XProtoTestHelpers.write_tmp_target(
"""
  {{ xproto_first_non_empty([None, None, None, None, None, None, "Eureka"]) }}
""")
        args = FakeArgs()
        args.inputs = ''
        args.target = target
        output = XOSGenerator.generate(args)
        self.assertIn("Eureka", output)
开发者ID:vpramo,项目名称:xos-1,代码行数:10,代码来源:target_test.py

示例8: test_context

    def test_context(self):
        target = XProtoTestHelpers.write_tmp_target(
"""
  {{ context.what }}
""")
        args = FakeArgs()
        args.inputs = ''
        args.target = target
        args.kv='what:what is what'
        output = XOSGenerator.generate(args)
        self.assertIn("what is what", output)
开发者ID:vpramo,项目名称:xos-1,代码行数:11,代码来源:target_test.py

示例9: test_slice_policy

    def test_slice_policy(self):
        xproto = \
"""
   policy site_policy <
            ctx.user.is_admin
            | (ctx.write_access -> exists Privilege: Privilege.object_type = "Site" & Privilege.object_id = obj.id & Privilege.accessor_id = ctx.user.id & Privilege.permission_id = "role:admin") >

   policy test_policy <
         ctx.user.is_admin
         | (*site_policy(site)
         & ((exists Privilege:
             Privilege.accessor_id = ctx.user.id
             & Privilege.accessor_type = "User"
             & Privilege.object_type = "Slice"
             & Privilege.object_id = obj.id
             & (ctx.write_access->Privilege.permission="role:admin"))
           | (exists Privilege:
             Privilege.accessor_id = ctx.user.id
             & Privilege.accessor_type = "User"
             & Privilege.object_type = "Site"
             & Privilege.object_id = obj.site.id
             & Privilege.permission = "role:admin"))
            )>
    
"""
        args = FakeArgs()
        args.inputs = xproto
        args.target = self.target

        output = XOSGenerator.generate(args)

        exec(output) # This loads the generated function, which should look like this:

        """
        def policy_output_enforcer(obj, ctx):
	    i2 = ctx.user.is_admin
	    i4 = policy_site_policy_enforcer(obj.site, ctx)
	    i10 = ctx.write_access
	    i11 = (not (not Privilege.objects.filter(Q(accessor_id=ctx.user.id), Q(accessor_type='User'), Q(object_type='Slice'), Q(object_id=obj.id), Q(permission='role:admin'))))
	    i8 = (i10 and i11)
	    i14 = ctx.write_access
	    i12 = (not i14)
	    i13 = (not (not Privilege.objects.filter(Q(accessor_id=ctx.user.id), Q(accessor_type='User'), Q(object_type='Slice'), Q(object_id=obj.id))))
	    i9 = (i12 and i13)
	    i6 = (i8 or i9)
	    i7 = (not (not Privilege.objects.filter(Q(accessor_id=ctx.user.id), Q(accessor_type='User'), Q(object_type='Site'), Q(object_id=obj.site.id), Q(permission='role:admin'))))
	    i5 = (i6 or i7)
	    i3 = (i4 and i5)
	    i1 = (i2 or i3)
	    return i1
        """

        # FIXME: Test this policy by executing it
        self.assertTrue(policy_output_enforcer is not None)
开发者ID:vpramo,项目名称:xos-1,代码行数:54,代码来源:xos_security_test.py

示例10: test_through_extensions

    def test_through_extensions(self):
        xtarget = XProtoTestHelpers.write_tmp_target("{{ proto.messages.0.links.0.through }}")
        xproto = \
"""
message links {
    required manytomany vrouter_service->VRouterService/ServiceProxy:device_ports = 4 [db_index = True, null = False, blank = False];
}
"""
        args = FakeArgs()
        args.inputs = xproto
        args.target = xtarget
        output = XOSGenerator.generate(args)
        self.assertIn("ServiceProxy", output)
开发者ID:vpramo,项目名称:xos-1,代码行数:13,代码来源:parse_test.py

示例11: test_proto_generator

    def test_proto_generator(self):
        """
        [XOS-GenX] Generate DJANGO models, verify Fields and Foreign Keys
        """
        args = FakeArgs()
        args.files = [VROUTER_XPROTO]
        args.target = 'django.xtarget'
        output = XOSGenerator.generate(args)

        fields = filter(lambda s:'Field(' in s, output.splitlines())
        self.assertEqual(len(fields), 2)
        links = filter(lambda s:'Key(' in s, output.splitlines())
        self.assertEqual(len(links), 2)
开发者ID:vpramo,项目名称:xos-1,代码行数:13,代码来源:django_generator_test.py

示例12: test_message_base

    def test_message_base(self):
        xtarget = XProtoTestHelpers.write_tmp_target("{{ proto.messages.0.bases }}")
        xproto = \
"""
message base(Base) {
}
"""

        args = FakeArgs()
        args.inputs = xproto
        args.target = xtarget
        output = XOSGenerator.generate(args)
        self.assertIn("Base", output)
开发者ID:vpramo,项目名称:xos-1,代码行数:13,代码来源:parse_test.py

示例13: test_constant

    def test_constant(self):
        xproto = \
"""
    policy true_policy < True >
"""

        target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.true_policy }}")

        args = FakeArgs()
        args.inputs = xproto
        args.target = target

        output = XOSGenerator.generate(args).replace('t','T')
        self.assertTrue(eval(output)) 
开发者ID:vpramo,项目名称:xos-1,代码行数:14,代码来源:policy_test.py

示例14: test_policy_missing_function

    def test_policy_missing_function(self):
        xproto = \
"""
    policy slice_policy < exists Privilege: Privilege.object_id = obj.id >
    policy network_slice_policy < *slice_policyX(slice) >
"""

        target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.network_slice_policy }} ")
        args = FakeArgs()
        args.inputs = xproto
        args.target = target

        with self.assertRaises(Exception):
            output = XOSGenerator.generate(args)
开发者ID:vpramo,项目名称:xos-1,代码行数:14,代码来源:policy_test.py

示例15: test_file_methods

    def test_file_methods(self):
        target = XProtoTestHelpers.write_tmp_target(
"""
  {%% if file_exists("%s") %%}
    {{ include_file("%s") }}
  {%% endif %%}
"""%(TEST_FILE, TEST_FILE)
        )

        args = FakeArgs()
        args.inputs = ''
        args.target = target
        args.attic = OUTPUT_DIR
        output = XOSGenerator.generate(args)
        self.assertIn(TEST_OUTPUT, output)
开发者ID:vpramo,项目名称:xos-1,代码行数:15,代码来源:target_test.py


注:本文中的helpers.FakeArgs类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。