def test_progress_create(self): tracker = ProgressTracker() progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 0) self.assertEquals(progress["remaining_bytes"], 0) self.assertEquals(progress["total_num_items"], 0) self.assertEquals(progress["remaining_num_items"], 0) self.assertEquals(progress["type_info"], {})
def test_add_item(self): tracker = ProgressTracker() progress = tracker.get_progress() tracker.add_item("http://test1", 100, "rpm") progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 100) self.assertEquals(progress["remaining_bytes"], 100) self.assertEquals(progress["total_num_items"], 1) self.assertEquals(progress["remaining_num_items"], 1) self.assertTrue(progress["type_info"].has_key("rpm")) self.assertEquals(progress["type_info"]["rpm"]["total_size_bytes"], 100) self.assertEquals(progress["type_info"]["rpm"]["size_left"], 100) self.assertEquals(progress["type_info"]["rpm"]["total_count"], 1) self.assertEquals(progress["type_info"]["rpm"]["items_left"], 1) self.assertEquals(progress["type_info"]["rpm"]["num_success"], 0) self.assertEquals(progress["type_info"]["rpm"]["num_error"], 0) tracker.item_complete("http://test1", True) progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 100) self.assertEquals(progress["remaining_bytes"], 0) self.assertEquals(progress["total_num_items"], 1) self.assertEquals(progress["remaining_num_items"], 0) self.assertTrue(progress["type_info"].has_key("rpm")) self.assertEquals(progress["type_info"]["rpm"]["total_size_bytes"], 100) self.assertEquals(progress["type_info"]["rpm"]["size_left"], 0) self.assertEquals(progress["type_info"]["rpm"]["total_count"], 1) self.assertEquals(progress["type_info"]["rpm"]["items_left"], 0) self.assertEquals(progress["type_info"]["rpm"]["num_success"], 1) self.assertEquals(progress["type_info"]["rpm"]["num_error"], 0)
def test_progress_modify_size(self): tracker = ProgressTracker() progress = tracker.get_progress() fetchURL = "http://test1" tracker.add_item(fetchURL, 100, "rpm") # Updating progress with a smaller expected download size, causing total_size_bytes to decrease tracker.update_progress_download(fetchURL, 80, 5) progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 80) self.assertEquals(progress["remaining_bytes"], 75) self.assertEquals(progress["type_info"]["rpm"]["total_size_bytes"], 80) self.assertEquals(progress["type_info"]["rpm"]["size_left"], 75)
def test_update_progress_with_NaN(self): tracker = ProgressTracker() progress = tracker.get_progress() # Simulate a call with 'NaN' tracker.add_item("http://test1", 100, "rpm") tracker.update_progress_download("http://test1", float("nan"), 5) progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 100) self.assertEquals(progress["remaining_bytes"], 100) self.assertEquals(progress["total_num_items"], 1) self.assertEquals(progress["remaining_num_items"], 1) self.assertTrue(progress["type_info"].has_key("rpm")) self.assertEquals(progress["type_info"]["rpm"]["total_size_bytes"], 100) self.assertEquals(progress["type_info"]["rpm"]["size_left"], 100) self.assertEquals(progress["type_info"]["rpm"]["total_count"], 1) self.assertEquals(progress["type_info"]["rpm"]["items_left"], 1) self.assertEquals(progress["type_info"]["rpm"]["num_success"], 0) self.assertEquals(progress["type_info"]["rpm"]["num_error"], 0)
def __init__(self, cacert=None, clicert=None, clikey=None, proxy_url=None, proxy_port=None, proxy_user=None, proxy_pass=None, sslverify=1, max_speed = None, verify_options = None, tracker = None, num_retries=None): self.sslcacert = cacert self.sslclientcert = clicert self.sslclientkey = clikey self.proxy_url = proxy_url self.proxy_port = proxy_port self.proxy_user = proxy_user self.proxy_pass = proxy_pass self.sslverify = sslverify self.max_speed = max_speed self.verify_options = verify_options if not tracker: tracker = ProgressTracker() self.tracker = tracker self.num_retries = 2 if num_retries is not None: self.num_retries=num_retries
def test_update_progress_with_bad_data(self): tracker = ProgressTracker() progress = tracker.get_progress() # Simulate a call with bad data tracker.add_item("http://test1", "Bad_Value_Non_Integer", "rpm") tracker.update_progress_download("http://test1", "Bad_Value", 5) progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 0) self.assertEquals(progress["remaining_bytes"], 0) self.assertEquals(progress["total_num_items"], 1) self.assertEquals(progress["remaining_num_items"], 1) self.assertTrue(progress["type_info"].has_key("rpm")) self.assertEquals(progress["type_info"]["rpm"]["total_size_bytes"], 0) self.assertEquals(progress["type_info"]["rpm"]["size_left"], 0) self.assertEquals(progress["type_info"]["rpm"]["total_count"], 1) self.assertEquals(progress["type_info"]["rpm"]["items_left"], 1) self.assertEquals(progress["type_info"]["rpm"]["num_success"], 0) self.assertEquals(progress["type_info"]["rpm"]["num_error"], 0) # Now simulate if update is called subsequently with good data # Ensure it's working tracker.update_progress_download("http://test1", 100, 5) progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 100) self.assertEquals(progress["remaining_bytes"], 95) self.assertEquals(progress["total_num_items"], 1) self.assertEquals(progress["remaining_num_items"], 1) self.assertTrue(progress["type_info"].has_key("rpm")) self.assertEquals(progress["type_info"]["rpm"]["total_size_bytes"], 100) self.assertEquals(progress["type_info"]["rpm"]["size_left"], 95) self.assertEquals(progress["type_info"]["rpm"]["total_count"], 1) self.assertEquals(progress["type_info"]["rpm"]["items_left"], 1) self.assertEquals(progress["type_info"]["rpm"]["num_success"], 0) self.assertEquals(progress["type_info"]["rpm"]["num_error"], 0)
def test_progress_after_refetch_of_item(self): tracker = ProgressTracker() progress = tracker.get_progress() fetchURL = "http://test1" tracker.add_item(fetchURL, 100, "rpm") tracker.update_progress_download(fetchURL, 80, 5) tracker.reset_progress(fetchURL) progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 80) self.assertEquals(progress["remaining_bytes"], 80) self.assertEquals(progress["total_num_items"], 1) self.assertEquals(progress["remaining_num_items"], 1) self.assertTrue(progress["type_info"].has_key("rpm")) self.assertEquals(progress["type_info"]["rpm"]["total_size_bytes"], 80) self.assertEquals(progress["type_info"]["rpm"]["size_left"], 80) self.assertEquals(progress["type_info"]["rpm"]["total_count"], 1) self.assertEquals(progress["type_info"]["rpm"]["items_left"], 1) self.assertEquals(progress["type_info"]["rpm"]["num_success"], 0) self.assertEquals(progress["type_info"]["rpm"]["num_error"], 0) tracker.update_progress_download(fetchURL, 80, 5) progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 80) self.assertEquals(progress["remaining_bytes"], 75) tracker.item_complete("http://test1", True) progress = tracker.get_progress() self.assertEquals(progress["total_size_bytes"], 80) self.assertEquals(progress["remaining_bytes"], 0) self.assertEquals(progress["total_num_items"], 1) self.assertEquals(progress["remaining_num_items"], 0) self.assertTrue(progress["type_info"].has_key("rpm")) self.assertEquals(progress["type_info"]["rpm"]["total_size_bytes"], 80) self.assertEquals(progress["type_info"]["rpm"]["size_left"], 0) self.assertEquals(progress["type_info"]["rpm"]["total_count"], 1) self.assertEquals(progress["type_info"]["rpm"]["items_left"], 0) self.assertEquals(progress["type_info"]["rpm"]["num_success"], 1) self.assertEquals(progress["type_info"]["rpm"]["num_error"], 0)