Changeset 155

Show
Ignore:
Timestamp:
12/01/06 17:15:45 (2 years ago)
Author:
mk
Message:

Mock urllib.urlretrieve() in test_index_installability, so it works without Internet access.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tests/unit/_helper_cheesecake.py

    r97 r155  
    11 
    22import os 
     3import shutil 
     4 
     5from mock import Mock 
    36 
    47if 'set' not in dir(__builtins__): 
     
    69 
    710DATA_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../data/')) 
     11NOSE_PACKAGE_URL = "http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz" 
    812 
    913class Glutton(object): 
     
    2630    for filename in files: 
    2731        create_empty_file(os.path.join(directory, filename)) 
     32 
     33def dump_str_to_file(string, filename): 
     34    fd = file(filename, 'w') 
     35    fd.write(string) 
     36    fd.close() 
     37 
     38def mocked_urlretrieve(url, filename): 
     39    if url == NOSE_PACKAGE_URL: 
     40        shutil.copy(os.path.join(DATA_PATH, "nose-0.8.3.tar.gz"), filename) 
     41        headers = Mock({'gettype': 'application/x-gzip'}) 
     42    else: 
     43        response_content = '''<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
     44        <html><head> 
     45        <title>404 Not Found</title> 
     46        </head><body> 
     47        <h1>Not Found</h1> 
     48        <p>The requested URL was not found on this server.</p> 
     49        </body></html> 
     50        ''' 
     51        dump_str_to_file(response_content, filename) 
     52        headers = Mock({'gettype': 'text/html'}) 
     53 
     54    return filename, headers 
  • trunk/tests/unit/test_index_installability.py

    r80 r155  
    22 
    33import _path_cheesecake 
    4 from _helper_cheesecake import DATA_PATH 
     4from _helper_cheesecake import DATA_PATH, NOSE_PACKAGE_URL 
     5from _helper_cheesecake import dump_str_to_file 
     6from _helper_cheesecake import mocked_urlretrieve 
    57 
     8import cheesecake.cheesecake_index as cheesecake_index 
    69from cheesecake.cheesecake_index import Cheesecake 
    710from cheesecake.cheesecake_index import IndexPyPIDownload 
     
    1720    def setUp(self): 
    1821        self.cheesecake = None 
     22        self.nose_file_path = os.path.join(DATA_PATH, "nose-0.8.3.tar.gz") 
    1923 
    2024    def tearDown(self): 
     
    2428 
    2529    def test_index_installability_local_path(self): 
    26         self.cheesecake = Cheesecake(path=os.path.join(DATA_PATH, "nose-0.8.3.tar.gz")
     30        self.cheesecake = Cheesecake(path=self.nose_file_path
    2731 
    2832        index = self.cheesecake.index["INSTALLABILITY"] 
     
    3539 
    3640    def test_index_installability_url_download(self): 
    37         self.cheesecake = Cheesecake(url="http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz") 
     41        # Mock a successful file download. 
     42        cheesecake_index.urlretrieve = mocked_urlretrieve 
     43 
     44        self.cheesecake = Cheesecake(url=NOSE_PACKAGE_URL) 
    3845 
    3946        index = self.cheesecake.index["INSTALLABILITY"] 
  • trunk/tests/unit/test_index_unittests.py

    r89 r155  
    66 
    77import _path_cheesecake 
     8from _helper_cheesecake import dump_str_to_file 
    89 
    910from cheesecake.cheesecake_index import IndexUnitTests 
    1011from cheesecake import logger 
    11  
    12  
    13 def dump_str_to_file(string, filename): 
    14     fd = file(filename, 'w') 
    15     fd.write(string) 
    16     fd.close() 
    1712 
    1813