def test_fail_render_weird_type(self):
     with self.assertRaises((DataGenError, TypeError)):
         o = ObjectTemplate(
             "abcd",
             filename="abc.yml",
             line_num=10,
             fields=[
                 FieldFactory(
                     "x",
                     SimpleValue(b"junk", filename="abc.yml", line_num=42),
                     **line)
             ],
         )
         o.generate_rows(DebugOutputStream(), standard_runtime())
 def test_fail_render_weird_template(self):
     with pytest.raises(DataGenError):
         o = ObjectTemplate(
             "abcd",
             filename="abc.yml",
             line_num=10,
             fields=[
                 FieldFactory(
                     "x",
                     SimpleValue("${{5()}}", filename="abc.yml", line_num=42),
                     **line
                 )
             ],
         )
         o.generate_rows(DebugOutputStream(), standard_runtime())
Пример #3
0
    def _generate_psa(self, context, line_info, name):
        fields = {"AssigneeId": ("Use")}

        query = f"PermissionSet where Name = '{name}'"

        fields = [
            FieldFactory(
                "PermissionSetId",
                StructuredValue("SalesforceQuery.find_record", {"from": query},
                                **line_info),
                **line_info,
            ),
            FieldFactory(
                "AssigneeId",
                StructuredValue("reference", ["User"], **line_info),
                **line_info,
            ),
        ]

        new_template = ObjectTemplate(
            "PermissionSetAssignment",
            filename=line_info["filename"],
            line_num=line_info["line_num"],
            fields=fields,
        )
        context.register_template(new_template)
        return new_template
Пример #4
0
    def _render_person_contact(self, context, sobj, nickname, line_info):
        """Generate the code to render a person contact as CCI expects.

        Code generation is a better strategy for this than a runtime
        plugin because some analysis of the table structures happens
        at parse time.
        """
        fields = [
            FieldFactory(
                "IsPersonAccount",
                SimpleValue("true", **line_info),
                **line_info,
            ),
            FieldFactory(
                "AccountId",
                StructuredValue("reference", ["Account"], **line_info),
                **line_info,
            ),
        ]
        new_template = ObjectTemplate(
            sobj,
            filename=line_info["filename"],
            line_num=line_info["line_num"],
            nickname=nickname,
            fields=fields,
        )
        context.register_template(new_template)
        return new_template
Пример #5
0
    def PermissionSetAssignments(self, context, args) -> ObjectTemplate:
        names = args.get("names")
        if not isinstance(names, str):
            raise DataGenValueError(
                f"string `names` not specified for PermissionSetAssignments: {names}"
            )
        names = names.split(",")
        line_info = context.line_num()
        decls = [
            self._generate_psa(context, line_info, name) for name in names
        ]

        return ObjectTemplate(
            "__wrapper_for_permission_sets",
            filename=line_info["filename"],
            line_num=line_info["line_num"],
            friends=decls,
        )
 def test_fail_render_object_template(self):
     o = ObjectTemplate("abcd", filename="abc.yml", line_num=10)
     with pytest.raises(DataGenError):
         o.generate_rows(None, standard_runtime())
 def test_render_empty_object_template(self):
     o = ObjectTemplate("abcd", filename="abc.yml", line_num=10)
     o.generate_rows(DebugOutputStream(), standard_runtime())
 def test_check_type(self):
     o = ObjectTemplate("abcd", filename="abc.yml", line_num=10)
     field = mock.MagicMock()
     field.name = "foo"
     with pytest.raises(DataGenValueError):
         o._check_type(field, int, standard_runtime())