def test_write_node_to_learnf_file(self): config = FileStorageConfiguration() tmpdir = FileStorageConfiguration.get_temp_dir() + os.sep + "learnf" tmpfile = tmpdir + os.sep + "tmp" + os.sep + "test.xml" config.learnf_storage._dirs = [tmpdir] engine = FileStorageEngine(config) engine.initialise() store = FileLearnfStore(engine) test_client = TestClient() client_context = test_client.create_client_context("test1") learn_cat = LearnCategory(ET.Element("HELLO"), ET.Element("*"), ET.Element("*"), TemplateWordNode("Hi")) node = store.create_category_xml_node(client_context, learn_cat) with self.assertRaises(Exception): store.write_node_to_learnf_file(client_context, node, tmpfile)
def test_write_node_to_learnf_file_already_exists(self): config = FileStorageConfiguration() tmpdir = FileStorageConfiguration.get_temp_dir() + os.sep + "learnf" tmpfile = tmpdir + os.sep + "tmp" + os.sep + "test.xml" config.learnf_storage._dirs = [tmpdir] engine = FileStorageEngine(config) engine.initialise() store = FileLearnfStore(engine) test_client = TestClient() client_context = test_client.create_client_context("test1") learn_cat = LearnCategory(ET.Element("HELLO"), ET.Element("*"), ET.Element("*"), TemplateWordNode("Hi")) node = store.create_category_xml_node(client_context, learn_cat) store.write_node_to_learnf_file(client_context, node, tmpfile) self.assertTrue(os.path.exists(tmpfile)) store.write_node_to_learnf_file(client_context, node, tmpfile) if os.path.exists(tmpdir): shutil.rmtree(tmpdir)