Exemplo n.º 1
0
def store_rendered_templates(store, signal, sender, template, context, **kwargs):
    """
    Stores templates and contexts that are rendered.

    The context is copied so that it is an accurate representation at the time
    of rendering.
    """
    store.setdefault('templates', []).append(template)
    store.setdefault('context', ContextList()).append(copy(context))
Exemplo n.º 2
0
def store_rendered_templates(store, signal, sender, template, context, **kwargs):
    """
    Store templates and contexts that are rendered.

    The context is copied so that it is an accurate representation at the time
    of rendering.
    """
    store.setdefault("templates", []).append(template)
    if "context" not in store:
        store["context"] = ContextList()
    store["context"].append(copy(context))
Exemplo n.º 3
0
def store_rendered_templates(store, signal, sender, template, context,
                             **kwargs):
    """
    Stores templates and contexts that are rendered.

    The context is copied so that it is an accurate representation at the time
    of rendering.
    Entirely based on the Django Test Client
    https://github.com/django/django/blob/master/django/test/client.py#L88
    """
    store.setdefault('templates', []).append(template)
    store.setdefault('context', ContextList()).append(copy(context))
Exemplo n.º 4
0
 def __init__(self, test_case, template_name):
     self.test_case = test_case
     self.template_name = template_name
     self.rendered_templates = []
     self.rendered_template_names = []
     self.context = ContextList()
Exemplo n.º 5
0
    snapshot = Snapshot("test", data_dir=reference_file.dirname)
    reference_content = "FOO"
    reference_file.write(reference_content)
    assert snapshot.reference == reference_content


@pytest.mark.parametrize(
    "input, clean_output",
    [
        (None, None),
        ([], []),
        ({"foo": "bar"}, {"foo": "bar"}),
        ({"block": True, "forloop": False, "lastupdated": 1234}, {}),
        ([{"foo": "bar"}], [{"foo": "bar"}]),
        ([{"block": True}, {"forloop": False, "lastupdated": 1234}], [{}, {}]),
        (ContextList([Context({"foo": "bar"})]), {"foo": "bar"}),
        (ContextList([Context({"block": True})]), {}),
        (
            ContextList([Context({"block": True}), Context({"foo": "bar"})]),
            {"foo": "bar"},
        ),
        (RequestContext(None, {"foo": "bar"}), {"foo": "bar"}),
    ],
)
def test_snapshot_clean(input, clean_output):
    """Tests the cleanup of snapshot contexts."""
    snapshot = Snapshot("test")
    assert snapshot.clean(input) == clean_output


def test_snapshot_assert_matches_generate(tmpdir):
Exemplo n.º 6
0
 def setUp(self):
     self.templates = []
     self.contexts = ContextList()
     template_rendered.connect(self.store_rendered_template)