root/branches/mk/tests/test_index_url_download.py

Revision 21, 2.2 kB (checked in by mk, 7 years ago)

Use tempfile.gettempdir() instead of fixed /tmp/.

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         def test_fun():
25             datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data"))
26
27             urls = [
28                 "http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz",
29                 "file://%s" % os.path.join(datadir, "nose-0.8.3.tar.gz")
30             ]
31
32             for url in urls:
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                 assert 0 # This statement should not be reached
54             except CheesecakeError, e:
55                 msg = "Could not read tar file %s ... exiting\n" % \
56                       os.path.join(default_temp_directory, 'not_there.tar.gz')
57                 msg += pad_msg("CHEESECAKE INDEX", 0)
58                 assert str(e) == msg
59
60         self._run_it(test_fun)
Note: See TracBrowser for help on using the browser.