Changeset 157
- Timestamp:
- 12/01/06 18:01:40 (2 years ago)
- Files:
-
- trunk/tests/unit/_helper_cheesecake.py (modified) (2 diffs)
- trunk/tests/unit/test_index_installability.py (modified) (4 diffs)
- trunk/tests/unit/test_index_url_download.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tests/unit/_helper_cheesecake.py
r155 r157 9 9 10 10 DATA_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../data/')) 11 NOSE_PACKAGE_URL = "http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz" 11 SAMPLE_PACKAGE_PATH = os.path.join(DATA_PATH, "nose-0.8.3.tar.gz") 12 SAMPLE_PACKAGE_URL = "http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz" 13 14 VALID_URLS = [ SAMPLE_PACKAGE_URL, 'file://%s' % SAMPLE_PACKAGE_PATH ] 15 12 16 13 17 class Glutton(object): … … 37 41 38 42 def mocked_urlretrieve(url, filename): 39 if url == NOSE_PACKAGE_URL:43 if url in VALID_URLS: 40 44 shutil.copy(os.path.join(DATA_PATH, "nose-0.8.3.tar.gz"), filename) 41 45 headers = Mock({'gettype': 'application/x-gzip'}) 46 elif url == 'connection_refused': 47 raise IOError("[Errno socket error] (111, 'Connection refused')") 42 48 else: 43 49 response_content = '''<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> trunk/tests/unit/test_index_installability.py
r155 r157 2 2 3 3 import _path_cheesecake 4 from _helper_cheesecake import DATA_PATH, NOSE_PACKAGE_URL 5 from _helper_cheesecake import dump_str_to_file 4 from _helper_cheesecake import SAMPLE_PACKAGE_PATH, SAMPLE_PACKAGE_URL 6 5 from _helper_cheesecake import mocked_urlretrieve 7 6 … … 20 19 def setUp(self): 21 20 self.cheesecake = None 22 self.nose_file_path = os.path.join(DATA_PATH, "nose-0.8.3.tar.gz")21 cheesecake_index.urlretrieve = mocked_urlretrieve 23 22 24 23 def tearDown(self): … … 28 27 29 28 def test_index_installability_local_path(self): 30 self.cheesecake = Cheesecake(path= self.nose_file_path)29 self.cheesecake = Cheesecake(path=SAMPLE_PACKAGE_PATH) 31 30 32 31 index = self.cheesecake.index["INSTALLABILITY"] … … 39 38 40 39 def test_index_installability_url_download(self): 41 # Mock a successful file download. 42 cheesecake_index.urlretrieve = mocked_urlretrieve 43 44 self.cheesecake = Cheesecake(url=NOSE_PACKAGE_URL) 40 self.cheesecake = Cheesecake(url=SAMPLE_PACKAGE_URL) 45 41 46 42 index = self.cheesecake.index["INSTALLABILITY"] trunk/tests/unit/test_index_url_download.py
r146 r157 3 3 4 4 import _path_cheesecake 5 from _helper_cheesecake import DATA_PATH 5 from _helper_cheesecake import VALID_URLS 6 from _helper_cheesecake import mocked_urlretrieve 7 8 import cheesecake.cheesecake_index as cheesecake_index 6 9 from cheesecake.cheesecake_index import Cheesecake, CheesecakeError, pad_msg, IndexUrlDownload 7 10 … … 12 15 def setUp(self): 13 16 self.cheesecake = None 17 cheesecake_index.urlretrieve = mocked_urlretrieve 14 18 15 19 def _run_it(self, test_fun): … … 26 30 27 31 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 urls = VALID_URLS 32 33 33 34 for url in urls: 34 35 def test_fun(logfile): 35 try: 36 self.cheesecake = Cheesecake(url=url, logfile=logfile) 36 self.cheesecake = Cheesecake(url=url, logfile=logfile) 37 37 38 index = self.cheesecake.index["INSTALLABILITY"]["IndexUrlDownload"]39 index.compute_with(self.cheesecake)38 index = self.cheesecake.index["INSTALLABILITY"]["IndexUrlDownload"] 39 index.compute_with(self.cheesecake) 40 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 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 51 46 52 47 self._run_it(test_fun) … … 55 50 def test_fun(logfile): 56 51 try: 57 self.cheesecake = Cheesecake(url=" http://www.agilistas.org/cheesecake/not_there.tar.gz",52 self.cheesecake = Cheesecake(url="invalid_url", 58 53 sandbox=default_temp_directory, logfile=logfile) 59 assert 0 # This statement should not be reached54 assert False, "Should throw a CheesecakeError." 60 55 except CheesecakeError, e: 61 56 msg = "Error: Got '404 Not Found' error while trying to download package ... exiting" … … 64 59 65 60 self._run_it(test_fun) 61 62 def test_index_url_download_connection_refused(self): 63 def test_fun(logfile): 64 try: 65 self.cheesecake = Cheesecake(url='connection_refused', 66 sandbox=default_temp_directory, logfile=logfile) 67 assert False, "Should throw a CheesecakeError." 68 except CheesecakeError, e: 69 print str(e) 70 msg = "Error: [Errno socket error] (111, 'Connection refused')\n" 71 msg += "Detailed info available in log file %s" % logfile 72 assert str(e) == msg 73 74 self._run_it(test_fun)
