Beispiel #1
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
 def test_field_recipe_calculation(self):
     definition = SimpleValue("${{5*3}}", "abc.yml", 10)
     repr(definition)
     f = FieldFactory("field", definition, "abc.yml", 10)
     repr(f)
     x = f.generate_value(standard_runtime())
     assert x == 15
Beispiel #3
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
 def test_field_recipe_int(self):
     definition = SimpleValue(5, "abc.yml", 10)
     repr(definition)
     f = FieldFactory("field", definition, "abc.yml", 10)
     repr(f)
     x = f.generate_value(standard_runtime())
     assert x == 5
 def test_mixed_jinja_syntax(self):
     definition = SimpleValue("${{2+3}} <<5*3>>", "abc.yml", 10)
     repr(definition)
     f = FieldFactory("field", definition, "abc.yml", 10)
     repr(f)
     x = f.generate_value(standard_runtime())
     assert x == "5 <<5*3>>"
 def test_structured_value(self):
     definition = StructuredValue(
         "random_choice",
         [SimpleValue("abc", "", 1), SimpleValue("def", "", 1)],
         "abc.yml",
         10,
     )
     repr(definition)
     f = FieldFactory("field", definition, "abc.yml", 10)
     x = f.generate_value(standard_runtime())
     assert x in ["abc", "def"]
 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())