Ejemplo n.º 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
Ejemplo n.º 2
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_structured_value_errors(self):
        with pytest.raises(DataGenError) as e:
            StructuredValue("this.that.foo", [], **line).render(standard_runtime())
        assert "only one" in str(e.value)

        with pytest.raises(DataGenError) as e:
            StructuredValue("bar", [], **line).render(standard_runtime())
        assert "Cannot find func" in str(e.value)
        assert "bar" in str(e.value)

        with pytest.raises(DataGenError) as e:
            StructuredValue("xyzzy.abc", [], **line).render(standard_runtime())
        assert "Cannot find defini" in str(e.value)
        assert "xyzzy" in str(e.value)

        with pytest.raises(DataGenError) as e:
            StructuredValue("this.abc", [], **line).render(standard_runtime())
        assert "Cannot find defini" in str(e.value)
        assert "abc" in str(e.value)
 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"]