def testEEToAndFromStringShouldMatch(self): string_from_ee = self.ee.ToString() new_ee = atom.ExtensionElementFromString(string_from_ee) string_from_new_ee = new_ee.ToString() self.assert_(string_from_ee == string_from_new_ee) deep_tree = atom.ExtensionElementFromString(test_data.EXTENSION_TREE) string_from_deep_tree = deep_tree.ToString() new_deep_tree = atom.ExtensionElementFromString(string_from_deep_tree) string_from_new_deep_tree = new_deep_tree.ToString() self.assert_(string_from_deep_tree == string_from_new_deep_tree)
def SendNotice(self, subject, body=None, content_type='html', ccr=None, profile_id=None): """Sends (posts) a notice to the user's Google Health profile. Args: subject: A string representing the message's subject line. body: string (optional) The message body. content_type: string (optional) The content type of the notice message body. This parameter is only honored when a message body is specified. ccr: string (optional) The CCR XML document to reconcile into the user's profile. profile_id: string (optional) The profile id to work with when using ClientLogin. Note: this parameter is ignored if query is set. Returns: A gdata.health.ProfileEntry object of the posted entry. """ if body: content = atom.Content(content_type=content_type, text=body) else: content = body entry = gdata.GDataEntry( title=atom.Title(text=subject), content=content, extension_elements=[atom.ExtensionElementFromString(ccr)]) projection = profile_id and 'ui' or 'default' query = HealthRegisterQuery(service=self.__get_service(), projection=projection, profile_id=profile_id) return self.Post(entry, query.ToUri(), converter=gdata.health.ProfileEntryFromString)
def testEEParsesTreeCorrectly(self): deep_tree = atom.ExtensionElementFromString(test_data.EXTENSION_TREE) self.assert_(deep_tree.tag == 'feed') self.assert_(deep_tree.namespace == 'http://www.w3.org/2005/Atom') self.assert_(deep_tree.children[0].tag == 'author') self.assert_( deep_tree.children[0].namespace == 'http://www.google.com') self.assert_(deep_tree.children[0].children[0].tag == 'name') self.assert_(deep_tree.children[0].children[0].namespace == 'http://www.google.com') self.assert_( deep_tree.children[0].children[0].text.strip() == 'John Doe') self.assert_(deep_tree.children[0].children[0].children[0].text.strip( ) == 'Bar') foo = deep_tree.children[0].children[0].children[0] self.assert_(foo.tag == 'foo') self.assert_(foo.namespace == 'http://www.google.com') self.assert_(foo.attributes['up'] == 'down') self.assert_(foo.attributes['yes'] == 'no') self.assert_(foo.children == [])
def SetXmlBlob(self, blob): """Sets the contents of the extendedProperty to XML as a child node. Since the extendedProperty is only allowed one child element as an XML blob, setting the XML blob will erase any preexisting extension elements in this object. Args: blob: str, ElementTree Element or atom.ExtensionElement representing the XML blob stored in the extendedProperty. """ # Erase any existing extension_elements, clears the child nodes from the # extendedProperty. self.extension_elements = [] if isinstance(blob, atom.ExtensionElement): self.extension_elements.append(blob) elif ElementTree.iselement(blob): self.extension_elements.append( atom._ExtensionElementFromElementTree(blob)) else: self.extension_elements.append( atom.ExtensionElementFromString(blob))