def testMetaTagToAndFromString(self): self.method = webmastertools.VerificationMethod() self.method.type = 'metatag' self.method.in_use = 'false' self.assert_(self.method.type == 'metatag') self.assert_(self.method.in_use == 'false') self.method.meta = webmastertools.VerificationMethodMeta( name='verify-vf1', content='a2Ai') self.assert_(self.method.meta.name == 'verify-vf1') self.assert_(self.method.meta.content == 'a2Ai') new_method = webmastertools.VerificationMethodFromString( self.method.ToString()) self.assert_(self.method.type == new_method.type) self.assert_(self.method.in_use == new_method.in_use) self.assert_(self.method.meta.name == new_method.meta.name) self.assert_(self.method.meta.content == new_method.meta.content) method = webmastertools.VerificationMethod(type='xyz') self.assertEqual(method.type, 'xyz') method = webmastertools.VerificationMethod() self.assert_(method.type is None)
def testHtmlPageToAndFromString(self): self.method = webmastertools.VerificationMethod() self.method.type = 'htmlpage' self.method.in_use = 'false' self.method.text = '456456-google.html' self.assert_(self.method.type == 'htmlpage') self.assert_(self.method.in_use == 'false') self.assert_(self.method.text == '456456-google.html') self.assert_(self.method.meta is None) new_method = webmastertools.VerificationMethodFromString( self.method.ToString()) self.assert_(self.method.type == new_method.type) self.assert_(self.method.in_use == new_method.in_use) self.assert_(self.method.text == new_method.text) self.assert_(self.method.meta is None)
def VerifySite(self, site_uri, verification_method, uri=SITE_TEMPLATE, url_params=None, escape_params=True, converter=None): """Requests a verification of a site. Args: site_uri: str URI of which site to add sitemap for. verification_method: str The method to verify a site. Valid values are 'htmlpage', and 'metatag'. uri: str (optional) URI template to update a site. Default SITE_TEMPLATE. url_params: dict (optional) Additional URL parameters to be included in the insertion request. escape_params: boolean (optional) If true, the url_parameters will be escaped before they are included in the request. converter: func (optional) Function which is executed on the server's response before it is returned. Usually this is a function like SitemapsEntryFromString which will parse the response and turn it into an object. Returns: If converter is defined, the results of running converter on the server's response. Otherwise, it will be a SitesEntry object. """ site_entry = webmastertools.SitesEntry( atom_id=atom.Id(text=site_uri), category=atom.Category( scheme='http://schemas.google.com/g/2005#kind', term= 'http://schemas.google.com/webmasters/tools/2007#sites-info'), verification_method=webmastertools.VerificationMethod( type=verification_method, in_use='true')) response = self.Put(site_entry, uri % urllib.quote_plus(site_uri), url_params=url_params, escape_params=escape_params, converter=converter) if not converter and isinstance(response, atom.Entry): return webmastertools.SitesEntryFromString(response.ToString()) return response