<div dir="ltr"><div><div><div><div><div><div>Hey,<br></div><div><br>Good review, I didn't pick up on the locals directory not existing and<br></div><div>your right about the bad docstring on the function.<br></div><div><br>I decided to ditch the function because it seemed more appropriate<br></div>to just keep everything in the one function now that it was handling<br></div>all news tests.<br></div><div><br></div>I've attached the file again, is that unnecessary or is it helpful to<br></div>you?<br><br></div>Let me know what you think,<br></div>- Aaron<br><div><div><div><div><br>From: Aaron Delaney <<a href="mailto:aaron.delaney29@mail.dcu.ie">aaron.delaney29@mail.dcu.ie</a>><br>Date: Mon, 21 Mar 2016 05:58:39 +0000<br>Subject: [PATCH] Add test for news files<br><br>Closes: #783461<br><br>Note that if a file called local exists where your local directory<br>should, the test will raise an IOError.<br>---<br> debsources/tests/test_webapp.py | 30 ++++++++++++++++++++++++++++++<br> 1 file changed, 30 insertions(+)<br><br>diff --git a/debsources/tests/test_webapp.py b/debsources/tests/test_webapp.py<br>index ccbf1b4..8b4b00d 100644<br>--- a/debsources/tests/test_webapp.py<br>+++ b/debsources/tests/test_webapp.py<br>@@ -556,6 +556,36 @@ class DebsourcesTestCase(DebsourcesBaseWebTests, unittest.TestCase):<br> rv = self.app.get('/copyright/')<br> self.assertEqual(200, rv.status_code)<br> <br>+ def test_news(self):<br>+ # news_routes = { news_filename: associated_route }<br>+ news_routes = {<br>+ 'sources_news.html': '/',<br>+ 'copyright_news.html': '/copyright/',<br>+ 'patches_news.html': '/patches/'<br>+ }<br>+ # Go through each news_route and ensure it contains the data we expect<br>+ # which is the data in local/news.html file.<br>+ # If data doesn't exist, create dummy data to test.<br>+ for news_file in news_routes.keys():<br>+ fullpath = os.path.join(self.app_wrapper.app.config["LOCAL_DIR"],<br>+ news_file)<br>+ news_string = ""<br>+ if not os.path.isdir(self.app_wrapper.app.config["LOCAL_DIR"]):<br>+ if os.path.exists(self.app_wrapper.app.config["LOCAL_DIR"]):<br>+ # for some reason local_dir is a file, raise an IOError<br>+ raise IOError<br>+ else:<br>+ os.makedirs(self.app_wrapper.app.config["LOCAL_DIR"])<br>+ if os.path.isfile(fullpath):<br>+ with open(fullpath, 'r') as f:<br>+ news_string = f.read()<br>+ else:<br>+ news_string = "<ul><li>This item was created in a test for " \<br>+ + news_file + "</li></ul>"<br>+ with open(fullpath, 'w') as f:<br>+ f.write(news_string)<br>+ rv = self.app.get(news_routes[news_file])<br>+ self.assertIn(news_string, rv.data)<br> <br> if __name__ == '__main__':<br> unittest.main(exit=False)<br>-- <br>2.1.4<br><br></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 22 March 2016 at 06:55, Matthieu Caneill <span dir="ltr"><<a href="mailto:matt@brokenwa.re" target="_blank">matt@brokenwa.re</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Mar 21, 2016 at 02:20:26PM +0000, Aaron Delaney wrote:<br>
> I can just use it in the test file if it makes more sense. Technically the<br>
> copyright andpatches have news kwargs, but they're not being used.<br>
> Should I test these too actually?<br>
<br>
</span>And I just saw this. Yes, that would be nice to test all the<br>
blueprints as well. The file creation and checking is probably<br>
loopable - looping over the defined blueprints.<br>
<br>
Cheers,<br>
<div class="HOEnZb"><div class="h5">--<br>
Matthieu<br>
<br>
_______________________________________________<br>
Qa-debsources mailing list<br>
<a href="mailto:Qa-debsources@lists.alioth.debian.org">Qa-debsources@lists.alioth.debian.org</a><br>
<a href="https://lists.alioth.debian.org/mailman/listinfo/qa-debsources" rel="noreferrer" target="_blank">https://lists.alioth.debian.org/mailman/listinfo/qa-debsources</a><br>
</div></div></blockquote></div><br></div>