Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 def return_sources(self) -> str:
     """
         Obtém o conteúdo, organiza e retorna os cards gerados."""
     phrases = get_from_txt(self.source)
     if len(phrases) == 0:
         return phrases
     for phrase in phrases:
         self.writer.update_contents(phrase, self.source)
     return self.writer.return_written_cards()
Exemplo n.º 3
0
 def update_sources(self) -> None:
     """
         Atualiza a fonte de conteúdo após a escrita de objetos MyCard e posterior inserção no banco de dados."""
     contents = self.writer.contents
     if len(contents) == 0:
         return
     phrases = [card['phrase'] for card in contents]
     source = get_from_txt(self.source)
     update = [phrase for phrase in source if phrase not in phrases]
     with open(self.source, "w") as source:
         for phrase in update:
             source.write(f"{phrase}\n")
 def test_obtained_phrases(self):
     """
         TESTA SE É POSSÍVEL OBTER UMA LISTA CONTENDO STRINGS DE UM ARQUÍVO file DE EXTENSÃO .TXT. AS STRINGS DEVEM SER CONFORME AS FRASES CONTIDAS NA LISTA frases."""
     frases = [            
         "Take this time, Francis, to know your other attendees.",
         "Tell me you're not peddling influence with your wife?",
         "The Russian research vessel.",
         "Let's reconvene when you know more.",
     ]
     file = "frasesTestePreenchida.txt"
     path = os.path.join(SAMPLE_FOLDER, file)
     phrases = get_from_txt(path)
     self.assertEqual(phrases, frases)
Exemplo n.º 5
0
 def test__update_cards_clear_all_phrases_in_file(self):
     self.sourceAdmin.return_sources()
     self.sourceAdmin.update_sources()
     expected = get_from_txt(self.source)
     self.assertEqual(expected, [])
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 def setUp(self):
     self.source = filled_text_path
     self.src_before = get_from_txt(self.source)
     self.writer = DictBasedCardWriter()