summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askbot/management/commands/merge_users.py8
-rw-r--r--askbot/migrations/0106_update_postgres_full_text_setup.py4
-rw-r--r--askbot/search/postgresql/thread_and_post_models_01162012.plsql1
-rw-r--r--askbot/tests/page_load_tests.py36
-rw-r--r--askbot/tests/post_model_tests.py14
5 files changed, 46 insertions, 17 deletions
diff --git a/askbot/management/commands/merge_users.py b/askbot/management/commands/merge_users.py
index 3c7069e5..9eb76756 100644
--- a/askbot/management/commands/merge_users.py
+++ b/askbot/management/commands/merge_users.py
@@ -1,6 +1,14 @@
from django.core.management.base import CommandError, BaseCommand
from askbot.models import User
+# TODO: this command is broken - doesn't take into account UNIQUE constraints
+# and therefore causes db errors:
+# In SQLite: "Warning: columns feed_type, subscriber_id are not unique"
+# In MySQL: "Warning: (1062, "Duplicate entry 'm_and_c-2' for key 'askbot_emailfeedsetting_feed_type_6da6fdcd_uniq'")"
+# In PostgreSQL: "Warning: duplicate key value violates unique constraint "askbot_emailfeedsetting_feed_type_6da6fdcd_uniq"
+# "DETAIL: Key (feed_type, subscriber_id)=(m_and_c, 619) already exists."
+# (followed by series of "current transaction is aborted, commands ignored until end of transaction block" warnings)
+
class MergeUsersBaseCommand(BaseCommand):
args = '<from_user_id> <to_user_id>'
help = 'Merge an account and all information from a <user_id> to a <user_id>, deleting the <from_user>'
diff --git a/askbot/migrations/0106_update_postgres_full_text_setup.py b/askbot/migrations/0106_update_postgres_full_text_setup.py
index 0f940b96..b0b0c668 100644
--- a/askbot/migrations/0106_update_postgres_full_text_setup.py
+++ b/askbot/migrations/0106_update_postgres_full_text_setup.py
@@ -1,4 +1,5 @@
# encoding: utf-8
+import sys
import askbot
from askbot.search.postgresql import setup_full_text_search
import datetime
@@ -14,6 +15,9 @@ class Migration(DataMigration):
def forwards(self, orm):
"Write your forwards methods here."
+ if 'test' in sys.argv:
+ return # Somehow this migration fails when called from test runner
+
if 'postgresql_psycopg2' in askbot.get_database_engine_name():
script_path = os.path.join(
askbot.get_install_directory(),
diff --git a/askbot/search/postgresql/thread_and_post_models_01162012.plsql b/askbot/search/postgresql/thread_and_post_models_01162012.plsql
index 7156833b..44d0ea4a 100644
--- a/askbot/search/postgresql/thread_and_post_models_01162012.plsql
+++ b/askbot/search/postgresql/thread_and_post_models_01162012.plsql
@@ -219,4 +219,5 @@ DROP TRIGGER IF EXISTS post_search_vector_update_trigger on askbot_post;
CREATE TRIGGER post_search_vector_update_trigger
BEFORE INSERT OR UPDATE ON askbot_post FOR EACH ROW EXECUTE PROCEDURE post_trigger();
+DROP INDEX IF EXISTS askbot_search_idx;
CREATE INDEX askbot_search_idx ON askbot_thread USING gin(text_search_vector);
diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py
index f9385bec..ace41e8b 100644
--- a/askbot/tests/page_load_tests.py
+++ b/askbot/tests/page_load_tests.py
@@ -1,19 +1,19 @@
from askbot.search.state_manager import SearchState
-from django.test import TestCase
from django.test import signals
-from django.template import defaultfilters
from django.conf import settings
from django.core.urlresolvers import reverse
+from django.core import management
+
import coffin
import coffin.template
+
from askbot import models
from askbot.utils.slug import slugify
from askbot.deployment import package_utils
from askbot.tests.utils import AskbotTestCase
from askbot.conf import settings as askbot_settings
from askbot.tests.utils import skipIf
-import sys
-import os
+
def patch_jinja2():
@@ -37,16 +37,32 @@ if CMAJOR == 0 and CMINOR == 3 and CMICRO < 4:
class PageLoadTestCase(AskbotTestCase):
- def _fixture_setup(self):
- from django.core import management
+ #############################################
+ #
+ # INFO: We load test data once for all tests in this class (setUpClass + cleanup in tearDownClass)
+ #
+ # We also disable (by overriding _fixture_setup/teardown) per-test fixture setup,
+ # which by default flushes the database for non-transactional db engines like MySQL+MyISAM.
+ # For transactional engines it only messes with transactions, but to keep things uniform
+ # for both types of databases we disable it all.
+ #
+ @classmethod
+ def setUpClass(cls):
+ management.call_command('flush', verbosity=0, interactive=False)
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
+ @classmethod
+ def tearDownClass(self):
management.call_command('flush', verbosity=0, interactive=False)
+ def _fixture_setup(self):
+ pass
+
+ def _fixture_teardown(self):
+ pass
+
+ #############################################
+
def try_url(
self,
url_name, status_code=200, template=None,
diff --git a/askbot/tests/post_model_tests.py b/askbot/tests/post_model_tests.py
index 7e66d144..824a4a8f 100644
--- a/askbot/tests/post_model_tests.py
+++ b/askbot/tests/post_model_tests.py
@@ -114,9 +114,9 @@ class PostModelTests(AskbotTestCase):
self.user = self.u1
q = self.post_question()
- c1 = self.post_comment(parent_post=q)
- c2 = q.add_comment(user=self.user, comment='blah blah')
- c3 = self.post_comment(parent_post=q)
+ c1 = self.post_comment(parent_post=q, timestamp=datetime.datetime(2010, 10, 2, 14, 33, 20))
+ c2 = q.add_comment(user=self.user, comment='blah blah', added_at=datetime.datetime(2010, 10, 2, 14, 33, 21))
+ c3 = self.post_comment(parent_post=q, body_text='blah blah 2', timestamp=datetime.datetime(2010, 10, 2, 14, 33, 22))
Post.objects.precache_comments(for_posts=[q], visitor=self.user)
self.assertListEqual([c1, c2, c3], q._cached_comments)
@@ -138,9 +138,9 @@ class PostModelTests(AskbotTestCase):
self.user = self.u1
q = self.post_question()
- c1 = self.post_comment(parent_post=q)
- c2 = q.add_comment(user=self.user, comment='blah blah')
- c3 = self.post_comment(parent_post=q)
+ c1 = self.post_comment(parent_post=q, timestamp=datetime.datetime(2010, 10, 2, 14, 33, 20))
+ c2 = q.add_comment(user=self.user, comment='blah blah', added_at=datetime.datetime(2010, 10, 2, 14, 33, 21))
+ c3 = self.post_comment(parent_post=q, timestamp=datetime.datetime(2010, 10, 2, 14, 33, 22))
Post.objects.precache_comments(for_posts=[q], visitor=self.user)
self.assertListEqual([c1, c2, c3], q._cached_comments)
@@ -209,7 +209,7 @@ class ThreadTagModelsTests(AskbotTestCase):
tags = Tag.objects.get_related_to_search(threads=[self.q3.thread], ignored_tag_names=['tag6'])
self.assertListEqual([], [t.name for t in tags])
- tags = Tag.objects.get_related_to_search(threads=[self.q1.thread, self.q2.thread, self.q4], ignored_tag_names=['tag2'])
+ tags = Tag.objects.get_related_to_search(threads=[self.q1.thread, self.q2.thread, self.q4.thread], ignored_tag_names=['tag2'])
self.assertListEqual(['tag3', 'tag1', 'tag4', 'tag5', 'tag6'], [t.name for t in tags])
self.assertListEqual([3, 2, 2, 2, 1], [t.local_used_count for t in tags])
self.assertListEqual([3, 2, 2, 2, 2], [t.used_count for t in tags])