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