def test_wiki_replace_pages_from_dir(self): names = self._insert_pages(2) path1 = os.path.join(self.tempdir, names[0]) path2 = os.path.join(self.tempdir, names[1]) content1 = random_paragraph() content2 = random_paragraph() with open(path1, 'w') as f: f.write(content1) with open(path2, 'w') as f: f.write(content2) os.mkdir(os.path.join(self.tempdir, 'subdir')) rv, output = self.execute('replace', self.tempdir) page1 = WikiPage(self.env, names[0]) page2 = WikiPage(self.env, names[1]) self.assertEqual(0, rv, output) self.assertExpectedResult(output, { 'name1': names[0], 'name2': names[1], 'path1': path1, 'path2': path2, }) self.assertEqual(content1, page1.text) self.assertEqual(content2, page2.text) self.assertEqual(1, page1.version) self.assertEqual(1, page2.version)
def test_wiki_load_pages_from_dir(self): name1 = 'PageOne' name2 = 'PageTwo' path1 = os.path.join(self.tempdir, name1) path2 = os.path.join(self.tempdir, name2) content1 = random_paragraph() content2 = random_paragraph() with open(path1, 'w') as f: f.write(content1) with open(path2, 'w') as f: f.write(content2) os.mkdir(os.path.join(self.tempdir, 'subdir')) rv, output = self.execute('load', self.tempdir) page1 = WikiPage(self.env, name1) page2 = WikiPage(self.env, name2) self.assertEqual(0, rv, output) self.assertExpectedResult(output, { 'name1': name1, 'name2': name2, 'path1': path1, 'path2': path2, }) self.assertEqual(content1, page1.text) self.assertEqual(content2, page2.text) self.assertEqual(1, page1.version) self.assertEqual(1, page2.version)
def test_wiki_replace(self): name1 = random_unique_camel() name2 = random_unique_camel() path1 = os.path.join(self.tempdir, name1) path2 = os.path.join(self.tempdir, name2) content1 = random_paragraph() content2 = random_paragraph() self._insert_page(name1) self._insert_page(name2) with open(path1, 'w') as f: f.write(content1) with open(path2, 'w') as f: f.write(content2) rv, output = self.execute('replace', path1, path2) page1 = WikiPage(self.env, name1) page2 = WikiPage(self.env, name2) self.assertEqual(0, rv, output) self.assertExpectedResult(output, { 'name1': name1, 'name2': name2, 'path1': path1, 'path2': path2, }) self.assertIn(('INFO', '%s imported from %s' % (name1, path1)), self.env.log_messages) self.assertIn(('INFO', '%s imported from %s' % (name2, path2)), self.env.log_messages) self.assertEqual(content1, page1.text) self.assertEqual(content2, page2.text) self.assertEqual(1, page1.version) self.assertEqual(1, page2.version)
def _insert_page(self, name=None): page = WikiPage(self.env) if name is None: name = random_unique_camel() page.name = name page.text = random_paragraph() page.save('user1', 'Page created.') return name
def create_product(self, prefix=None, name=None, desc=None): """Create a product from the product list page.""" products_url = self.url + '/products' tc.go(products_url) tc.find('Products') tc.submit('add', 'new') tc.find('New Product') prefix = prefix or random_word() name = name or random_sentence() desc = desc or random_paragraph() tc.formvalue('edit', 'prefix', prefix) tc.formvalue('edit', 'name', name) tc.formvalue('edit', 'description', desc) tc.submit() tc.find('The product "%s" has been added' % prefix) return prefix, name
def _write_file(self, path, content=None): if content is None: content = random_paragraph() with open(path, 'w') as f: f.write(content) return content
def _change_page(self, name): page = WikiPage(self.env, name) page.text = random_paragraph() page.save('user2', 'Page changed.')