From db0cfbacd3abfb64d50d51183d0fa00b6d9bd9a6 Mon Sep 17 00:00:00 2001 From: Tomasz Zielinski Date: Tue, 13 Dec 2011 23:18:09 +0100 Subject: Healing test suite --- .../0088_install__post_view__for__development.py | 2 +- askbot/tests/page_load_tests.py | 27 ++++++++++----- askbot/tests/utils.py | 39 +++++++++++++--------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/askbot/migrations/0088_install__post_view__for__development.py b/askbot/migrations/0088_install__post_view__for__development.py index 1066dc5d..a5439154 100644 --- a/askbot/migrations/0088_install__post_view__for__development.py +++ b/askbot/migrations/0088_install__post_view__for__development.py @@ -13,7 +13,7 @@ class Migration(SchemaMigration): askbot.get_path_to('models/post_view.sql') ).read() import warnings - warnings.filterwarnings("ignore", "Unknown table 'askbot.askbot_post'") # DROP VIEW might raise a warning so let's filter that out + warnings.filterwarnings("ignore", "Unknown table .*?\.askbot_post'") # DROP VIEW might raise a warning so let's filter that out db.execute('DROP VIEW IF EXISTS askbot_post') db.execute(create_post_view_sql) diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 8cebb602..318e42e8 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -36,14 +36,25 @@ if CMAJOR == 0 and CMINOR == 3 and CMICRO < 4: class PageLoadTestCase(AskbotTestCase): - if getattr(settings, 'ASKBOT_FAST_TESTS', False) == True: - fixtures = [ os.path.join(os.path.dirname(__file__), 'test_data.json'),] - def setUp(self): - if getattr(settings, 'ASKBOT_FAST_TESTS', False) == True: - return - else: - from django.core import management - management.call_command('askbot_add_test_content', verbosity=0, interactive=False) + + def _fixture_setup(self): + from django.core import management + management.call_command('askbot_add_test_content', verbosity=0, interactive=False) + super(PageLoadTestCase, self)._fixture_setup() + + def _fixture_teardown(self): + super(PageLoadTestCase, self)._fixture_teardown() + from django.core import management + management.call_command('flush', verbosity=0, interactive=False) + +# if getattr(settings, 'ASKBOT_FAST_TESTS', False) == True: +# fixtures = [ os.path.join(os.path.dirname(__file__), 'test_data.json'),] +# def setUp(self): +# if getattr(settings, 'ASKBOT_FAST_TESTS', False) == True: +# return +# else: +# from django.core import management +# management.call_command('askbot_add_test_content', verbosity=0, interactive=False) def try_url( self, diff --git a/askbot/tests/utils.py b/askbot/tests/utils.py index 218e9c4d..182b7768 100644 --- a/askbot/tests/utils.py +++ b/askbot/tests/utils.py @@ -61,22 +61,29 @@ class AskbotTestCase(TestCase): """adds some askbot-specific methods to django TestCase class """ - - def _fixture_setup(self): - # HACK: Create askbot_post database VIEW for the purpose of performing tests - import os.path - from django.conf import settings - from django.db import connection - sql = open(os.path.join(settings.PROJECT_ROOT, 'askbot', 'models', 'post_view.sql'), 'rt').read() - cursor = connection.cursor() - cursor.execute(sql) - super(AskbotTestCase, self)._fixture_setup() - - def _fixture_teardown(self): - super(AskbotTestCase, self)._fixture_teardown() - from django.db import connection - cursor = connection.cursor() - cursor.execute('DROP VIEW IF EXISTS askbot_post') +# INFO: This fixture has been replaced by migration 0088 (and possibly some subsequent ones) +# Therefore we should have South migrations enabled for testing, even though they it's not too efficient +# def _fixture_setup(self): +# # HACK: Create askbot_post database VIEW for the purpose of performing tests +# import os.path +# from django.conf import settings +# from django.db import connection +# sql = open(os.path.join(settings.PROJECT_ROOT, 'askbot', 'models', 'post_view.sql'), 'rt').read() +# cursor = connection.cursor() +# import warnings +# warnings.filterwarnings("ignore", "Unknown table .*?\.askbot_post'") # DROP VIEW might raise a warning so let's filter that out +# cursor.execute('DROP VIEW IF EXISTS askbot_post') +# cursor.execute(sql) +## connection.connection.store_result() +# connection.close() +# super(AskbotTestCase, self)._fixture_setup() +# +# def _fixture_teardown(self): +# super(AskbotTestCase, self)._fixture_teardown() +# from django.db import connection +# cursor = connection.cursor() +# cursor.execute('DROP VIEW IF EXISTS askbot_post') +# connection.close() def create_user( -- cgit v1.2.3-1-g7c22