def test_set_non_str_attribute_casts_to_string(self): # If the value of the attribute passed to set_attribute is not a # string, it's cast to a string. tag = Tag('whatever', self.req) tag.set_attribute('new-attribute', 42) result = tag.get_attribute('new-attribute') self.assertEqual('42', result)
def test_set_then_get_attribute(self): # Attributes set with set_attribute can be retrieved with # get_attribute. tag = Tag('whatever', self.req) tag.set_attribute('new-attribute', 'value') result = tag.get_attribute('new-attribute') self.assertEqual('value', result)
def test_set_name_attribute_does_nothing(self): # The 'name' attribute is set by the constructor. After it is set, it # cannot be changed with further calls to set_attribute. tag = Tag('old', self.req) tag.set_attribute('name', 'new') self.assertEqual('old', tag.get_name()) self.assertEqual('old', tag.get_attribute('name'))
def test_missing_attribute_returns_none(self): # If get_attribute is called for an attribute that doesn't exist, it # returns None. tag = Tag('whatever', self.req) result = tag.get_attribute('no-such-attribute') self.assertEqual(None, result)
def test_name_is_attribute(self): # The name of the tag is also stored as an attribute. tag = Tag('foo', self.req) self.assertEqual('foo', tag.get_attribute('name'))