root/branches/mk/tests/test_index_url_download.py

Revision 22, 2.3 kB (checked in by mk, 7 years ago)

Use random temporary directory for sandbox by default.

Line 
1 import _path_cheesecake
2 from cheesecake.cheesecake_index import Cheesecake, CheesecakeError, pad_msg
3        
4 import os
5 import tempfile
6
7 default_temp_directory = os.path.join(tempfile.gettempdir(), 'cheesecake_sandbox')
8
9
10 class TestIndexInstallability(object):
11
12     def setUp(self):
13         self.cheesecake = None
14
15     def _run_it(self, test_fun):
16         try:
17             test_fun()
18         finally:
19             if self.cheesecake:
20                 self.cheesecake.cleanup()
21                 os.unlink(self.cheesecake.logfile)
22
23     def test_index_url_download_valid_url(self):
24         datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data"))
25
26         urls = [
27             "http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz",
28             "file://%s" % os.path.join(datadir, "nose-0.8.3.tar.gz")
29         ]
30
31         for url in urls:
32             def test_fun():
33                 try:
34                     self.cheesecake = Cheesecake(url=url)
35                     index = self.cheesecake.index_url_download()
36                     assert index.name == "index_url_download"
37                     assert index.value == self.cheesecake.INDEX_URL_DOWNLOAD
38                     assert index.details == "downloaded package " + \
39                            self.cheesecake.package + " from URL " + \
40                            self.cheesecake.url
41                 except CheesecakeError, e:
42                     # it's OK if we get "connection refused" sometimes
43                     msg = "[Errno socket error] (111, 'Connection refused')\n"
44                     msg += pad_msg("CHEESECAKE INDEX", 0)
45                     assert str(e) == msg
46
47             self._run_it(test_fun)
48
49     def test_index_url_download_invalid_url(self):
50         def test_fun():
51             try:
52                 self.cheesecake = Cheesecake(url="http://www.agilistas.org/cheesecake/not_there.tar.gz",
53                                              sandbox=default_temp_directory)
54                 assert 0 # This statement should not be reached
55             except CheesecakeError, e:
56                 msg = "Could not read tar file %s ... exiting\n" % \
57                       os.path.join(default_temp_directory, 'not_there.tar.gz')
58                 msg += pad_msg("CHEESECAKE INDEX", 0)
59                 assert str(e) == msg
60
61         self._run_it(test_fun)
Note: See TracBrowser for help on using the browser.