def test_widget_base_element_attribute_dispatches_when_view_exists():
    view = FakeDispatchView({'name': 'attr', 'selector': '#id', 'attr': 'hello', 'value': 'world'})

    b_elem = BaseElement(id='id')
    b_elem.view = view
    b_elem._set_attribute('hello', 'world')
    view.verify()
def test_widget_base_element_property_parent_setter_sets_view():
    fake_parent = BaseElement(id='id')
    fake_parent.view = 3

    b_elem = BaseElement(id='id2')
    b_elem.parent = fake_parent
    assert b_elem.view == 3, "BaseElement.parent should set the value of BaseElement.view to the parent's view"
def test_widget_base_container_clear_children_removes_all():
    container = BaseContainer(id='id')

    child_1 = BaseElement(id='id', parent=container)
    child_2 = BaseElement(id='id2', parent=container)

    assert len(container.children) == 2
    container.clear_children()
    assert len(container.children) == 0
def test_widget_base_container_replace_child_replaces_child():
    fake_parent = BaseContainer(id='id')

    b_elem_1 = BaseElement(id='id1', parent=fake_parent)
    b_elem_2 = BaseElement(id='id2')

    fake_parent.replace_child(b_elem_1, b_elem_2)

    assert len(fake_parent.children) == 1 and fake_parent.children[
        0] is b_elem_2, 'BaseContainer.replace_child() should replace the child in BaseContainer.children.'
def test_widget_base_container_replace_child_handles_parents():
    fake_parent = BaseContainer(id='id')

    b_elem_1 = BaseElement(id='id1', parent=fake_parent)
    b_elem_2 = BaseElement(id='id2')

    fake_parent.replace_child(b_elem_1, b_elem_2)

    assert b_elem_1.parent is None, "BaseContainer.replace_child() should unset the old child's parent."
    assert b_elem_2.parent is fake_parent, "BaseContainer.replace_child() should set the new child's parent."
Esempio n. 6
0
def test_widget_base_element_attribute_dispatches_when_view_exists():
    view = FakeDispatchView({
        'name': 'attr',
        'selector': '#id',
        'attr': 'hello',
        'value': 'world'
    })

    b_elem = BaseElement(id='id')
    b_elem.view = view
    b_elem._set_attribute('hello', 'world')
    view.verify()
def test_widget_base_container_add_child_dispatches_append():
    view_test = FakeDispatchView({
        'name': 'append',
        'html': '<x id="id">',
        'selector': '#id'
    })
    fake_parent = BaseContainer(id='id')
    fake_parent.view = view_test

    b_elem = BaseElement(id='id')
    b_elem.html_tag = 'x'
    b_elem.autoclosing = True

    fake_parent.add_child(b_elem)
    view_test.verify()
def test_widget_base_container_remove_child_dispatches_remove():
    view_test = FakeDispatchView({'name': 'remove', 'selector': '#id'})
    fake_parent = BaseContainer(id='id')

    b_elem = BaseElement(id='id')

    fake_parent.add_child(b_elem)
    fake_parent.view = view_test
    fake_parent.remove_child(b_elem)
    view_test.verify()
Esempio n. 9
0
def test_widget_base_element_property_parent_setter_sets_view():
    fake_parent = BaseElement(id='id')
    fake_parent.view = 3

    b_elem = BaseElement(id='id2')
    b_elem.parent = fake_parent
    assert b_elem.view == 3, "BaseElement.parent should set the value of BaseElement.view to the parent's view"
Esempio n. 10
0
def test_widget_base_container_compile_compiles_children():
    fake_parent = BaseContainer(id='id')
    fake_parent.html_tag = 'a'

    b_elem_1 = BaseElement(id='id1', parent=fake_parent)
    b_elem_2 = BaseElement(id='id2', parent=fake_parent)

    b_elem_1.html_tag = 'b'
    b_elem_2.html_tag = 'c'

    assert fake_parent.compile(
    ) == '<a id="id"><b id="id1"></b><c id="id2"></c></a>'
Esempio n. 11
0
def test_widget_base_element_remove_class_removes_class():
    b_elem = BaseElement(id='id', classname='hello')
    b_elem.remove_class('hello')
    assert len(b_elem._classes) == 0, 'BaseElement.remove_class() should delete specified class from BaseElement._classes.'
Esempio n. 12
0
def test_widget_base_element_property_id():
    b_elem = BaseElement(id='id')
    assert b_elem.id == 'id', 'BaseElement.id should return the value of internal BaseElement._attributes["id"]'
Esempio n. 13
0
def test_widget_base_element_property_parent_setter():
    fake_parent = BaseElement(id='id')

    b_elem = BaseElement(id='id2')
    b_elem.parent = fake_parent
    assert b_elem._parent is fake_parent, 'BaseElement.parent should set the value of internal BaseElement._parent'
