예제 #1
0
def get_test_layout_and_svc():
    svc = SavedViewConfig(theme_identifier=FauxTheme.identifier,
                          view_name=printable_gibberish(),
                          status=SavedViewConfigStatus.CURRENT_DRAFT)
    layout = Layout("ph")
    layout.add_plugin("text", {"text": "hello"})
    svc.set_layout_data(layout.placeholder_name, layout)
    svc.save()
    return layout, svc
예제 #2
0
def get_test_layout_and_svc():
    svc = SavedViewConfig(
        theme_identifier=FauxTheme.identifier,
        view_name=printable_gibberish(),
        status=SavedViewConfigStatus.CURRENT_DRAFT
    )
    layout = Layout("ph")
    layout.add_plugin("text", {"text": "hello"})
    svc.set_layout_data(layout.placeholder_name, layout)
    svc.save()
    return layout, svc
예제 #3
0
    def get_placeholder_layout(self, placeholder_name, default_layout=None):
        """
        Get a Layout object for the given placeholder.

        :param placeholder_name: The name of the placeholder to load.
        :type placeholder_name: str
        :param default_layout: Default layout configuration (either a dict or an actual Layout)
        :type default_layout: dict|Layout
        :return: Layout
        :rtype: Layout
        """
        svc = self.saved_view_config
        if svc:
            placeholder_data = svc.get_layout_data(placeholder_name)
            if placeholder_data:
                return Layout.unserialize(data=placeholder_data, placeholder_name=placeholder_name)
        if default_layout:
            if isinstance(default_layout, Layout):
                return default_layout
            return Layout.unserialize(default_layout)
        return Layout(placeholder_name=placeholder_name)
예제 #4
0
def test_layout_serialization():
    with plugin_override():
        l = Layout("test")
        l.begin_column({"md": 8})
        l.add_plugin("text", {"text": "yes"})
        serialized = l.serialize()
        expected = {
            'name': "test",
            'rows': [
                {
                    'cells': [
                        {'config': {'text': 'yes'}, 'plugin': 'text', 'sizes': {"md": 8}}
                    ]
                }
            ]
        }
        assert serialized == expected
        assert Layout.unserialize(serialized).serialize() == expected
예제 #5
0
def test_layout_serialization():
    with plugin_override():
        l = Layout("test")
        l.begin_column({"md": 8})
        l.add_plugin("text", {"text": "yes"})
        serialized = l.serialize()
        expected = {
            'name': "test",
            'rows': [
                {
                    'cells': [
                        {'config': {'text': 'yes'}, 'plugin': 'text', 'sizes': {"md": 8}}
                    ]
                }
            ]
        }
        assert serialized == expected
        assert Layout.unserialize(serialized).serialize() == expected
예제 #6
0
def test_layout_api():
    l = Layout("test")
    l.begin_column({"md": 8})
    px0y0 = l.add_plugin("text", {"text": "yes"})
    l.begin_column({"md": 4})
    px1y0 = l.add_plugin("text", {"text": "no"})
    assert len(l) == 1
    assert len(l.rows[0]) == 2
    assert not l.delete_cell(x=0, y=1)  # nonexistent row
    assert l.get_cell(0, 0) == px0y0
    assert l.get_cell(1, 0) == px1y0
    assert not l.get_cell(2, 0)
    assert not l.get_cell(0, 1)
    l.begin_row()
    assert len(l) == 2
    assert len(l.rows[1]) == 0
    l.begin_column()
    assert len(l.rows[1]) == 1
    assert l.delete_cell(x=0, y=1)  # existent cell
    assert not l.delete_cell(x=0, y=1)  # cell existent no more
    assert l.delete_row(1)  # existent row
    assert len(l) == 1
    assert not l.delete_row(1)  # nonexistent row
    l.insert_row(0).add_cell()  # insert a cellful row in first place
    assert len(l) == 2 and list(map(len, l.rows)) == [1, 2]
    l.insert_row(1)  # insert an empty row in second place
    assert len(l) == 3 and list(map(len, l.rows)) == [1, 0, 2]
    assert not l.insert_row(-1)  # that's silly!
예제 #7
0
def test_layout_api():
    l = Layout("test")
    l.begin_column({"md": 8})
    px0y0 = l.add_plugin("text", {"text": "yes"})
    l.begin_column({"md": 4})
    px1y0 = l.add_plugin("text", {"text": "no"})
    assert len(l) == 1
    assert len(l.rows[0]) == 2
    assert not l.delete_cell(x=0, y=1)  # nonexistent row
    assert l.get_cell(0, 0) == px0y0
    assert l.get_cell(1, 0) == px1y0
    assert not l.get_cell(2, 0)
    assert not l.get_cell(0, 1)
    l.begin_row()
    assert len(l) == 2
    assert len(l.rows[1]) == 0
    l.begin_column()
    assert len(l.rows[1]) == 1
    assert l.delete_cell(x=0, y=1)  # existent cell
    assert not l.delete_cell(x=0, y=1)  # cell existent no more
    assert l.delete_row(1)  # existent row
    assert len(l) == 1
    assert not l.delete_row(1)  # nonexistent row
    l.insert_row(0).add_cell()  # insert a cellful row in first place
    assert len(l) == 2 and list(map(len, l.rows)) == [1, 2]
    l.insert_row(1)  # insert an empty row in second place
    assert len(l) == 3 and list(map(len, l.rows)) == [1, 0, 2]
    assert not l.insert_row(-1)  # that's silly!