2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
10 import webforms_aggregator
13 class WebformsAggregatorTest(unittest
.TestCase
):
14 """Unit tests for the webforms_aggregator module."""
17 self
.cookie_file
= 'test.cookie'
18 self
.url1
= 'http://www.google.com'
19 self
.url2
= 'http://www.macys.com'
20 self
.domain
= 'google.com'
21 self
.url_file
= tempfile
.NamedTemporaryFile(suffix
='.txt', delete
=False)
22 self
.url_file
.file.write(
23 'URLs to crawl:\n%s\n%s\n' % (self
.url1
, self
.url2
))
27 if os
.path
.isfile(self
.cookie_file
):
28 os
.unlink(self
.cookie_file
)
29 if os
.path
.isfile(self
.url_file
.name
):
31 os
.unlink(self
.url_file
.name
)
33 def testRetrieverDownloadsPage(self
):
34 """Verify the retriever can download a page."""
35 r
= webforms_aggregator
.Retriever(self
.url1
, self
.domain
, self
.cookie_file
)
36 self
.assertTrue(r
.Download(),
37 msg
='Retriever could not download "%s"' % self
.url1
)
39 def testCrawlerFindsRegPageFromUrl(self
):
40 """Verify that the crawler is able to find a reg page from the given URL."""
41 c
= webforms_aggregator
.Crawler(self
.url2
)
43 c
.Run(), msg
='Crawler could not find the reg page of "%s"' % self
.url2
)
45 def testThreadedCrawlerFindsRegPageFromUrlsFile(self
):
46 """Verify the threaded crawler finds reg page from a file of URLs."""
47 c
= webforms_aggregator
.ThreadedCrawler(self
.url_file
.name
)
50 msg
='Threaded crawler could not find the reg page from the URLs file')
53 if __name__
== '__main__':
54 suite
= unittest
.TestLoader().loadTestsFromTestCase(
55 WebformsAggregatorTest
)
56 unittest
.TextTestRunner(verbosity
=2).run(suite
)