Esempio n. 14
0
def test_widget_base_element_property_parent_getter():
    b_elem = BaseElement(id='id')
    assert b_elem.parent is b_elem._parent, 'BaseElement.parent should return the value of internal BaseElement._parent'
Esempio n. 15
0
def test_widget_base_element_property_id_setter():
    b_elem = BaseElement(id='id')
    b_elem.id = 'id2'
    assert b_elem.id == 'id2', 'BaseElement.id should set the value of BaseElement._attributes["id"]'
Esempio n. 16
0
def test_widget_base_element_doesnt_set_attribute_when_none():
    b_elem = BaseElement(id='id')
    b_elem._set_attribute('hello', None)
    assert 'hello' not in b_elem._attributes, 'BaseElement._set_attribute should do nothing when attribute value is None'
Esempio n. 17
0
def test_widget_base_element_compile_not_autoclosing():
    b_elem = BaseElement(id='a')
    b_elem.html_tag = 'x'
    b_elem.content = "b"
    assert b_elem.compile() == '<x id="a">b</x>'
Esempio n. 18
0
def test_widget_base_element_property_parent_setter():
    fake_parent = BaseElement(id='id')

    b_elem = BaseElement(id='id2')
    b_elem.parent = fake_parent
    assert b_elem._parent is fake_parent, 'BaseElement.parent should set the value of internal BaseElement._parent'
Esempio n. 19
0
def test_widget_base_element_sets_attributes():
    b_elem = BaseElement(id='id')
    b_elem._set_attribute('hello', 'there')
    assert b_elem._attributes.get('hello') == 'there', "BaseElement._set_attribute should set the specified attribute in BaseElement._attributes"
Esempio n. 20
0
def test_widget_base_element_remove_class_removes_class():
    b_elem = BaseElement(id='id', classname='hello')
    b_elem.remove_class('hello')
    assert len(
        b_elem._classes
    ) == 0, 'BaseElement.remove_class() should delete specified class from BaseElement._classes.'
Esempio n. 21
0
def test_widget_base_element_property_classname_getter():
    b_elem = BaseElement(id='hello', classname="hello")
    assert b_elem.classname == "hello", 'BaseElement.classname should return an aggregate of BaseElement._classes.'
Esempio n. 22
0
def test_widget_base_element_classname_is_set():
    b_elem = BaseElement(id='hello', classname="hello")
    err = 'BaseElement constructor should be able to set a class via the "classname" keyword arg.'

    assert len(b_elem._classes) == 1, err
    assert b_elem._classes[0] == "hello", err
Esempio n. 23
0
def test_widget_base_element_compile_autoclosing():
    b_elem = BaseElement(id='a')
    b_elem.html_tag = "x"
    b_elem.autoclosing = True
    assert b_elem.compile() == '<x id="a">'
Esempio n. 24
0
def test_widget_base_element_sets_attributes():
    b_elem = BaseElement(id='id')
    b_elem._set_attribute('hello', 'there')
    assert b_elem._attributes.get(
        'hello'
    ) == 'there', "BaseElement._set_attribute should set the specified attribute in BaseElement._attributes"
Esempio n. 25
0
def test_widget_base_element_doesnt_set_attribute_when_none():
    b_elem = BaseElement(id='id')
    b_elem._set_attribute('hello', None)
    assert 'hello' not in b_elem._attributes, 'BaseElement._set_attribute should do nothing when attribute value is None'
Esempio n. 26
0
def test_widget_base_element_compile_not_autoclosing():
    b_elem = BaseElement(id='a')
    b_elem.html_tag = 'x'
    b_elem.content = "b"
    assert b_elem.compile() == '<x id="a">b</x>'
Esempio n. 27
0
def test_widget_base_element_property_id_setter():
    b_elem = BaseElement(id='id')
    b_elem.id = 'id2'
    assert b_elem.id == 'id2', 'BaseElement.id should set the value of BaseElement._attributes["id"]'
Esempio n. 28
0
 def element(self):
     return BaseElement(id='id')
Esempio n. 29
0
def test_widget_base_element_compile_autoclosing():
    b_elem = BaseElement(id='a')
    b_elem.html_tag = "x"
    b_elem.autoclosing = True
    assert b_elem.compile() == '<x id="a">'
Esempio n. 30
0
def test_widget_base_element_property_view_getter():
    b_elem = BaseElement(id='id')
    assert b_elem.view is b_elem._view, 'BaseElement.view should return the value of internal BaseElement._view.'
Esempio n. 31
0
def test_widget_base_element_property_view_setter():
    b_elem = BaseElement(id='id')
    b_elem.view = 42
    assert b_elem._view == 42, 'BaseElement.view should set the value of internal BaseElement._view'
Esempio n. 32
0
def test_widget_base_element_property_view_setter():
    b_elem = BaseElement(id='id')
    b_elem.view = 42
    assert b_elem._view == 42, 'BaseElement.view should set the value of internal BaseElement._view'