[Qa-debsources] [PATCH] Add test for index news, bug #783461

Matthieu Caneill matt at brokenwa.re
Tue Mar 22 06:53:09 UTC 2016


Hi,

On Tue, Mar 22, 2016 at 06:15:03AM +0000, Aaron Delaney wrote:
> Okay, fixed the issues we talked about in IRC and that. It no longer uses
> the
> testdata.py file, and the test data is loaded in the test itself.
> 
> I used git format-patch but not git send email, because mail.dcu.ie is
> handled
> by Gmail and I can't setup SMTP at the moment because of login redirects. I
> don't know how the line cap slipped in anyway.

Thanks! I could apply it locally.
Comments below.

> +    def create_news_file(self, name):
> +        """Returns news file contents"""

The description is not accurate. It indeed returns the file content,
but also has some side effect, etc.

> +        fullpath = os.path.join(self.app_wrapper.app.config["LOCAL_DIR"],
> name)
> +        # don't overwrite any news files that already exist
> +        if os.path.isfile(fullpath):
> +            news_string = ""
> +            with open(fullpath, 'r') as f:
> +                news_string = f.read()
> +            return news_string
> +        else:
> +            news_string = "<ul><li>This item was created in a
> test</li></ul>"
> +            with open(fullpath, 'w') as f:

This breaks when the folder local/ doesn't exist (which is the default
on a freshly cloned debsources). Please create the folder in that case.

> +                f.write(news_string)
> +            return news_string
> +
> 
>  @attr('webapp')
>  class DebsourcesTestCase(DebsourcesBaseWebTests, unittest.TestCase):
> @@ -556,6 +571,11 @@ class DebsourcesTestCase(DebsourcesBaseWebTests,
> unittest.TestCase):
>              rv = self.app.get('/copyright/')
>              self.assertEqual(200, rv.status_code)
> 
> +    def test_index_help(self):
> +        # create_news_file preserves existing news files
> +        source_news_data = self.create_news_file('sources_news.html')
> +        rv = self.app.get('/')
> +        self.assertIn(source_news_data, rv.data)

OK!

Also please use a commit message. Its title should describe what it
fixes (which you did), and the extended description can add more
details (if needed) and specify which bug it closes (Closes:
#bugnumber).

Thanks!
Cheers,
--
Matthieu



More information about the Qa-debsources mailing list