Skip to content

Commit

Permalink
Added Div() class for constructing <div></div> tag
Browse files Browse the repository at this point in the history
  • Loading branch information
bharadwajyarlagadda committed Sep 2, 2016
1 parent 34deaab commit 3b7ba75
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
37 changes: 28 additions & 9 deletions korona/html/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
dd_tag,
del_tag,
details_tag,
dialog_tag
dialog_tag,
div_tag
)

RECTANGLE_SHAPE_COORDINATES = 4
Expand Down Expand Up @@ -816,9 +817,7 @@ class Del(object):
def __init__(self, cite=None, datetime=None, text=None):
self.tag = 'del'
# TODO: If possible, add validation for attribute cite
self.values = {'cite': cite,
'datetime': datetime,
'text': text}
self.values = {'cite': cite, 'datetime': datetime, 'text': text}

def construct(self):
"""Returns the constructed del tag <del>."""
Expand All @@ -838,8 +837,7 @@ class Details(object):
"""
def __init__(self, open=False, text=None):
self.tag = 'details'
self.values = {'open': open,
'text': text}
self.values = {'open': open, 'text': text}

def construct(self):
"""Returns the constructed details tag <details>."""
Expand All @@ -852,16 +850,37 @@ class Dialog(object):
Args:
open (bool): Specifies that the dialog element is active and that the
user can interact with it.
text (str): Specifies the details text. (As in
text (str): Specifies the dialog text. (As in
<dialog>{text}</dialog>)
.. versionadded:: 0.2.0-alpha
"""
def __init__(self, open=False, text=None):
self.tag = 'dialog'
self.values = {'open': open,
'text': text}
self.values = {'open': open, 'text': text}

def construct(self):
"""Returns the constructed dialog tag <dialog>."""
return dialog_tag.render(self.values)


class Div(object):
"""Class for constructing div tag.
Args:
align (str): Specifies the alignment of the content inside a <div>
element.
text (str): Specifies the div text. (As in <div>{text}</div>)
.. versionadded:: 0.2.0-alpha
"""
def __init__(self, align=None, text=None):
self.tag = 'div'
validate_attribute_values(tag=self.tag,
attribute_name='align',
value=align)
self.values = {'align': align, 'text': text}

def construct(self):
"""Returns the constructed div tag <div>."""
return div_tag.render(self.values)
31 changes: 29 additions & 2 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
DD,
Del,
Details,
Dialog
Dialog,
Div
)
from korona.templates.html import (
anchor_tag,
Expand All @@ -40,7 +41,8 @@
dd_tag,
del_tag,
details_tag,
dialog_tag
dialog_tag,
div_tag
)
from korona.lib.utils import validate_tag

Expand Down Expand Up @@ -567,3 +569,28 @@ def test_construct_dialog_tag(attributes):
"""
dialog = Dialog(**attributes)
assert dialog.construct() == dialog_tag.render(attributes)


@parametrize('attributes', [
({'align': 'left'}),
({'text': 'abcd'}),
({'align': 'right', 'text': 'abcd'})
])
def test_construct_div_tag(attributes):
"""Test for validating whether the div tag is constructed correctly or not.
"""
div = Div(**attributes)
assert div.construct() == div_tag.render(attributes)


@parametrize('attributes,exception,error_msg', [
({'align': 'abcd'},
AttributeError,
'attribute values should be one of these')
])
def test_construct_div_tag_error(attributes, exception, error_msg):
"""Test for validating div tag's attributes."""
with pytest.raises(exception) as exc:
Div(**attributes)

assert error_msg in str(exc)

0 comments on commit 3b7ba75

Please sign in to comment.