diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-12-25 21:47:32 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-12-25 21:47:32 -0300 |
commit | 4544e49c0f488e9f8e6ba7700149df37a69075f9 (patch) | |
tree | f88aac27757e9d565cd67231b4387dfed843c695 | |
parent | 908fb13a4a30d2db8a2729d900f12dc9a86ced91 (diff) | |
download | askbot-4544e49c0f488e9f8e6ba7700149df37a69075f9.tar.gz askbot-4544e49c0f488e9f8e6ba7700149df37a69075f9.tar.bz2 askbot-4544e49c0f488e9f8e6ba7700149df37a69075f9.zip |
made all test cases pass and small refactoring of the user activity page
-rw-r--r-- | askbot/models/__init__.py | 2 | ||||
-rw-r--r-- | askbot/tests/badge_tests.py | 3 | ||||
-rw-r--r-- | askbot/tests/post_model_tests.py | 12 | ||||
-rw-r--r-- | askbot/tests/skin_tests.py | 17 | ||||
-rw-r--r-- | askbot/views/users.py | 36 |
5 files changed, 49 insertions, 21 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index e83a92c8..21bd1781 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1637,7 +1637,7 @@ def user_post_question( if timestamp is None: timestamp = datetime.datetime.now() - #todo: split this into "create thread" + "add queston", if text exists + #todo: split this into "create thread" + "add question", if text exists #or maybe just add a blank question post anyway thread = Thread.objects.create_new( author = self, diff --git a/askbot/tests/badge_tests.py b/askbot/tests/badge_tests.py index c184db6f..91c6b349 100644 --- a/askbot/tests/badge_tests.py +++ b/askbot/tests/badge_tests.py @@ -1,5 +1,6 @@ import datetime from django.conf import settings as django_settings +from django.core.urlresolvers import reverse from django.test.client import Client from askbot.tests.utils import AskbotTestCase from askbot.conf import settings @@ -502,6 +503,6 @@ class BadgeTests(AskbotTestCase): self.u1.save() self.assert_have_badge('enthusiast', self.u1, 0) self.client.login(method = 'force', user_id = self.u1.id) - self.client.get('/' + django_settings.ASKBOT_URL) + self.client.get(reverse('questions')) self.assert_have_badge('enthusiast', self.u1, 1) diff --git a/askbot/tests/post_model_tests.py b/askbot/tests/post_model_tests.py index 031909fb..cad58388 100644 --- a/askbot/tests/post_model_tests.py +++ b/askbot/tests/post_model_tests.py @@ -126,17 +126,21 @@ class PostModelTests(AskbotTestCase): th.title = 'lala-x-lala' p = Post(id=3, post_type='question') p._thread_cache = th # cannot assign non-Thread instance directly - self.assertEqual('/question/3/lala-x-lala/', p.get_absolute_url(thread=th)) + expected_url = urlresolvers.reverse('question', kwargs={'id': 3}) \ + + th.title + '/' + self.assertEqual(expected_url, p.get_absolute_url(thread=th)) self.assertTrue(p._thread_cache is th) - self.assertEqual('/question/3/lala-x-lala/', p.get_absolute_url(thread=th)) + self.assertEqual(expected_url, p.get_absolute_url(thread=th)) def test_cached_get_absolute_url_2(self): p = Post(id=3, post_type='question') th = lambda:1 th.title = 'lala-x-lala' - self.assertEqual('/question/3/lala-x-lala/', p.get_absolute_url(thread=th)) + expected_url = urlresolvers.reverse('question', kwargs={'id': 3}) \ + + th.title + '/' + self.assertEqual(expected_url, p.get_absolute_url(thread=th)) self.assertTrue(p._thread_cache is th) - self.assertEqual('/question/3/lala-x-lala/', p.get_absolute_url(thread=th)) + self.assertEqual(expected_url, p.get_absolute_url(thread=th)) def test_get_moderators_with_groups(self): groups_enabled_backup = askbot_settings.GROUPS_ENABLED diff --git a/askbot/tests/skin_tests.py b/askbot/tests/skin_tests.py index 5226e6d6..8499ab70 100644 --- a/askbot/tests/skin_tests.py +++ b/askbot/tests/skin_tests.py @@ -1,20 +1,23 @@ import os import shutil +import tempfile from django.test import TestCase from django.core.files.uploadedfile import UploadedFile from django.conf import settings as django_settings from askbot.conf import settings as askbot_settings -from askbot.utils.path import mkdir_p from askbot.skins import utils as skin_utils +from askbot.utils.path import mkdir_p import askbot class SkinTests(TestCase): def setUp(self): #create dummy skin + self.temp_dir = tempfile.mkdtemp() + self.skins_dir_backup = getattr(django_settings, 'ASKBOT_EXTRA_SKINS_DIR', None) + setattr(django_settings, 'ASKBOT_EXTRA_SKINS_DIR', self.temp_dir) skin_image_dir = os.path.join( - askbot.get_install_directory(), - 'skins', + self.temp_dir, 'test_skin', 'media', 'images' @@ -31,12 +34,12 @@ class SkinTests(TestCase): def tearDown(self): #delete the dummy skin test_skin_dir = os.path.join( - askbot.get_install_directory(), - 'skins', + self.temp_dir, 'test_skin' ) - shutil.rmtree(test_skin_dir) + shutil.rmtree(self.temp_dir) askbot_settings.update('ASKBOT_DEFAULT_SKIN', 'default') + django_settings.ASKBOT_EXTRA_SKINS_DIR = self.skins_dir_backup def assert_default_logo_in_skin(self, skin_name): url = skin_utils.get_media_url(askbot_settings.SITE_LOGO_URL) @@ -62,5 +65,5 @@ class SkinTests(TestCase): askbot_settings.update('SITE_LOGO_URL', new_logo) logo_url = askbot_settings.SITE_LOGO_URL self.assertTrue(logo_url.startswith(django_settings.MEDIA_URL)) - response = self.client.get(logo_url) + response = self.client.get(logo_url, follow=True) self.assertTrue(response.status_code == 200) diff --git a/askbot/views/users.py b/askbot/views/users.py index 9102a6bc..8763c3ec 100644 --- a/askbot/views/users.py +++ b/askbot/views/users.py @@ -560,24 +560,44 @@ def user_recent(request, user, context): self.content_object = content_object self.badge = badge - activities = [] - # TODO: Don't process all activities here for the user, only a subset ([:const.USER_VIEW_DATA_SIZE]) - for activity in models.Activity.objects.filter(user=user): + activity_types = ( + const.TYPE_ACTIVITY_ASK_QUESTION, + const.TYPE_ACTIVITY_ANSWER, + const.TYPE_ACTIVITY_COMMENT_QUESTION, + const.TYPE_ACTIVITY_COMMENT_ANSWER, + const.TYPE_ACTIVITY_UPDATE_QUESTION, + const.TYPE_ACTIVITY_UPDATE_ANSWER, + const.TYPE_ACTIVITY_MARK_ANSWER, + const.TYPE_ACTIVITY_PRIZE + ) + + #source of information about activities + activity_objects = models.Activity.objects.filter( + user=user, + activity_type__in=activity_types + )[:const.USER_VIEW_DATA_SIZE] + + #a list of digest objects, suitable for display + #the number of activities to show is not guaranteed to be + #const.USER_VIEW_DATA_TYPE, because we don't show activity + #for deleted content + activities = [] + for activity in activity_objects: # TODO: multi-if means that we have here a construct for which a design pattern should be used # ask questions if activity.activity_type == const.TYPE_ACTIVITY_ASK_QUESTION: - q = activity.content_object - if q.deleted: + question = activity.content_object + if not question.deleted: activities.append(Event( time=activity.active_at, type=activity.activity_type, - title=q.thread.title, + title=question.thread.title, summary='', #q.summary, # TODO: was set to '' before, but that was probably wrong answer_id=0, - question_id=q.id + question_id=question.id )) elif activity.activity_type == const.TYPE_ACTIVITY_ANSWER: @@ -678,7 +698,7 @@ def user_recent(request, user, context): 'tab_name' : 'recent', 'tab_description' : _('recent user activity'), 'page_title' : _('profile - recent activity'), - 'activities' : activities[:const.USER_VIEW_DATA_SIZE] + 'activities' : activities } context.update(data) return render(request, 'user_profile/user_recent.html', context) |