class LinkGeneratorTest(googletest.TestCase): def setUp(self): self.generator = link_generator.LinkGenerator() def testGetLinkFromIDs(self): expected = ('https://frontend.google.com/advancedSearchResults?' 's.op=ALL&s.r0.field=ID&s.r0.val=1288585+1310696+1346270+') actual = self.generator.GetLinkFromIDs(set((1346270, 1310696, 1288585))) self.assertEqual(expected, actual)
import urllib class LinkGenerator(object): _URL = ( 'https://frontend.google.com/advancedSearchResults?' 's.op=ALL&s.r0.field=ID&s.r0.val=') def GetLinkFromIDs(self, ids): result = [] for id in sorted(ids): result.append('%s ' % id) return self._URL + urllib.quote_plus(''.join(result))