<div dir="ltr"><div><div>Hello all,</div><div><br></div><div>See bug #783461</div><div>Link for the lazy: <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=783461">https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=783461</a></div><div><br></div><div>This is my first time committing a patch (on any software that isn't on Github)</div><div>so I might do stuff wrong. That being said I won't take criticism personally.</div><div><br></div><div>In order to avoid overwriting news, and also avoiding having to modify code </div><div>outside the tests, I chose to save the text data as a class attribute.</div><div><br></div><div>There are other ways to do it but they're more complex, or involve globals.</div><div> Let me know if this way is too hacky.</div><div><br></div><div>Cheers, </div><div>devoxel</div><div><br></div><div>---</div><div> debsources/tests/test_webapp.py | 12 +++++++++++-</div><div> debsources/tests/testdata.py Â  Â | 16 ++++++++++++++++</div><div> 2 files changed, 27 insertions(+), 1 deletion(-)</div><div><br></div><div>diff --git a/debsources/tests/test_webapp.py b/debsources/tests/test_webapp.py</div><div>index ccbf1b4..9343799 100644</div><div>--- a/debsources/tests/test_webapp.py</div><div>+++ b/debsources/tests/test_webapp.py</div><div>@@ -20,7 +20,7 @@ from nose.plugins.attrib import attr</div><div><br></div><div> from debsources.app.app_factory import AppWrapper</div><div> from debsources.tests.db_testing import DbTestFixture</div><div>-from debsources.tests.testdata import TEST_DB_NAME</div><div>+from debsources.tests.testdata import TEST_DB_NAME, create_news_file</div><div><br></div><div><br></div><div> @attr('basewebapp')</div><div>@@ -48,6 +48,13 @@ class DebsourcesBaseWebTests(DbTestFixture):</div><div>  Â  Â  Â  Â cls.app = app_wrapper.app.test_client()</div><div>  Â  Â  Â  Â cls.app_wrapper = app_wrapper</div><div><br></div><div>+ Â  Â  Â  Â # Create temporary news files to test, they return the data written to</div><div>+ Â  Â  Â  Â # the file, or the data that was already there if they already existed</div><div>+ Â  Â  Â  Â cls.source_news_data = create_news_file(</div><div>+ Â  Â  Â  Â  Â  Â cls.app_wrapper.app.config["LOCAL_DIR"],</div><div>+ Â  Â  Â  Â  Â  Â 'sources_news.html'</div><div>+ Â  Â  Â  Â )</div><div>+</div><div>  Â  Â @classmethod</div><div>  Â  Â def tearDownClass(cls):</div><div>  Â  Â  Â  Â cls.app_wrapper.engine.dispose()</div><div>@@ -556,6 +563,9 @@ class DebsourcesTestCase(DebsourcesBaseWebTests, unittest.TestCase):</div><div>  Â  Â  Â  Â  Â  Â rv = self.app.get('/copyright/')</div><div>  Â  Â  Â  Â  Â  Â self.assertEqual(200, rv.status_code)</div><div><br></div><div>+ Â  Â def test_index_help(self):</div><div>+ Â  Â  Â  Â rv = self.app.get('/')</div><div>+ Â  Â  Â  Â self.assertIn(self.source_news_data, rv.data)</div><div><br></div><div> if __name__ == '__main__':</div><div>  Â  Â unittest.main(exit=False)</div><div>diff --git a/debsources/tests/testdata.py b/debsources/tests/testdata.py</div><div>index ff411cd..2751301 100644</div><div>--- a/debsources/tests/testdata.py</div><div>+++ b/debsources/tests/testdata.py</div><div>@@ -16,3 +16,19 @@ import os</div><div> TEST_DIR = os.path.dirname(os.path.abspath(__file__))</div><div> TEST_DATA_DIR = os.path.join(TEST_DIR, 'data')</div><div> TEST_DB_NAME = 'debsources-test'</div><div>+</div><div>+</div><div>+def create_news_file(local_dir, name):</div><div>+ Â  Â """Returns news file contents"""</div><div>+ Â  Â fullpath = os.path.join(local_dir, name)</div><div>+ Â  Â # don't overwrite any news files that already exist</div><div>+ Â  Â if os.path.isfile(fullpath):</div><div>+ Â  Â  Â  Â news_string = ""</div><div>+ Â  Â  Â  Â with open(fullpath, 'r') as f:</div><div>+ Â  Â  Â  Â  Â  Â news_string = f.read()</div><div>+ Â  Â  Â  Â return news_string</div><div>+ Â  Â else:</div><div>+ Â  Â  Â  Â news_string = "<ul><li>This item was created in a test</li></ul>"</div><div>+ Â  Â  Â  Â with open(fullpath, 'w') as f:</div><div>+ Â  Â  Â  Â  Â  Â f.write(news_string)</div><div>+ Â  Â  Â  Â return news_string</div><div>--</div><div>2.1.4</div></div><div><br></div><div><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div style="font-size:12.8px"></div></div></div></div></div>
</div>