Beispiel #1
0
    def test_duplicate_copies_fresh_cache(self):
        # The cache's filename depends on workflow_id and step_id.
        # Duplicating it would need more complex code :).
        table = make_table(make_column("A", [1], format="${:,.2f}"))
        write_to_rendercache(
            self.workflow,
            self.step,
            1,
            table=table,
            errors=[RenderError(I18nMessage("X", {}, None))],
            json={"foo": "bar"},
        )

        workflow2 = Workflow.objects.create()
        tab2 = workflow2.tabs.create(position=0)
        dup = self.step.duplicate_into_new_workflow(tab2)

        dup_cached_result = dup.cached_render_result
        self.assertEqual(
            dup_cached_result,
            replace(
                self.step.cached_render_result,
                workflow_id=workflow2.id,
                step_id=dup.id,
                delta_id=0,
            ),
        )
        with open_cached_render_result(dup_cached_result) as result2:
            assert_arrow_table_equals(result2.table, table)
            self.assertEqual(result2.errors,
                             [RenderError(I18nMessage("X", {}, None))])
            self.assertEqual(result2.json, {"foo": "bar"})
Beispiel #2
0
def test_assert_result_equals_ok():
    table1 = make_table(make_column("A", [1]))
    table2 = make_table(make_column("A", [1]))
    assert_result_equals(
        ArrowRenderResult(
            table1,
            errors=[RenderError(I18nMessage("foo", {}, "module"))],
            json={"foo": "bar"},
        ),
        ArrowRenderResult(
            table2,
            errors=[RenderError(I18nMessage("foo", {}, "module"))],
            json={"foo": "bar"},
        ),
    )
Beispiel #3
0
def test_assert_result_equals_check_errors():
    with pytest.raises(AssertionError, match=r"-\[Render.*\n\+\[\]"):
        assert_result_equals(
            ArrowRenderResult(make_table()),
            ArrowRenderResult(
                make_table(),
                errors=[RenderError(I18nMessage("foo", {}, "module"))]),
        )
    def test_render_result(self):
        error = RenderError(
            message=I18nMessage("x", {"y": 1}, "module"),
            quick_fixes=[
                QuickFix(
                    button_text=I18nMessage("z", {}, "module"),
                    action=QuickFixAction.PrependStep("converttotext",
                                                      {"a": "b"}),
                )
            ],
        )  # we're testing it is serialized+deserialized correctly

        def render_arrow_v1(table, params, **kwargs):
            return ArrowRenderResult(make_table(make_column("A", ["x"])),
                                     [error])

        with ModuleTestEnv(render_arrow_v1=render_arrow_v1) as env:
            outcome = env.call_render(make_table(), {})
            self.assertEqual(outcome.result, RenderResult([error]))
Beispiel #5
0
def thrift_i18n_message_to_arrow(value: ttypes.I18nMessage) -> I18nMessage:
    if value.source not in [None, "module", "cjwmodule", "cjwparse"]:
        raise ValueError("Invalid message source %r" % value.source)
    return I18nMessage(
        value.id,
        {
            k: _thrift_i18n_argument_to_arrow(v)
            for k, v in value.arguments.items()
        },
        value.source,
    )
Beispiel #6
0
    def test_delete_step(self):
        write_to_rendercache(
            self.workflow,
            self.step,
            1,
            table=make_table(make_column("A", [1])),
            errors=[RenderError(I18nMessage("X", {}, None), [])],
            json={"foo": "bar"},
        )

        parquet_key = crr_parquet_key(self.step.cached_render_result)
        self.step.delete()
        self.assertFalse(s3.exists(BUCKET, parquet_key))
    def test_render_fetch_result_errors(self):
        def render_arrow_v1(table, params, *, fetch_result, **kwargs):
            self.assertEqual(fetch_result.errors,
                             [FetchError(I18nMessage("foo", {}, "cjwmodule"))])
            return ArrowRenderResult(make_table())

        with ModuleTestEnv(render_arrow_v1=render_arrow_v1) as env:
            with tempfile_context(dir=env.basedir) as tf:
                env.call_render(
                    make_table(),
                    {},
                    fetch_result=FetchResult(
                        Path(tf.name),
                        [FetchError(I18nMessage("foo", {}, "cjwmodule"))]),
                )
 def render_arrow_v1(table, params, *, fetch_result, **kwargs):
     self.assertEqual(fetch_result.errors,
                      [FetchError(I18nMessage("foo", {}, "cjwmodule"))])
     return ArrowRenderResult(make_table())