[Qa-debsources] [PATCH] Add test for index news, bug #783461
Aaron Delaney
aaron.delaney29 at mail.dcu.ie
Mon Mar 21 06:50:22 UTC 2016
Hello all,
See bug #783461
Link for the lazy: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=783461
This is my first time committing a patch (on any software that isn't on
Github)
so I might do stuff wrong. That being said I won't take criticism
personally.
In order to avoid overwriting news, and also avoiding having to modify code
outside the tests, I chose to save the text data as a class attribute.
There are other ways to do it but they're more complex, or involve globals.
Let me know if this way is too hacky.
Cheers,
devoxel
---
debsources/tests/test_webapp.py | 12 +++++++++++-
debsources/tests/testdata.py | 16 ++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/debsources/tests/test_webapp.py
b/debsources/tests/test_webapp.py
index ccbf1b4..9343799 100644
--- a/debsources/tests/test_webapp.py
+++ b/debsources/tests/test_webapp.py
@@ -20,7 +20,7 @@ from nose.plugins.attrib import attr
from debsources.app.app_factory import AppWrapper
from debsources.tests.db_testing import DbTestFixture
-from debsources.tests.testdata import TEST_DB_NAME
+from debsources.tests.testdata import TEST_DB_NAME, create_news_file
@attr('basewebapp')
@@ -48,6 +48,13 @@ class DebsourcesBaseWebTests(DbTestFixture):
cls.app = app_wrapper.app.test_client()
cls.app_wrapper = app_wrapper
+ # Create temporary news files to test, they return the data
written to
+ # the file, or the data that was already there if they already
existed
+ cls.source_news_data = create_news_file(
+ cls.app_wrapper.app.config["LOCAL_DIR"],
+ 'sources_news.html'
+ )
+
@classmethod
def tearDownClass(cls):
cls.app_wrapper.engine.dispose()
@@ -556,6 +563,9 @@ class DebsourcesTestCase(DebsourcesBaseWebTests,
unittest.TestCase):
rv = self.app.get('/copyright/')
self.assertEqual(200, rv.status_code)
+ def test_index_help(self):
+ rv = self.app.get('/')
+ self.assertIn(self.source_news_data, rv.data)
if __name__ == '__main__':
unittest.main(exit=False)
diff --git a/debsources/tests/testdata.py b/debsources/tests/testdata.py
index ff411cd..2751301 100644
--- a/debsources/tests/testdata.py
+++ b/debsources/tests/testdata.py
@@ -16,3 +16,19 @@ import os
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_DATA_DIR = os.path.join(TEST_DIR, 'data')
TEST_DB_NAME = 'debsources-test'
+
+
+def create_news_file(local_dir, name):
+ """Returns news file contents"""
+ fullpath = os.path.join(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:
+ f.write(news_string)
+ return news_string
--
2.1.4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/qa-debsources/attachments/20160321/733ae3b3/attachment.html>
More information about the Qa-debsources
mailing list