def test_push_invalid(self): ''' When passing in an invalid file, or one that is already open, does it raise Exception after going through exponential backoff? ''' # create FileQueue file_q = FileQueue(self.input_path, self.output_path, self.queue_path, self.archive_path) # test invalid case test_file = os.path.join(self.input_path, 'test_file.txt') self.assertFalse(os.path.isfile(test_file)) with self.assertRaises(Exception): file_q.push(test_file)
def test_pop_valid(self): ''' When popping a file, is it moved from the queue_path to the output_path and return the new file path? ''' # create FileQueue file_q = FileQueue(self.input_path, self.output_path, self.queue_path, self.archive_path) # create test file and push to the queue test_file = os.path.join(self.input_path, 'test_file.txt') with open(test_file, 'w') as file_: file_.write('test text') file_q.push(test_file) # test WITH timestamp (standard) out_file = file_q.pop() self.assertTrue(os.path.isfile(out_file)) archive_file = os.path.join(self.archive_path, os.path.basename(out_file)) self.assertTrue(os.path.isfile(out_file)) self.assertTrue(os.path.isfile(archive_file)) self.assertNotEqual(os.path.basename(out_file), os.path.basename(test_file)) self.assertEqual(os.path.dirname(out_file), self.output_path) queue_file = os.path.join(self.queue_path, os.path.basename(test_file)) self.assertFalse(os.path.isfile(queue_file)) self.assertFalse(os.path.isfile(test_file)) with open(test_file, 'w') as file_: file_.write('test text') file_q.push(test_file) # test WITHOUT timestamp out_file = file_q.pop(addtimestamp=False) self.assertTrue(os.path.isfile(out_file)) self.assertTrue( os.path.isfile(os.path.join(self.output_path, 'test_file.txt'))) self.assertTrue( os.path.isfile(os.path.join(self.archive_path, 'test_file.txt'))) self.assertEqual(os.path.basename(out_file), os.path.basename(test_file)) self.assertEqual(os.path.dirname(out_file), self.output_path) queue_file = os.path.join(self.queue_path, os.path.basename(test_file)) self.assertFalse(os.path.isfile(queue_file)) self.assertFalse(os.path.isfile(test_file))
def test_push_valid(self): ''' When pushing a file is it moved the queue_path and return True? ''' # create FileQueue file_q = FileQueue(self.input_path, self.output_path, self.queue_path, self.archive_path) # create test file to push test_file = os.path.join(self.input_path, 'test_file.txt') with open(test_file, 'w') as file_: file_.write('test text') self.assertTrue(os.path.isfile(test_file)) # test valid case result = file_q.push(test_file) self.assertTrue(result) queue_file = os.path.join(self.queue_path, os.path.basename(test_file)) self.assertTrue(os.path.isfile(queue_file)) self.assertFalse(os.path.isfile(test_file))