def test_sync_one_task(self): task_sync = TaskLibrarySync() task_filename = 'task4.rpm' task_rpm_disk = os.path.join(task_sync.tasklib.rpmspath, task_filename) task_sync.sync_tasks(['%s%s' % (self.task_url, task_filename)]) with session.begin(): tasks = Task.query.filter(Task.rpm == task_filename).all() self.assertEqual(len(tasks), 1) self.assertTrue(os.path.exists(task_rpm_disk))
def test_invalid_task_rpm_is_not_synced(self): task_sync = TaskLibrarySync() # add a task to DB task_filename = 'bad-task1.rpm' # task RPM in test dir task_rpm_disk = os.path.join(task_sync.tasklib.rpmspath, task_filename) task_sync.sync_tasks(['%s%s' % (self.task_url, task_filename)]) with session.begin(): tasks = Task.query.filter(Task.rpm == task_filename).all() self.assertEqual(len(tasks), 0) self.assertFalse(os.path.exists(task_rpm_disk))
def test_sync_two_tasks(self): task_sync = TaskLibrarySync() task_filename1 = "task1.rpm" task_filename2 = "task2.rpm" task_rpm_disk1 = os.path.join(task_sync.tasklib.rpmspath, task_filename1) task_rpm_disk2 = os.path.join(task_sync.tasklib.rpmspath, task_filename2) task_sync.sync_tasks(["%s%s" % (self.task_url, task_filename1), "%s%s" % (self.task_url, task_filename2)]) with session.begin(): tasks = Task.query.filter(Task.rpm == task_filename1).all() self.assertEqual(len(tasks), 1) tasks = Task.query.filter(Task.rpm == task_filename2).all() self.assertEqual(len(tasks), 1) self.assertTrue(os.path.exists(task_rpm_disk1)) self.assertTrue(os.path.exists(task_rpm_disk2))
def test_sync_two_tasks(self): task_sync = TaskLibrarySync() task_filename1 = 'task1.rpm' task_filename2 = 'task2.rpm' task_rpm_disk1 = os.path.join(task_sync.tasklib.rpmspath, task_filename1) task_rpm_disk2 = os.path.join(task_sync.tasklib.rpmspath, task_filename2) task_sync.sync_tasks(['%s%s' % (self.task_url, task_filename1), '%s%s' % (self.task_url, task_filename2)]) with session.begin(): tasks = Task.query.filter(Task.rpm == task_filename1).all() self.assertEqual(len(tasks), 1) tasks = Task.query.filter(Task.rpm == task_filename2).all() self.assertEqual(len(tasks), 1) self.assertTrue(os.path.exists(task_rpm_disk1)) self.assertTrue(os.path.exists(task_rpm_disk2))
def test_sync_two_tasks_one_fails(self): task_sync = TaskLibrarySync() task_sync.batch_size = 1 good_task = 'task3.rpm' good_task_url = '%s%s' % (self.task_url, good_task) # We need this URL to end up sorted after the real one, hence 'x' bad_task = 'thisisnotreal.rpm' bad_task_url = '%s%s' % ('http://x.example.com/', bad_task) task_rpm_disk = os.path.join(task_sync.tasklib.rpmspath, good_task) try: task_sync.sync_tasks([good_task_url, bad_task_url]) except Exception: pass with session.begin(): tasks = Task.query.filter(Task.rpm == good_task).all() self.assertEqual(len(tasks), 1) tasks = Task.query.filter(Task.rpm == bad_task).all() self.assertEqual(len(tasks), 0) self.assertTrue(os.path.exists(task_rpm_disk))
def test_sync_two_tasks_one_fails(self): task_sync = TaskLibrarySync() task_sync.batch_size = 1 good_task = "task3.rpm" good_task_url = "%s%s" % (self.task_url, good_task) # We need this URL to end up sorted after the real one, hence 'x' bad_task = "thisisnotreal.rpm" bad_task_url = "%s%s" % ("http://x.example.com/", bad_task) task_rpm_disk = os.path.join(task_sync.tasklib.rpmspath, good_task) try: task_sync.sync_tasks([good_task_url, bad_task_url]) except Exception: pass with session.begin(): tasks = Task.query.filter(Task.rpm == good_task).all() self.assertEqual(len(tasks), 1) tasks = Task.query.filter(Task.rpm == bad_task).all() self.assertEqual(len(tasks), 0) self.assertTrue(os.path.exists(task_rpm_disk))