Skip to content

Commit

Permalink
Removed validate_string methods from all the classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bharadwajyarlagadda committed Aug 28, 2016
1 parent 299ba5f commit 7dab5a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
34 changes: 4 additions & 30 deletions korona/html/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@ def __init__(self,

# Series of validation methods for validating all the attribute values
# given.
self.validate_string(value=charset)
validate_tag_attribute_value(tag=self.tag, value=charset)
coordinates = self.get_coords(shape=shape, coords=coords)
self.pre_validate(href=href, attribute_name='download', value=download)
self.validate_string(value=href)
# Validate href link
self.pre_validate(href=href, attribute_name='hreflang', value=hreflang)
self.validate_string(value=name)
self.validate_values(href=href, attribute_name='rel', value=rel)
self.validate_values(href=href, attribute_name='rev', value=rev)
self.validate_values(href=href, attribute_name='shape', value=shape)
self.validate_string(value=target)
self.pre_validate(href=href, attribute_name='type', value=type)

# Assign all the values in a dictionary.
Expand All @@ -93,15 +91,6 @@ def construct_tag(self):
"""Returns the constructed anchor tag <a></a>."""
return anchor_tag.render(self.values)

def validate_string(self, value):
"""Validates whether the given value is a string or not."""
if not value:
return

# If the attribute value is not a string raise a ValueError.
if not isinstance(value, str):
raise ValueError('<a>: {0} should be a string'.format(value))

def get_coords(self, shape, coords):
"""Returns coordinates after a series of validations.
Expand Down Expand Up @@ -151,9 +140,6 @@ def pre_validate(self, href, attribute_name, value):
'href attribute is set.'
.format(attribute_name))

if not isinstance(value, str):
raise ValueError('<a>: {0} should be a string'.format(value))

def validate_values(self, href, attribute_name, value):
"""Validates whether the given attribute value is a valid value or not.
Some of the attributes have confined values. Even if we give some
Expand Down Expand Up @@ -261,12 +247,12 @@ def __init__(self,
self.validate_alt(href=href, attribute_name='alt', value=alt)
coordinates = self.get_coords(shape=shape, coords=coords)
self.pre_validate(href=href, attribute_name='download', value=download)
self.validate_string(value=href)
# Add validation for href link
self.pre_validate(href=href, attribute_name='hreflang', value=hreflang)
self.pre_validate(href=href, attribute_name='media', value=media)
self.validate_values(href=href, attribute_name='rel', value=rel)
self.validate_values(href=href, attribute_name='shape', value=shape)
self.pre_validate(href=href, attribute_name='targte', value=target)
self.pre_validate(href=href, attribute_name='target', value=target)
self.pre_validate(href=href, attribute_name='type', value=type)
self.values = {'alt': alt,
'coords': coordinates,
Expand All @@ -284,15 +270,6 @@ def construct_tag(self):
"""Returns the constructed area tag <area></area>."""
return area_tag.render(self.values)

def validate_string(self, value):
"""Validates whether the given value is a string or not."""
if not value:
return

# If the attribute value is not a string raise a ValueError.
if not isinstance(value, str):
raise ValueError('<area>: {0} should be a string'.format(value))

def validate_alt(self, href, attribute_name, value):
"""Validates area's alt attribute."""
if href and not value:
Expand All @@ -305,9 +282,6 @@ def validate_alt(self, href, attribute_name, value):
'href attribute is set.'
.format(attribute_name))

if value and not isinstance(value, str):
raise ValueError('<area>: {0} should be a string'.format(value))

def pre_validate(self, href, attribute_name, value):
"""Validates whether an attribute is dependant on another attribute or
not. Some of the attributes requires href attribute to be set.
Expand Down
7 changes: 0 additions & 7 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def test_construct_anchor_tag_coords(attributes):
@parametrize('attributes,exception,error_msg', [
({'rel': 1}, AttributeError, 'only used when href attribute is set.'),
({'type': 1}, AttributeError, 'only used when href attribute is set.'),
({'href': 'abc', 'type': 1}, ValueError, 'should be a string'),
({'charset': 1}, ValueError, 'should be a string'),
({'rel': 1, 'href': 'www.google.com'}, ValueError, 'should be a string'),
({'shape': 'circle', 'coords': [1, 2, 3, 4]},
Expand Down Expand Up @@ -244,9 +243,6 @@ def test_construct_area_tag_coords(attributes):
({'href': 'abc', 'alt': 'abc', 'download': 123},
ValueError,
'should be a string'),
({'href': 123, 'alt': 'abc'},
ValueError,
'should be a string'),
({'href': 'www.google.com', 'alt': 'abc', 'rel': 'abc'},
AttributeError,
'attribute values should be one of these'),
Expand All @@ -259,9 +255,6 @@ def test_construct_area_tag_coords(attributes):
({'href': 'abc'},
AttributeError,
'attribute is required if the href attribute is present'),
({'href': 'www.google.com', 'alt': 123},
ValueError,
'should be a string')
])
def test_construct_area_tag_error(attributes, exception, error_msg):
"""Test for validating area tag's attributes."""
Expand Down

0 comments on commit 7dab5a1

Please sign in to comment.