<s> __author__ = '<STR_LIT>' <EOL> import unittest <EOL> try : <EOL> from xml . etree import ElementTree <EOL> except ImportError : <EOL> from elementtree import ElementTree <EOL> import gdata <EOL> from gdata import test_data <EOL> import gdata . base <EOL> class LabelTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . label = gdata . base . Label ( ) <EOL> def testToAndFromString ( self ) : <EOL> self . label . text = '<STR_LIT>' <EOL> self . assert_ ( self . label . text == '<STR_LIT>' ) <EOL> new_label = gdata . base . LabelFromString ( self . label . ToString ( ) ) <EOL> self . assert_ ( self . label . text == new_label . text ) <EOL> class ItemTypeTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . item_type = gdata . base . ItemType ( ) <EOL> def testToAndFromString ( self ) : <EOL> self . item_type . text = '<STR_LIT>' <EOL> self . item_type . type = '<STR_LIT:text>' <EOL> self . assert_ ( self . item_type . text == '<STR_LIT>' ) <EOL> self . assert_ ( self . item_type . type == '<STR_LIT:text>' ) <EOL> new_item_type = gdata . base . ItemTypeFromString ( self . item_type . ToString ( ) ) <EOL> self . assert_ ( self . item_type . text == new_item_type . text ) <EOL> self . assert_ ( self . item_type . type == new_item_type . type ) <EOL> class GBaseItemTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . item = gdata . base . GBaseItem ( ) <EOL> def testToAndFromString ( self ) : <EOL> self . item . label . append ( gdata . base . Label ( text = '<STR_LIT>' ) ) <EOL> self . assert_ ( self . item . label [ <NUM_LIT:0> ] . text == '<STR_LIT>' ) <EOL> self . item . item_type = gdata . base . ItemType ( text = '<STR_LIT>' ) <EOL> self . assert_ ( self . item . item_type . text == '<STR_LIT>' ) <EOL> self . item . item_attributes . append ( gdata . base . ItemAttribute ( '<STR_LIT>' , text = '<STR_LIT:foo>' ) ) <EOL> self . assert_ ( self . item . item_attributes [ <NUM_LIT:0> ] . text == '<STR_LIT:foo>' ) <EOL> self . assert_ ( self . item . item_attributes [ <NUM_LIT:0> ] . name == '<STR_LIT>' ) <EOL> new_item = gdata . base . GBaseItemFromString ( self . item . ToString ( ) ) <EOL> self . assert_ ( self . item . label [ <NUM_LIT:0> ] . text == new_item . label [ <NUM_LIT:0> ] . text ) <EOL> self . assert_ ( self . item . item_type . text == new_item . item_type . text ) <EOL> self . assert_ ( self . item . item_attributes [ <NUM_LIT:0> ] . text == <EOL> new_item . item_attributes [ <NUM_LIT:0> ] . text ) <EOL> def testCustomItemAttributes ( self ) : <EOL> self . item . AddItemAttribute ( '<STR_LIT>' , '<STR_LIT:foo>' ) <EOL> self . assert_ ( self . item . FindItemAttribute ( '<STR_LIT>' ) == '<STR_LIT:foo>' ) <EOL> self . item . SetItemAttribute ( '<STR_LIT>' , '<STR_LIT:bar>' ) <EOL> self . assert_ ( self . item . FindItemAttribute ( '<STR_LIT>' ) == '<STR_LIT:bar>' ) <EOL> self . item . RemoveItemAttribute ( '<STR_LIT>' ) <EOL> self . assert_ ( self . item . FindItemAttribute ( '<STR_LIT>' ) is None ) <EOL> def testConvertActualData ( self ) : <EOL> feed = gdata . base . GBaseSnippetFeedFromString ( test_data . GBASE_FEED ) <EOL> for an_entry in feed . entry : <EOL> if an_entry . author [ <NUM_LIT:0> ] . email . text == '<STR_LIT>' : <EOL> for attrib in an_entry . item_attributes : <EOL> if attrib . name == '<STR_LIT>' : <EOL> self . assert_ ( attrib . text == <EOL> '<STR_LIT>' ) <EOL> if attrib . name == '<STR_LIT>' : <EOL> self . assert_ ( attrib . text == '<STR_LIT>' ) <EOL> def testModifyCustomItemAttributes ( self ) : <EOL> self . item . AddItemAttribute ( '<STR_LIT>' , '<STR_LIT:foo>' , value_type = '<STR_LIT>' ) <EOL> self . item . AddItemAttribute ( '<STR_LIT>' , '<STR_LIT:bar>' , value_type = '<STR_LIT>' ) <EOL> self . assertEquals ( self . item . item_attributes [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEquals ( self . item . item_attributes [ <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> self . assertEquals ( self . item . item_attributes [ <NUM_LIT:0> ] . text , '<STR_LIT:foo>' ) <EOL> self . assertEquals ( self . item . item_attributes [ <NUM_LIT:1> ] . text , '<STR_LIT:bar>' ) <EOL> attributes = self . item . GetItemAttributes ( '<STR_LIT>' ) <EOL> self . assertEquals ( len ( attributes ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( attributes [ <NUM_LIT:0> ] . text , '<STR_LIT:foo>' ) <EOL> attributes [ <NUM_LIT:0> ] . text = '<STR_LIT>' <EOL> self . assertEquals ( attributes [ <NUM_LIT:0> ] . text , '<STR_LIT>' ) <EOL> self . assertEquals ( self . item . item_attributes [ <NUM_LIT:0> ] . text , '<STR_LIT>' ) <EOL> class GBaseItemFeedTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . item_feed = gdata . base . GBaseItemFeedFromString ( test_data . GBASE_FEED ) <EOL> def testToAndFromString ( self ) : <EOL> self . assert_ ( len ( self . item_feed . entry ) == <NUM_LIT:3> ) <EOL> for an_entry in self . item_feed . entry : <EOL> self . assert_ ( isinstance ( an_entry , gdata . base . GBaseItem ) ) <EOL> new_item_feed = gdata . base . GBaseItemFeedFromString ( str ( self . item_feed ) ) <EOL> for an_entry in new_item_feed . entry : <EOL> self . assert_ ( isinstance ( an_entry , gdata . base . GBaseItem ) ) <EOL> def testLinkFinderFindsHtmlLink ( self ) : <EOL> for entry in self . item_feed . entry : <EOL> self . assert_ ( entry . GetSelfLink ( ) is not None ) <EOL> self . assert_ ( entry . GetHtmlLink ( ) is not None ) <EOL> self . assert_ ( entry . GetEditLink ( ) is None ) <EOL> class GBaseSnippetFeedTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . snippet_feed = gdata . base . GBaseSnippetFeedFromString ( test_data . GBASE_FEED ) <EOL> def testToAndFromString ( self ) : <EOL> self . assert_ ( len ( self . snippet_feed . entry ) == <NUM_LIT:3> ) <EOL> for an_entry in self . snippet_feed . entry : <EOL> self . assert_ ( isinstance ( an_entry , gdata . base . GBaseSnippet ) ) <EOL> new_snippet_feed = gdata . base . GBaseSnippetFeedFromString ( str ( self . snippet_feed ) ) <EOL> for an_entry in new_snippet_feed . entry : <EOL> self . assert_ ( isinstance ( an_entry , gdata . base . GBaseSnippet ) ) <EOL> class ItemAttributeTest ( unittest . TestCase ) : <EOL> def testToAndFromStirng ( self ) : <EOL> attrib = gdata . base . ItemAttribute ( '<STR_LIT>' ) <EOL> attrib . type = '<STR_LIT:float>' <EOL> self . assert_ ( attrib . name == '<STR_LIT>' ) <EOL> self . assert_ ( attrib . type == '<STR_LIT:float>' ) <EOL> new_attrib = gdata . base . ItemAttributeFromString ( str ( attrib ) ) <EOL> self . assert_ ( new_attrib . name == attrib . name ) <EOL> self . assert_ ( new_attrib . type == attrib . type ) <EOL> def testClassConvertsActualData ( self ) : <EOL> attrib = gdata . base . ItemAttributeFromString ( test_data . TEST_GBASE_ATTRIBUTE ) <EOL> self . assert_ ( attrib . name == '<STR_LIT>' ) <EOL> self . assert_ ( attrib . type == '<STR_LIT:text>' ) <EOL> self . assert_ ( len ( attrib . extension_elements ) == <NUM_LIT:0> ) <EOL> element = attrib . _ToElementTree ( ) <EOL> self . assert_ ( element . tag == gdata . base . GBASE_TEMPLATE % '<STR_LIT>' ) <EOL> class AttributeTest ( unittest . TestCase ) : <EOL> def testAttributeToAndFromString ( self ) : <EOL> attrib = gdata . base . Attribute ( ) <EOL> attrib . type = '<STR_LIT:float>' <EOL> attrib . count = '<STR_LIT>' <EOL> attrib . name = '<STR_LIT>' <EOL> attrib . value . append ( gdata . base . Value ( count = '<STR_LIT>' , text = '<STR_LIT>' ) ) <EOL> self . assert_ ( attrib . type == '<STR_LIT:float>' ) <EOL> self . assert_ ( attrib . count == '<STR_LIT>' ) <EOL> self . assert_ ( attrib . name == '<STR_LIT>' ) <EOL> self . assert_ ( attrib . value [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( attrib . value [ <NUM_LIT:0> ] . text == '<STR_LIT>' ) <EOL> new_attrib = gdata . base . AttributeFromString ( str ( attrib ) ) <EOL> self . assert_ ( attrib . type == new_attrib . type ) <EOL> self . assert_ ( attrib . count == new_attrib . count ) <EOL> self . assert_ ( attrib . value [ <NUM_LIT:0> ] . count == new_attrib . value [ <NUM_LIT:0> ] . count ) <EOL> self . assert_ ( attrib . value [ <NUM_LIT:0> ] . text == new_attrib . value [ <NUM_LIT:0> ] . text ) <EOL> self . assert_ ( attrib . name == new_attrib . name ) <EOL> class ValueTest ( unittest . TestCase ) : <EOL> def testValueToAndFromString ( self ) : <EOL> value = gdata . base . Value ( ) <EOL> value . count = '<STR_LIT>' <EOL> value . text = '<STR_LIT>' <EOL> self . assert_ ( value . count == '<STR_LIT>' ) <EOL> self . assert_ ( value . text == '<STR_LIT>' ) <EOL> new_value = gdata . base . ValueFromString ( str ( value ) ) <EOL> self . assert_ ( new_value . count == value . count ) <EOL> self . assert_ ( new_value . text == value . text ) <EOL> class AttributeEntryTest ( unittest . TestCase ) : <EOL> def testAttributeEntryToAndFromString ( self ) : <EOL> value = gdata . base . Value ( count = '<STR_LIT>' , text = '<STR_LIT>' ) <EOL> attribute = gdata . base . Attribute ( count = '<STR_LIT>' , value = [ value ] ) <EOL> a_entry = gdata . base . GBaseAttributeEntry ( attribute = [ attribute ] ) <EOL> self . assert_ ( a_entry . attribute [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( a_entry . attribute [ <NUM_LIT:0> ] . value [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( a_entry . attribute [ <NUM_LIT:0> ] . value [ <NUM_LIT:0> ] . text == '<STR_LIT>' ) <EOL> new_entry = gdata . base . GBaseAttributeEntryFromString ( str ( a_entry ) ) <EOL> self . assert_ ( new_entry . attribute [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( new_entry . attribute [ <NUM_LIT:0> ] . value [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( new_entry . attribute [ <NUM_LIT:0> ] . value [ <NUM_LIT:0> ] . text == '<STR_LIT>' ) <EOL> class GBaseAttributeEntryTest ( unittest . TestCase ) : <EOL> def testAttribteEntryFromExampleData ( self ) : <EOL> entry = gdata . base . GBaseAttributeEntryFromString ( <EOL> test_data . GBASE_ATTRIBUTE_ENTRY ) <EOL> self . assert_ ( len ( entry . attribute ) == <NUM_LIT:1> ) <EOL> self . assert_ ( len ( entry . attribute [ <NUM_LIT:0> ] . value ) == <NUM_LIT:10> ) <EOL> self . assert_ ( entry . attribute [ <NUM_LIT:0> ] . name == '<STR_LIT>' ) <EOL> for val in entry . attribute [ <NUM_LIT:0> ] . value : <EOL> if val . text == '<STR_LIT>' : <EOL> self . assert_ ( val . count == '<STR_LIT>' ) <EOL> elif val . text == '<STR_LIT>' : <EOL> self . assert_ ( val . count == '<STR_LIT>' ) <EOL> class GBaseAttributesFeedTest ( unittest . TestCase ) : <EOL> def testAttributesFeedExampleData ( self ) : <EOL> feed = gdata . base . GBaseAttributesFeedFromString ( test_data . GBASE_ATTRIBUTE_FEED ) <EOL> self . assert_ ( len ( feed . entry ) == <NUM_LIT:1> ) <EOL> self . assert_ ( isinstance ( feed . entry [ <NUM_LIT:0> ] , gdata . base . GBaseAttributeEntry ) ) <EOL> def testAttributesFeedToAndFromString ( self ) : <EOL> value = gdata . base . Value ( count = '<STR_LIT>' , text = '<STR_LIT>' ) <EOL> attribute = gdata . base . Attribute ( count = '<STR_LIT>' , value = [ value ] ) <EOL> a_entry = gdata . base . GBaseAttributeEntry ( attribute = [ attribute ] ) <EOL> feed = gdata . base . GBaseAttributesFeed ( entry = [ a_entry ] ) <EOL> self . assert_ ( feed . entry [ <NUM_LIT:0> ] . attribute [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( feed . entry [ <NUM_LIT:0> ] . attribute [ <NUM_LIT:0> ] . value [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( feed . entry [ <NUM_LIT:0> ] . attribute [ <NUM_LIT:0> ] . value [ <NUM_LIT:0> ] . text == '<STR_LIT>' ) <EOL> new_feed = gdata . base . GBaseAttributesFeedFromString ( str ( feed ) ) <EOL> self . assert_ ( new_feed . entry [ <NUM_LIT:0> ] . attribute [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( new_feed . entry [ <NUM_LIT:0> ] . attribute [ <NUM_LIT:0> ] . value [ <NUM_LIT:0> ] . count == '<STR_LIT>' ) <EOL> self . assert_ ( new_feed . entry [ <NUM_LIT:0> ] . attribute [ <NUM_LIT:0> ] . value [ <NUM_LIT:0> ] . text == '<STR_LIT>' ) <EOL> class GBaseLocalesFeedTest ( unittest . TestCase ) : <EOL> def testLocatesFeedWithExampleData ( self ) : <EOL> feed = gdata . base . GBaseLocalesFeedFromString ( test_data . GBASE_LOCALES_FEED ) <EOL> self . assert_ ( len ( feed . entry ) == <NUM_LIT:3> ) <EOL> self . assert_ ( feed . GetSelfLink ( ) . href == <EOL> '<STR_LIT>' ) <EOL> for an_entry in feed . entry : <EOL> if an_entry . title . text == '<STR_LIT>' : <EOL> self . assert_ ( an_entry . category [ <NUM_LIT:0> ] . term == '<STR_LIT>' ) <EOL> self . assert_ ( an_entry . title . text == an_entry . category [ <NUM_LIT:0> ] . term ) <EOL> class GBaseItemTypesFeedAndEntryTest ( unittest . TestCase ) : <EOL> def testItemTypesFeedToAndFromString ( self ) : <EOL> feed = gdata . base . GBaseItemTypesFeed ( ) <EOL> entry = gdata . base . GBaseItemTypeEntry ( ) <EOL> entry . attribute . append ( gdata . base . Attribute ( name = '<STR_LIT:location>' , <EOL> attribute_type = '<STR_LIT:location>' ) ) <EOL> entry . item_type = gdata . base . ItemType ( text = '<STR_LIT>' ) <EOL> feed . entry . append ( entry ) <EOL> self . assert_ ( len ( feed . entry ) == <NUM_LIT:1> ) <EOL> self . assert_ ( feed . entry [ <NUM_LIT:0> ] . attribute [ <NUM_LIT:0> ] . name == '<STR_LIT:location>' ) <EOL> new_feed = gdata . base . GBaseItemTypesFeedFromString ( str ( feed ) ) <EOL> self . assert_ ( len ( new_feed . entry ) == <NUM_LIT:1> ) <EOL> self . assert_ ( new_feed . entry [ <NUM_LIT:0> ] . attribute [ <NUM_LIT:0> ] . name == '<STR_LIT:location>' ) <EOL> class GBaseImageLinkTest ( unittest . TestCase ) : <EOL> def testImageLinkToAndFromString ( self ) : <EOL> image_link = gdata . base . ImageLink ( ) <EOL> image_link . type = '<STR_LIT:url>' <EOL> image_link . text = '<STR_LIT>' <EOL> thumbnail = gdata . base . Thumbnail ( ) <EOL> thumbnail . width = '<STR_LIT>' <EOL> thumbnail . height = '<STR_LIT>' <EOL> thumbnail . text = '<STR_LIT>' <EOL> image_link . thumbnail . append ( thumbnail ) <EOL> xml = image_link . ToString ( ) <EOL> parsed = gdata . base . ImageLinkFromString ( xml ) <EOL> self . assert_ ( parsed . type == image_link . type ) <EOL> self . assert_ ( parsed . text == image_link . text ) <EOL> self . assert_ ( len ( parsed . thumbnail ) == <NUM_LIT:1> ) <EOL> self . assert_ ( parsed . thumbnail [ <NUM_LIT:0> ] . width == thumbnail . width ) <EOL> self . assert_ ( parsed . thumbnail [ <NUM_LIT:0> ] . height == thumbnail . height ) <EOL> self . assert_ ( parsed . thumbnail [ <NUM_LIT:0> ] . text == thumbnail . text ) <EOL> class GBaseItemAttributeAccessElement ( unittest . TestCase ) : <EOL> def testItemAttributeAccessAttribute ( self ) : <EOL> item = gdata . base . GBaseItem ( ) <EOL> item . AddItemAttribute ( '<STR_LIT:test>' , '<STR_LIT:1>' , value_type = '<STR_LIT:int>' , access = '<STR_LIT>' ) <EOL> private_attribute = item . GetItemAttributes ( '<STR_LIT:test>' ) [ <NUM_LIT:0> ] <EOL> self . assert_ ( private_attribute . access == '<STR_LIT>' ) <EOL> xml = item . ToString ( ) <EOL> new_item = gdata . base . GBaseItemFromString ( xml ) <EOL> new_attributes = new_item . GetItemAttributes ( '<STR_LIT:test>' ) <EOL> self . assert_ ( len ( new_attributes ) == <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
