root/trunk/tests/unit/test_index_url_download.py

Revision 146, 2.4 kB (checked in by mk, 7 years ago)

Each abnormal termination of cheesecake_index should end with line starting with "Error:".

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