class TestDictBasedCardWriter(TestCase): def setUp(self): self.source = filled_text_path self.src_before = get_from_txt(self.source) self.writer = DictBasedCardWriter() def tearDown(self): text_source_reset(self.source, self.src_before) def test_update_contents_works(self): phrases = self.src_before for phrase in phrases: self.writer.update_contents(phrase, self.source) expected = [{ 'phrase': phrase, 'source': self.source } for phrase in phrases] self.assertEqual(expected, self.writer.contents) def test__return_written_cards_returns_equal_amount_src(self): phrases = self.src_before for phrase in phrases: self.writer.update_contents(phrase, self.source) card_list = self.writer.return_written_cards() expected = len(card_list) self.assertEqual(expected, len(self.src_before)) def test_return_written_cards_returns_MyCard_instances(self): phrases = self.src_before for phrase in phrases: self.writer.update_contents(phrase, self.source) card_list = self.writer.return_written_cards() for card in card_list: self.assertEqual(isinstance(card, MyCard), True)
def test__run_task_returns_None_if_no_text_phrases(self, mocked): writer = DictBasedCardWriter() textAdm = TextSourceAdmin(config_file_path, writer) textAdm.source = empty_text_path ac = AutoFlashCards('_', textAdm, self.db_admin) ac.run_task() mocked.assert_not_called()
def setUp(self): self.db_source = os.path.join(SAMPLE_FOLDER, "db_cards_test") self.db_key = "test_key" self.db_source_before = [] self.text_src = filled_text_path self.text_src_before = get_from_txt(self.text_src) writer = DictBasedCardWriter() self.textAdmin = TextSourceAdmin(config_file_path, writer)
from src.clss.configurators import WebDriverConfigurator from src.clss.cardDeliverers import SeleniumAnkiBot from src.clss.cardWriter import DictBasedCardWriter from src.clss.imageSources import LocalFolderSource from src.clss.TextExtractors import GoogleVision from src.clss.sourceAdmins import ImageSourceAdmin from src.clss.sourceAdmins import MyCardShelveAdmin from . import CONFIG_FILE path = os.path.join(os.getcwd(), 'data.json') folder_path = login_path = path writer = DictBasedCardWriter() img_source = LocalFolderSource(CONFIG_FILE) text_extractor = GoogleVision() wdconfig = WebDriverConfigurator(CONFIG_FILE) selenium_anki_bot_args = { 'web_driver_settings': wdconfig, 'user_data': CONFIG_FILE } deliver = SeleniumAnkiBot(**selenium_anki_bot_args) #deliver = SeleniumAnkiBot(Firefox, login_path) img_admin = ImageSourceAdmin(img_source, writer, text_extractor) db = MyCardShelveAdmin('db', 'cards') automaton = AutoFlashCards(deliver, img_admin, db)
def setUp(self): self.source = filled_text_path self.src_before = get_from_txt(self.source) self.writer = DictBasedCardWriter() self.sourceAdmin = TextSourceAdmin(config_file_path, self.writer)
def setUp(self): self.source = filled_text_path self.src_before = get_from_txt(self.source) self.writer = DictBasedCardWriter()
def setUp(self): path = config_file_path self.mockImgSource = MockImageSource(path) self.writer = DictBasedCardWriter()
def setUp(self): path = os.path.join(SAMPLE_FOLDER, 'config(sample).json') self.mockImgSource = MockImageSource(path) self.writer = DictBasedCardWriter()