def test_matching_initial_files_are_queued(self): persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) persist.add_pattern(AutoQueuePattern(pattern="File.Two")) persist.add_pattern(AutoQueuePattern(pattern="File.Three")) file_one = ModelFile("File.One", True) file_one.remote_size = 100 file_two = ModelFile("File.Two", True) file_two.remote_size = 200 file_three = ModelFile("File.Three", True) file_three.remote_size = 300 file_four = ModelFile("File.Four", True) file_four.remote_size = 400 file_five = ModelFile("File.Five", True) file_five.remote_size = 500 self.initial_model = [ file_one, file_two, file_three, file_four, file_five ] # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) auto_queue.process() calls = self.controller.queue_command.call_args_list self.assertEqual(3, len(calls)) commands = [calls[i][0][0] for i in range(3)] self.assertEqual(set([Controller.Command.Action.QUEUE] * 3), {c.action for c in commands}) self.assertEqual({"File.One", "File.Two", "File.Three"}, {c.filename for c in commands})
def test_patterns(self): patterns = [ AutoQueuePattern(pattern="one"), AutoQueuePattern(pattern="tw o"), AutoQueuePattern(pattern="th'ree"), AutoQueuePattern(pattern="fo\"ur"), AutoQueuePattern(pattern="fi=ve") ] out = SerializeAutoQueue.patterns(patterns) out_list = json.loads(out) self.assertEqual(5, len(out_list)) self.assertEqual([ { "pattern": "one" }, { "pattern": "tw o" }, { "pattern": "th'ree" }, { "pattern": "fo\"ur" }, { "pattern": "fi=ve" }, ], out_list)
def test_add_good(self): resp = self.test_app.get("/server/autoqueue/add/one") self.assertEqual(200, resp.status_int) self.assertEqual(1, len(self.auto_queue_persist.patterns)) self.assertIn(AutoQueuePattern("one"), self.auto_queue_persist.patterns) uri = quote(quote("/value/with/slashes", safe=""), safe="") resp = self.test_app.get("/server/autoqueue/add/" + uri) self.assertEqual(200, resp.status_int) self.assertEqual(2, len(self.auto_queue_persist.patterns)) self.assertIn(AutoQueuePattern("/value/with/slashes"), self.auto_queue_persist.patterns) uri = quote(quote(" value with spaces", safe=""), safe="") resp = self.test_app.get("/server/autoqueue/add/" + uri) self.assertEqual(200, resp.status_int) self.assertEqual(3, len(self.auto_queue_persist.patterns)) self.assertIn(AutoQueuePattern(" value with spaces"), self.auto_queue_persist.patterns) uri = quote(quote("value'with'singlequote", safe=""), safe="") resp = self.test_app.get("/server/autoqueue/add/" + uri) self.assertEqual(200, resp.status_int) self.assertEqual(4, len(self.auto_queue_persist.patterns)) self.assertIn(AutoQueuePattern("value'with'singlequote"), self.auto_queue_persist.patterns) uri = quote(quote("value\"with\"doublequote", safe=""), safe="") resp = self.test_app.get("/server/autoqueue/add/" + uri) self.assertEqual(200, resp.status_int) self.assertEqual(5, len(self.auto_queue_persist.patterns)) self.assertIn(AutoQueuePattern("value\"with\"doublequote"), self.auto_queue_persist.patterns)
def test_non_extractable_files_are_not_extracted(self): persist = AutoQueuePersist() file_one = ModelFile("File.One", True) file_one.local_size = 100 file_one.state = ModelFile.State.DOWNLOADED file_one.is_extractable = True file_two = ModelFile("File.Two", True) file_two.local_size = 200 file_two.state = ModelFile.State.DOWNLOADED file_two.is_extractable = False self.initial_model = [file_one, file_two] # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) auto_queue.process() self.controller.queue_command.assert_not_called() persist.add_pattern(AutoQueuePattern(pattern="File.One")) auto_queue.process() self.controller.queue_command.assert_called_once_with( unittest.mock.ANY) command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.EXTRACT, command.action) self.assertEqual("File.One", command.filename) self.controller.queue_command.reset_mock() persist.add_pattern(AutoQueuePattern(pattern="File.Two")) auto_queue.process() self.controller.queue_command.assert_not_called()
def test_adding_then_removing_pattern_doesnt_queue_existing_file(self): persist = AutoQueuePersist() file_one = ModelFile("File.One", True) file_one.remote_size = 100 file_two = ModelFile("File.Two", True) file_two.remote_size = 200 file_three = ModelFile("File.Three", True) file_three.remote_size = 300 file_four = ModelFile("File.Four", True) file_four.remote_size = 400 file_five = ModelFile("File.Five", True) file_five.remote_size = 500 self.initial_model = [ file_one, file_two, file_three, file_four, file_five ] # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) auto_queue.process() self.controller.queue_command.assert_not_called() persist.add_pattern(AutoQueuePattern(pattern="File.One")) persist.remove_pattern(AutoQueuePattern(pattern="File.One")) auto_queue.process() self.controller.queue_command.assert_not_called()
def test_matching_is_case_insensitive(self): persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="FiLe.oNe")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) file_one = ModelFile("File.One", True) file_one.remote_size = 100 self.model_listener.file_added(file_one) auto_queue.process() command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.QUEUE, command.action) self.assertEqual("File.One", command.filename) persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) file_one = ModelFile("FiLe.oNe", True) file_one.remote_size = 100 self.model_listener.file_added(file_one) auto_queue.process() command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.QUEUE, command.action) self.assertEqual("FiLe.oNe", command.filename)
def test_add_blank_pattern_fails(self): persist = AutoQueuePersist() with self.assertRaises(ValueError): persist.add_pattern(AutoQueuePattern(pattern="")) with self.assertRaises(ValueError): persist.add_pattern(AutoQueuePattern(pattern=" ")) with self.assertRaises(ValueError): persist.add_pattern(AutoQueuePattern(pattern=" "))
def test_to_str(self): self.assertEqual("{\"pattern\": \"file.one\"}", AutoQueuePattern(pattern="file.one").to_str()) self.assertEqual("{\"pattern\": \"file'one\"}", AutoQueuePattern(pattern="file'one").to_str()) self.assertEqual("{\"pattern\": \"file\\\"one\"}", AutoQueuePattern(pattern="file\"one").to_str()) self.assertEqual("{\"pattern\": \"fil(eo)ne\"}", AutoQueuePattern(pattern="fil(eo)ne").to_str())
def test_listener_pattern_removed_non_existing(self): listener = TestAutoQueuePersistListener() listener.pattern_removed = MagicMock() persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="one")) persist.add_pattern(AutoQueuePattern(pattern="two")) persist.add_pattern(AutoQueuePattern(pattern="three")) persist.add_listener(listener) persist.remove_pattern(AutoQueuePattern(pattern="four")) listener.pattern_removed.assert_not_called()
def test_is_list(self): patterns = [ AutoQueuePattern(pattern="one"), AutoQueuePattern(pattern="two"), AutoQueuePattern(pattern="three") ] out = SerializeAutoQueue.patterns(patterns) out_list = json.loads(out) self.assertIsInstance(out_list, list) self.assertEqual(3, len(out_list))
def test_listener_pattern_added_duplicate(self): listener = TestAutoQueuePersistListener() listener.pattern_added = MagicMock() persist = AutoQueuePersist() persist.add_listener(listener) persist.add_pattern(AutoQueuePattern(pattern="one")) listener.pattern_added.assert_called_once_with( AutoQueuePattern(pattern="one")) listener.pattern_added.reset_mock() persist.add_pattern(AutoQueuePattern(pattern="one")) listener.pattern_added.assert_not_called()
def test_new_matching_pattern_queues_existing_files(self): persist = AutoQueuePersist() file_one = ModelFile("File.One", True) file_one.remote_size = 100 file_two = ModelFile("File.Two", True) file_two.remote_size = 200 file_three = ModelFile("File.Three", True) file_three.remote_size = 300 file_four = ModelFile("File.Four", True) file_four.remote_size = 400 file_five = ModelFile("File.Five", True) file_five.remote_size = 500 self.initial_model = [ file_one, file_two, file_three, file_four, file_five ] # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) auto_queue.process() self.controller.queue_command.assert_not_called() persist.add_pattern(AutoQueuePattern(pattern="File.One")) auto_queue.process() self.controller.queue_command.assert_called_once_with( unittest.mock.ANY) command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.QUEUE, command.action) self.assertEqual("File.One", command.filename) self.controller.queue_command.reset_mock() persist.add_pattern(AutoQueuePattern(pattern="File.Two")) auto_queue.process() self.controller.queue_command.assert_called_once_with( unittest.mock.ANY) command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.QUEUE, command.action) self.assertEqual("File.Two", command.filename) self.controller.queue_command.reset_mock() persist.add_pattern(AutoQueuePattern(pattern="File.Three")) auto_queue.process() self.controller.queue_command.assert_called_once_with( unittest.mock.ANY) command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.QUEUE, command.action) self.assertEqual("File.Three", command.filename) self.controller.queue_command.reset_mock() auto_queue.process() self.controller.queue_command.assert_not_called()
def test_matching_new_files_are_extracted(self): persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) persist.add_pattern(AutoQueuePattern(pattern="File.Two")) persist.add_pattern(AutoQueuePattern(pattern="File.Three")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) file_one = ModelFile("File.One", True) file_one.state = ModelFile.State.DOWNLOADED file_one.local_size = 100 file_one.is_extractable = True file_two = ModelFile("File.Two", True) file_two.state = ModelFile.State.DOWNLOADED file_two.local_size = 200 file_two.is_extractable = True file_three = ModelFile("File.Three", True) file_three.state = ModelFile.State.DOWNLOADED file_three.local_size = 300 file_three.is_extractable = True self.model_listener.file_added(file_one) auto_queue.process() command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.EXTRACT, command.action) self.assertEqual("File.One", command.filename) self.model_listener.file_added(file_two) auto_queue.process() command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.EXTRACT, command.action) self.assertEqual("File.Two", command.filename) self.model_listener.file_added(file_three) auto_queue.process() command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.EXTRACT, command.action) self.assertEqual("File.Three", command.filename) # All at once self.model_listener.file_added(file_one) self.model_listener.file_added(file_two) self.model_listener.file_added(file_three) auto_queue.process() calls = self.controller.queue_command.call_args_list[-3:] commands = [calls[i][0][0] for i in range(3)] self.assertEqual(set([Controller.Command.Action.EXTRACT] * 3), {c.action for c in commands}) self.assertEqual({"File.One", "File.Two", "File.Three"}, {c.filename for c in commands})
def test_get(self): self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="one")) self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="t wo")) self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="thr'ee")) self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="fo\"ur")) self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="fi%ve")) resp = self.test_app.get("/server/autoqueue/get") self.assertEqual(200, resp.status_int) json_list = json.loads(str(resp.html)) self.assertEqual(5, len(json_list)) self.assertIn({"pattern": "one"}, json_list) self.assertIn({"pattern": "t wo"}, json_list) self.assertIn({"pattern": "thr'ee"}, json_list) self.assertIn({"pattern": "fo\"ur"}, json_list) self.assertIn({"pattern": "fi%ve"}, json_list)
def test_downloaded_file_is_NOT_re_extracted_after_modified(self): persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) # File is auto-extracted file_one = ModelFile("File.One", True) file_one.local_size = 100 file_one.state = ModelFile.State.DOWNLOADED file_one.is_extractable = True self.model_listener.file_added(file_one) auto_queue.process() self.controller.queue_command.assert_called_once_with( unittest.mock.ANY) command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.EXTRACT, command.action) self.assertEqual("File.One", command.filename) self.controller.queue_command.reset_mock() # File is modified file_one_new = ModelFile("File.One", True) file_one_new.local_size = 101 file_one_new.state = ModelFile.State.DOWNLOADED file_one_new.is_extractable = True self.model_listener.file_updated(file_one, file_one_new) auto_queue.process() self.controller.queue_command.assert_not_called()
def test_partial_file_is_auto_queued_after_remote_discovery(self): # Test that a partial local file is auto-queued when discovered on remote some time later persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) # Local discovery file_one = ModelFile("File.One", True) file_one.local_size = 100 self.model_listener.file_added(file_one) auto_queue.process() self.controller.queue_command.assert_not_called() # Remote discovery file_one_new = ModelFile("File.One", True) file_one_new.local_size = 100 file_one_new.remote_size = 200 self.model_listener.file_updated(file_one, file_one_new) auto_queue.process() self.controller.queue_command.assert_called_once_with( unittest.mock.ANY) command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.QUEUE, command.action) self.assertEqual("File.One", command.filename)
def test_downloaded_file_with_changed_remote_size_is_queued(self): # Disable auto-extract self.context.config.autoqueue.auto_extract = False persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) file_one = ModelFile("File.One", True) file_one.remote_size = 100 file_one.local_size = 100 file_one.state = ModelFile.State.DOWNLOADED self.model_listener.file_added(file_one) auto_queue.process() self.controller.queue_command.assert_not_called() file_one_updated = ModelFile("File.One", True) file_one_updated.remote_size = 200 file_one_updated.local_size = 100 file_one_updated.state = ModelFile.State.DEFAULT self.model_listener.file_updated(file_one, file_one_updated) auto_queue.process() self.controller.queue_command.assert_called_once_with( unittest.mock.ANY) command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.QUEUE, command.action) self.assertEqual("File.One", command.filename)
def test_all_files_are_extracted_when_patterns_only_disabled(self): self.context.config.autoqueue.patterns_only = False persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) persist.add_pattern(AutoQueuePattern(pattern="File.Two")) persist.add_pattern(AutoQueuePattern(pattern="File.Three")) file_one = ModelFile("File.One", True) file_one.local_size = 100 file_one.state = ModelFile.State.DOWNLOADED file_one.is_extractable = True file_two = ModelFile("File.Two", True) file_two.local_size = 200 file_two.state = ModelFile.State.DOWNLOADED file_two.is_extractable = True file_three = ModelFile("File.Three", True) file_three.local_size = 300 file_three.state = ModelFile.State.DOWNLOADED file_three.is_extractable = True file_four = ModelFile("File.Four", True) file_four.local_size = 400 file_four.state = ModelFile.State.DOWNLOADED file_four.is_extractable = True file_five = ModelFile("File.Five", True) file_five.local_size = 500 file_five.state = ModelFile.State.DOWNLOADED file_five.is_extractable = True self.initial_model = [ file_one, file_two, file_three, file_four, file_five ] # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) auto_queue.process() calls = self.controller.queue_command.call_args_list self.assertEqual(5, len(calls)) commands = [calls[i][0][0] for i in range(5)] self.assertEqual(set([Controller.Command.Action.EXTRACT] * 5), {c.action for c in commands}) self.assertEqual( {"File.One", "File.Two", "File.Three", "File.Four", "File.Five"}, {c.filename for c in commands})
def test_remove_pattern(self): persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="one")) persist.add_pattern(AutoQueuePattern(pattern="two")) persist.remove_pattern(AutoQueuePattern(pattern="one")) self.assertEqual({AutoQueuePattern(pattern="two")}, persist.patterns) persist.add_pattern(AutoQueuePattern(pattern="one")) persist.add_pattern(AutoQueuePattern(pattern="three")) persist.remove_pattern(AutoQueuePattern(pattern="two")) self.assertEqual( { AutoQueuePattern(pattern="one"), AutoQueuePattern(pattern="three") }, persist.patterns)
def test_no_files_are_extracted_when_auto_extract_disabled(self): self.context.config.autoqueue.enabled = True self.context.config.autoqueue.auto_extract = False persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) persist.add_pattern(AutoQueuePattern(pattern="File.Two")) persist.add_pattern(AutoQueuePattern(pattern="File.Three")) file_one = ModelFile("File.One", True) file_one.local_size = 100 file_one.state = ModelFile.State.DOWNLOADED file_two = ModelFile("File.Two", True) file_two.local_size = 200 file_two.state = ModelFile.State.DOWNLOADED file_three = ModelFile("File.Three", True) file_three.local_size = 300 file_three.state = ModelFile.State.DOWNLOADED file_four = ModelFile("File.Four", True) file_four.local_size = 400 file_four.state = ModelFile.State.DOWNLOADED file_five = ModelFile("File.Five", True) file_five.local_size = 500 file_five.state = ModelFile.State.DOWNLOADED self.initial_model = [ file_one, file_two, file_three, file_four, file_five ] # First with patterns_only ON self.context.config.autoqueue.patterns_only = True # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) auto_queue.process() self.controller.queue_command.assert_not_called() # Second with patterns_only OFF self.context.config.autoqueue.patterns_only = False # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) auto_queue.process() self.controller.queue_command.assert_not_called()
def test_matching_queued_files_are_not_queued(self): persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) file_one = ModelFile("File.One", True) file_one.remote_size = 100 file_one.state = ModelFile.State.QUEUED self.model_listener.file_added(file_one) auto_queue.process() self.controller.queue_command.assert_not_called()
def test_get_is_ordered(self): self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="a")) self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="b")) self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="c")) self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="d")) self.auto_queue_persist.add_pattern(AutoQueuePattern(pattern="e")) resp = self.test_app.get("/server/autoqueue/get") self.assertEqual(200, resp.status_int) json_list = json.loads(str(resp.html)) self.assertEqual(5, len(json_list)) self.assertEqual([{ "pattern": "a" }, { "pattern": "b" }, { "pattern": "c" }, { "pattern": "d" }, { "pattern": "e" }], json_list)
def __handle_remove_autoqueue(self, pattern: str): # value is double encoded pattern = unquote(pattern) aqp = AutoQueuePattern(pattern=pattern) if aqp not in self.__auto_queue_persist.patterns: return HTTPResponse( body="Auto-queue pattern '{}' doesn't exist.".format(pattern), status=400) else: self.__auto_queue_persist.remove_pattern(aqp) return HTTPResponse( body="Removed auto-queue pattern '{}'.".format(pattern))
def test_removed_pattern_doesnt_queue_new_file(self): persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="One")) persist.add_pattern(AutoQueuePattern(pattern="Two")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) file_one = ModelFile("File.One", True) file_one.remote_size = 100 self.model_listener.file_added(file_one) auto_queue.process() command = self.controller.queue_command.call_args[0][0] self.assertEqual(Controller.Command.Action.QUEUE, command.action) self.assertEqual("File.One", command.filename) self.controller.queue_command.reset_mock() persist.remove_pattern(AutoQueuePattern(pattern="Two")) file_two = ModelFile("File.Two", True) file_two.remote_size = 100 self.model_listener.file_added(file_two) auto_queue.process() self.controller.queue_command.assert_not_called()
def test_matching_downloaded_files_are_not_queued(self): # Disable auto-extract self.context.config.autoqueue.auto_extract = False persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="File.One")) # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) file_one = ModelFile("File.One", True) file_one.remote_size = 100 file_one.state = ModelFile.State.DOWNLOADED self.model_listener.file_added(file_one) auto_queue.process() self.controller.queue_command.assert_not_called()
def test_from_str(self): self.assertEqual( AutoQueuePattern(pattern="file.one"), AutoQueuePattern.from_str("{\"pattern\": \"file.one\"}"), ) self.assertEqual( AutoQueuePattern(pattern="file'one"), AutoQueuePattern.from_str("{\"pattern\": \"file'one\"}"), ) self.assertEqual( AutoQueuePattern(pattern="file\"one"), AutoQueuePattern.from_str("{\"pattern\": \"file\\\"one\"}"), ) self.assertEqual( AutoQueuePattern(pattern="fil(eo)ne"), AutoQueuePattern.from_str("{\"pattern\": \"fil(eo)ne\"}"), )
def test_to_and_from_str(self): persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="one")) persist.add_pattern(AutoQueuePattern(pattern="two")) persist.add_pattern(AutoQueuePattern(pattern="th ree")) persist.add_pattern(AutoQueuePattern(pattern="fo.ur")) persist.add_pattern(AutoQueuePattern(pattern="fi\"ve")) persist.add_pattern(AutoQueuePattern(pattern="si'x")) persist_actual = AutoQueuePersist.from_str(persist.to_str()) self.assertEqual(persist.patterns, persist_actual.patterns)
def __handle_add_autoqueue(self, pattern: str): # value is double encoded pattern = unquote(pattern) aqp = AutoQueuePattern(pattern=pattern) if aqp in self.__auto_queue_persist.patterns: return HTTPResponse( body="Auto-queue pattern '{}' already exists.".format(pattern), status=400) else: try: self.__auto_queue_persist.add_pattern(aqp) return HTTPResponse( body="Added auto-queue pattern '{}'.".format(pattern)) except ValueError as e: return HTTPResponse(body=str(e), status=400)
def test_new_matching_pattern_doesnt_queue_local_file(self): persist = AutoQueuePersist() file_one = ModelFile("File.One", True) file_one.local_size = 100 self.initial_model = [file_one] # noinspection PyTypeChecker auto_queue = AutoQueue(self.context, persist, self.controller) auto_queue.process() self.controller.queue_command.assert_not_called() persist.add_pattern(AutoQueuePattern(pattern="File.One")) auto_queue.process() self.controller.queue_command.assert_not_called()
def test_listener_pattern_removed(self): listener = TestAutoQueuePersistListener() listener.pattern_removed = MagicMock() persist = AutoQueuePersist() persist.add_pattern(AutoQueuePattern(pattern="one")) persist.add_pattern(AutoQueuePattern(pattern="two")) persist.add_pattern(AutoQueuePattern(pattern="three")) persist.add_listener(listener) persist.remove_pattern(AutoQueuePattern(pattern="one")) listener.pattern_removed.assert_called_once_with( AutoQueuePattern(pattern="one")) listener.pattern_removed.reset_mock() persist.remove_pattern(AutoQueuePattern(pattern="two")) listener.pattern_removed.assert_called_once_with( AutoQueuePattern(pattern="two")) listener.pattern_removed.reset_mock()