Beispiel #1
0
 def test_stellar_badge1(self):
     exercise = self.post_exercise(user = self.u1)
     settings.update('STELLAR_EXERCISE_BADGE_MIN_STARS', 2)
     self.u2.toggle_favorite_exercise(exercise)
     self.assert_have_badge('stellar-exercise', self.u1, 0)
     self.u3.toggle_favorite_exercise(exercise)
     self.assert_have_badge('stellar-exercise', self.u1, 1)
Beispiel #2
0
def update_media_revision(skin = None):
    """update skin media revision number based on the contents
    of the skin media directory"""
    from askbot.conf import settings as askbot_settings
    resource_revision = askbot_settings.MEDIA_RESOURCE_REVISION

    if skin:
        if skin in get_skin_choices():
            skin_path = get_path_to_skin(skin)
        else:
            raise MediaNotFound('Skin %s not found' % skin)
    else:
        skin = 'default'
        skin_path = get_path_to_skin(askbot_settings.ASKBOT_DEFAULT_SKIN)

    media_dirs = [
        os.path.join(skin_path, 'media'),
        os.path.join(get_path_to_skin('common'), 'media')#we always use common
    ]

    if skin != 'default':
        #we have default skin as parent of the custom skin
        default_skin_path = get_path_to_skin('default')
        media_dirs.append(os.path.join(default_skin_path, 'media'))

    current_hash = hasher.get_hash_of_dirs(media_dirs)

    if current_hash != askbot_settings.MEDIA_RESOURCE_REVISION_HASH:
        askbot_settings.update('MEDIA_RESOURCE_REVISION', resource_revision + 1)
        askbot_settings.update('MEDIA_RESOURCE_REVISION_HASH', current_hash)
        logging.debug('MEDIA_RESOURCE_REVISION changed')
    askbot_settings.MEDIA_RESOURCE_REVISION
Beispiel #3
0
 def test_associate_editor_badge(self):
     self.u2.set_status('m')
     question = self.post_question(user = self.u1)
     settings.update('ASSOCIATE_EDITOR_BADGE_MIN_EDITS', 2)
     self.u2.edit_question(
         question = question,
         title = 'hahaha',
         body_text = 'sdgsdjghsldkfshd',
         revision_comment = 'sdgdfgsgfs'
     )
     self.assert_have_badge('strunk-and-white', self.u2, 0)
     self.u2.edit_question(
         question = question,
         title = 'hahaha',
         body_text = 'sdgsdjghsldkfshd',
         revision_comment = 'sdgdfgsgfs'
     )
     self.assert_have_badge('strunk-and-white', self.u2, 1)
     self.u2.edit_question(
         question = question,
         title = 'hahaha',
         body_text = 'sdgsdjghsldkfshd',
         revision_comment = 'sdgdfgsgfs'
     )
     self.assert_have_badge('strunk-and-white', self.u2, 1)
    def setUp(self):
        # An administrator user
        self.owner = User.objects.create_user(username='******', email='*****@*****.**', password='******')
        self.owner.is_staff = True
        self.owner.is_superuser = True
        self.owner.save()
        # A moderator
        self.mod1 = create_user(username='******', email='*****@*****.**', status='m')
        self.mod1.set_password('modpw')
        self.mod1.save()
        # A normal user
        User.objects.create_user(username='******', email='*****@*****.**', password='******')
        # Setup a small category tree
        self.root = Category.objects.create(name=u'Root')
        self.c1 = Category.objects.create(name=u'Child1', parent=self.root)
        self.c2 = Category.objects.create(name=u'Child2', parent=self.c1)
        c3 = Category.objects.create(name=u'Child3', parent=self.root)

        self.tag1 = Tag.objects.create(name=u'Tag1', created_by=self.owner)
        self.tag2 = Tag.objects.create(name=u'Tag2', created_by=self.owner)
        self.tag2.categories.add(self.c1)
        self.tag3 = Tag.objects.create(name=u'Tag3', created_by=self.owner)
        self.tag3.categories.add(c3)

        askbot_settings.update('ENABLE_CATEGORIES', True)
        askbot_settings.update('CATEGORIES_MAX_TREE_DEPTH', 3)
    def setup_data(self, is_anon, can_be_anon, is_owner, box_checked):
        """sets up data in the same order as shown in the
        truth table above

        the four positional arguments are in the same order
        """
        askbot_settings.update('ALLOW_ASK_ANONYMOUSLY', can_be_anon)
        question = self.post_question(is_anonymous = is_anon)
        if is_owner:
            editor = self.user
        else:
            editor = self.other_user
        data = {
            'tags': 'tag1 tag2',
            'text': 'ostaousohuosuh',
            'title': 'stahosetuhaoeudhuh'
        }
        if box_checked:
            data['reveal_identity'] = 'on'
        self.form = forms.EditQuestionForm(
                        data,
                        question=question,
                        user=editor,
                        revision=question.get_latest_revision(),
                    )
 def forwards(self, orm):
     """reads category tree saved as string,
     translates it to json and saves back"""
     old_data = askbot_settings.CATEGORY_TREE
     json_data = parse_tree(old_data)
     json_string = simplejson.dumps(json_data)
     askbot_settings.update('CATEGORY_TREE',  json_string)
    def test_get_moderators_with_groups(self):
        groups_enabled_backup = askbot_settings.GROUPS_ENABLED
        askbot_settings.update("GROUPS_ENABLED", True)
        # create group
        group = Group(name="testers", openness=Group.OPEN)
        group.save()

        # create one admin and one moderator, and one reg user
        mod1 = self.create_user("mod1", status="m")
        adm1 = self.create_user("adm1", status="d")
        reg1 = self.create_user("reg1")
        # join them to the group
        mod1.join_group(group)
        adm1.join_group(group)
        reg1.join_group(group)
        # create one admin and one moderator, and one reg user
        mod2 = self.create_user("mod2", status="m")
        adm2 = self.create_user("adm2", status="d")
        reg2 = self.create_user("reg2")
        # make a post
        question = self.post_question(user=reg1, group_id=group.id)
        # run get_moderators and see that only one admin and one
        mods = question.get_moderators()
        self.assertEqual(set([mod1, adm1]), set(mods))
        # moderator are in the set of moderators
        askbot_settings.update("GROUPS_ENABLED", groups_enabled_backup)
Beispiel #8
0
 def test_stellar_badge1(self):
     question = self.post_question(user = self.u1)
     settings.update('STELLAR_QUESTION_BADGE_MIN_STARS', 2)
     self.u2.toggle_favorite_question(question)
     self.assert_have_badge('stellar-question', self.u1, 0)
     self.u3.toggle_favorite_question(question)
     self.assert_have_badge('stellar-question', self.u1, 1)
Beispiel #9
0
    def test_get_moderators_with_groups(self):
        groups_enabled_backup = askbot_settings.GROUPS_ENABLED
        askbot_settings.update('GROUPS_ENABLED', True)
        #create group
        group = Group(name='testers', openness=Group.OPEN)
        group.save()

        #create one admin and one moderator, and one reg user
        mod1 = self.create_user('mod1', status='m')
        adm1 = self.create_user('adm1', status='d')
        reg1 = self.create_user('reg1')
        #join them to the group
        mod1.join_group(group)
        adm1.join_group(group)
        reg1.join_group(group)
        #create one admin and one moderator, and one reg user
        mod2 = self.create_user('mod2', status='m')
        adm2 = self.create_user('adm2', status='d')
        reg2 = self.create_user('reg2')
        #make a post
        exercise = self.post_exercise(user=reg1, group_id=group.id)
        #run get_moderators and see that only one admin and one
        mods = exercise.get_moderators()
        self.assertEqual(
            set([mod1, adm1]),
            set(mods)
        )
        #moderator are in the set of moderators
        askbot_settings.update('GROUPS_ENABLED', groups_enabled_backup)
 def __init__(self, *args, **kwargs):
     super(Command, self).__init__(*args, **kwargs)
     #relax certain settings
     askbot_settings.update('LIMIT_ONE_ANSWER_PER_USER', False)
     askbot_settings.update('MAX_COMMENT_LENGTH', 1000000)
     #askbot_settings.update('MIN_REP_TO_LEAVE_COMMENTS', 1)
     self.bad_email_count = 0
Beispiel #11
0
def update_media_revision(skin=None):
    """update skin media revision number based on the contents
    of the skin media directory"""
    from askbot.conf import settings as askbot_settings
    resource_revision = askbot_settings.MEDIA_RESOURCE_REVISION

    skin = skin or askbot_settings.ASKBOT_DEFAULT_SKIN

    if skin in get_available_skins().keys():
        skin_path = get_path_to_skin(skin)
    else:
        assert(skin != 'default')
        msg = 'Skin "%s" not found. Please check ASKBOT_EXTRA_SKINS_DIR setting'
        raise MediaNotFound(msg % skin)

    media_dirs = [
        os.path.join(skin_path, 'media'),
    ]

    if skin != 'default':
        #we have default skin as parent of the custom skin
        default_skin_path = get_path_to_skin('default')
        media_dirs.append(os.path.join(default_skin_path, 'media'))

    current_hash = hasher.get_hash_of_dirs(media_dirs)

    if current_hash != askbot_settings.MEDIA_RESOURCE_REVISION_HASH:
        askbot_settings.update('MEDIA_RESOURCE_REVISION', resource_revision + 1)
        askbot_settings.update('MEDIA_RESOURCE_REVISION_HASH', current_hash)
        logging.debug('MEDIA_RESOURCE_REVISION changed')
Beispiel #12
0
 def test_catch_missing_mandatory_tag(self):
     askbot_settings.update('MANDATORY_TAGS', 'one two')
     self.assertRaises(
         django_forms.ValidationError,
         self.clean,
         ('three',)
     )
Beispiel #13
0
 def test_categories_off(self):
     """AJAX category-related views shouldn't be published when master switch is off."""
     askbot_settings.update('ENABLE_CATEGORIES', False)
     r = self.ajax_post_json(reverse('add_category'), {'name': u'Entertainment', 'parent': self.root.id})
     self.assertEqual(r.status_code, 404)
     askbot_settings.update('ENABLE_CATEGORIES', True)
     r = self.ajax_post_json(reverse('add_category'), {'name': u'Family', 'parent': self.root.id})
     self.assertEqual(r.status_code, 200)
 def setUp(self):
     self._backup = askbot_settings.GROUPS_ENABLED
     askbot_settings.update("GROUPS_ENABLED", True)
     self.user = self.create_user("user")
     group = models.Group.objects.create(name="the group", openness=models.Group.OPEN)
     self.user.join_group(group)
     self.question = self.post_question(user=self.user)
     self.client.login(user_id=self.user.id, method="force")
 def setUp(self):
     self._backup = askbot_settings.GROUPS_ENABLED
     askbot_settings.update("GROUPS_ENABLED", True)
     self.user = self.create_user("user")
     self.group = models.Group.objects.create(name="the group", openness=models.Group.OPEN)
     self.user.join_group(self.group)
     self.qdata = {"title": "test question title", "text": "test question text"}
     self.client.login(user_id=self.user.id, method="force")
Beispiel #16
0
 def test_custom_case(self):
     """FORCE_LOWERCASE setting is off
     """
     askbot_settings.update('FORCE_LOWERCASE_TAGS', False)
     models.Tag(name = 'TAG1', created_by = self.user).save()
     models.Tag(name = 'Tag2', created_by = self.user).save()
     cleaned_tags = self.clean('tag1 taG2 TAG1 tag3 tag3')
     self.assert_tags_equal(cleaned_tags, ['TAG1', 'Tag2', 'tag3'])
Beispiel #17
0
 def tearDown(self):
     #delete the dummy skin
     test_skin_dir = os.path.join(
                         self.temp_dir,
                         'test_skin'
                     )
     shutil.rmtree(self.temp_dir)
     askbot_settings.update('ASKBOT_DEFAULT_SKIN', 'default')
     django_settings.ASKBOT_EXTRA_SKINS_DIR = self.skins_dir_backup
Beispiel #18
0
    def test_unlocalized_setting(self):
        backup = askbot_settings.MIN_REP_TO_VOTE_UP

        askbot_settings.update('MIN_REP_TO_VOTE_UP', 500)
        self.assertSettingEquals('MIN_REP_TO_VOTE_UP', 500)
        translation.activate('de')
        self.assertSettingEquals('MIN_REP_TO_VOTE_UP', 500)

        askbot_settings.update('MIN_REP_TO_VOTE_UP', backup)
Beispiel #19
0
 def test_uploaded_logo(self):
     logo_src = os.path.join(askbot.get_install_directory(), "tests", "images", "logo.gif")
     logo_file = open(logo_src, "r")
     new_logo = UploadedFile(file=logo_file)
     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)
     self.assertTrue(response.status_code == 200)
Beispiel #20
0
 def test_user_dislikes_wildcard(self):
     """user set must have one user who does not dislike the tag via wildcard"""
     self.set_email_tag_filter_strategy(const.EXCLUDE_IGNORED)
     askbot_settings.update('USE_WILDCARD_TAGS', True)
     self.u1.mark_tags(wildcards = ('da*',), reason = 'I', action = 'add')
     self.assert_subscribers_are(
         expected_subscribers = set([self.u2,]),
         reason = 'I'
     )
Beispiel #21
0
 def test_user_likes_wildcard(self):
     """user set must contain one person who likes the tag via wildcard"""
     self.set_email_tag_filter_strategy(const.INCLUDE_INTERESTING)
     askbot_settings.update('USE_WILDCARD_TAGS', True)
     self.u1.mark_tags(wildcards = ('da*',), reason = 'S', action = 'add')
     self.assert_subscribers_are(
         expected_subscribers = set([self.u1,]),
         reason = 'S'
     )
Beispiel #22
0
 def test_user_does_not_care_about_question_no_wildcards(self):
     askbot_settings.update('USE_WILDCARD_TAGS', False)
     tag = models.Tag(name='five', created_by=self.user)
     tag.save()
     mt = models.MarkedTag(user=self.user, tag=tag, reason='good')
     mt.save()
     self.assertFalse(
         self.user.has_affinity_to_question(question=self.question,
                                            affinity_type='like'))
Beispiel #23
0
 def setup_wildcard(self, wildcard=None, reason=None):
     if reason == 'good':
         self.user.interesting_tags = wildcard
         self.user.ignored_tags = ''
     else:
         self.user.ignored_tags = wildcard
         self.user.interesting_tags = ''
     self.user.save()
     askbot_settings.update('USE_WILDCARD_TAGS', True)
Beispiel #24
0
    def test_no_category_simple_success(self):
        """Tags page should work without errors when no category is specified"""
        r = self.client.get('/%s' % _('tags/'))
        self.assertEqual(200, r.status_code)

        # Same thing when master categories switch is off
        askbot_settings.update('ENABLE_CATEGORIES', False)
        r = self.client.get('/%s' % _('tags/'))
        self.assertEqual(200, r.status_code)
Beispiel #25
0
 def tearDown(self):
     #delete the dummy skin
     test_skin_dir = os.path.join(self.temp_dir, 'test_skin')
     shutil.rmtree(self.temp_dir)
     askbot_settings.update('ASKBOT_DEFAULT_SKIN', 'default')
     if self.skins_dir_backup is None:
         del (django_settings.ASKBOT_EXTRA_SKINS_DIR)
     else:
         django_settings.ASKBOT_EXTRA_SKINS_DIR = self.skins_dir_backup
Beispiel #26
0
 def test_global_group_name_setting_changes_group_name(self):
     orig_group_name = askbot_settings.GLOBAL_GROUP_NAME;
     askbot_settings.update('GLOBAL_GROUP_NAME', 'all-people')
     group = models.Group.objects.get_global_group()
     self.assertEqual(group.name, 'all-people')
     # Revert the global group name, so we don't mess up other tests!
     askbot_settings.update('GLOBAL_GROUP_NAME', orig_group_name);
     group = models.Group.objects.get_global_group()
     self.assertEqual(group.name, orig_group_name)
 def proto_test_ask_page(self, allow_anonymous, status_code):
     prev_setting = askbot_settings.ALLOW_POSTING_BEFORE_LOGGING_IN
     askbot_settings.update('ALLOW_POSTING_BEFORE_LOGGING_IN', allow_anonymous)
     self.try_url(
         'ask',
         status_code = status_code,
         template = 'ask.html'
     )
     askbot_settings.update('ALLOW_POSTING_BEFORE_LOGGING_IN', prev_setting)
Beispiel #28
0
 def tearDown(self):
     #delete the dummy skin
     test_skin_dir = os.path.join(
                         askbot.get_install_directory(),
                         'skins',
                         'test_skin'
                     )
     shutil.rmtree(test_skin_dir)
     askbot_settings.update('ASKBOT_DEFAULT_SKIN', 'default')
Beispiel #29
0
 def setup_wildcard(self, wildcard = None, reason = None):
     if reason == 'good':
         self.user.interesting_tags = wildcard
         self.user.ignored_tags = ''
     else:
         self.user.ignored_tags = wildcard
         self.user.interesting_tags = ''
     self.user.save()
     askbot_settings.update('USE_WILDCARD_TAGS', True)
Beispiel #30
0
 def test_global_group_name_setting_changes_group_name(self):
     orig_group_name = askbot_settings.GLOBAL_GROUP_NAME
     askbot_settings.update('GLOBAL_GROUP_NAME', 'all-people')
     group = models.Group.objects.get_global_group()
     self.assertEqual(group.name, 'all-people')
     # Revert the global group name, so we don't mess up other tests!
     askbot_settings.update('GLOBAL_GROUP_NAME', orig_group_name)
     group = models.Group.objects.get_global_group()
     self.assertEqual(group.name, orig_group_name)
Beispiel #31
0
 def proto_test_ask_page(self, allow_anonymous, status_code):
     prev_setting = askbot_settings.ALLOW_POSTING_BEFORE_LOGGING_IN
     askbot_settings.update('ALLOW_POSTING_BEFORE_LOGGING_IN', allow_anonymous)
     self.try_url(
         'ask',
         status_code = status_code,
         template = 'ask.html'
     )
     askbot_settings.update('ALLOW_POSTING_BEFORE_LOGGING_IN', prev_setting)
Beispiel #32
0
 def test_uploaded_logo(self):
     logo_src = os.path.join(askbot.get_install_directory(), 'tests',
                             'images', 'logo.gif')
     logo_file = open(logo_src, 'r')
     new_logo = UploadedFile(file=logo_file)
     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)
     self.assertTrue(response.status_code == 200)
 def test_user_likes_wildcard(self):
     """user set must contain one person who likes the tag via wildcard"""
     self.set_email_tag_filter_strategy(const.INCLUDE_INTERESTING)
     askbot_settings.update('USE_WILDCARD_TAGS', True)
     self.u1.mark_tags(wildcards = ('da*',), reason = 'good', action = 'add')
     self.u1.save()
     self.assert_subscribers_are(
         expected_subscribers = set([self.u1,]),
         reason = 'good'
     )
 def test_user_dislikes_wildcard(self):
     """user set must have one user who does not dislike the tag via wildcard"""
     self.set_email_tag_filter_strategy(const.EXCLUDE_IGNORED)
     askbot_settings.update('USE_WILDCARD_TAGS', True)
     self.u1.mark_tags(wildcards = ('da*',), reason = 'bad', action = 'add')
     self.u1.save()
     self.assert_subscribers_are(
         expected_subscribers = set([self.u2,]),
         reason = 'bad'
     )
Beispiel #35
0
 def setUp(self):
     self._backup = askbot_settings.GROUPS_ENABLED
     askbot_settings.update('GROUPS_ENABLED', True)
     self.user = self.create_user('user')
     group = models.Group.objects.create(
         name='the group', openness=models.Group.OPEN
     )
     self.user.join_group(group)
     self.question = self.post_question(user=self.user)
     self.client.login(user_id=self.user.id, method='force')
 def test_reminder_simple(self):
     """a positive test - user must receive a reminder
     """
     askbot_settings.update("ENABLE_UNANSWERED_REMINDERS", True)
     days_ago = 5 * askbot_settings.DAYS_BEFORE_SENDING_UNANSWERED_REMINDER
     long_ago = datetime.datetime.now() - datetime.timedelta(days_ago)
     self.post_question(user=self.u1, timestamp=long_ago)
     management.call_command("send_unanswered_question_reminders")
     outbox = django.core.mail.outbox
     self.assertEqual(len(outbox), 1)
Beispiel #37
0
 def setup_data(self, allow_anonymous = True, ask_anonymously = None):
     askbot_settings.update('ALLOW_ASK_ANONYMOUSLY', allow_anonymous)
     data = {
         'title': 'test title',
         'text': 'test content',
         'tags': 'test',
     }
     if ask_anonymously == True:
         data['ask_anonymously'] = 'on'
     self.form = forms.AskForm(data, user=AnonymousUser())
     self.form.full_clean()
def toggle_user_answer_limit_setting(val):
    """Turns the Askbot live_setting for LIMIT_ONE_ANSWER_PER_USER on 
    or off.

    :param val: (bool) value to set LIMIT_ONE_ANSWER_PER_USER to
    """
    if val:
        askbot_settings.update('LIMIT_ONE_ANSWER_PER_USER', True)
    else:
        askbot_settings.update('LIMIT_ONE_ANSWER_PER_USER', False)
    print "set LIMIT_ONE_ANSWER_PER_USER to %s" % val
Beispiel #39
0
 def setup_data(self, allow_anonymous=True, ask_anonymously=None):
     askbot_settings.update('ALLOW_ASK_ANONYMOUSLY', allow_anonymous)
     data = {
         'title': 'test title',
         'text': 'test content',
         'tags': 'test',
     }
     if ask_anonymously:
         data['ask_anonymously'] = 'on'
     self.form = forms.AskForm(data, user=AnonymousUser())
     self.form.full_clean()
Beispiel #40
0
def remove_email_from_invited_moderators(email):
    """Update the `INVITED_MODERATORS` setting by removing
    the matching email entry"""
    lines = askbot_settings.INVITED_MODERATORS.strip().split('\n')
    clean_lines = list()
    prefix = email + ' '
    for line in lines:
        if not line.startswith(prefix):
            clean_lines.append(line)
    if len(clean_lines) != len(lines):
        value = '\n'.join(clean_lines)
        askbot_settings.update('INVITED_MODERATORS', value)
Beispiel #41
0
 def setUp(self):
     self._backup = askbot_settings.GROUPS_ENABLED
     askbot_settings.update('GROUPS_ENABLED', True)
     self.user = self.create_user('user')
     self.group = models.Group.objects.create(name='the group',
                                              openness=models.Group.OPEN)
     self.user.join_group(self.group)
     self.qdata = {
         'title': 'test question title',
         'text': 'test question text'
     }
     self.client.login(user_id=self.user.id, method='force')
Beispiel #42
0
 def test_user_does_not_care_about_question_no_wildcards(self):
     askbot_settings.update('USE_WILDCARD_TAGS', False)
     tag = models.Tag(name = 'five', created_by = self.user)
     tag.save()
     mt = models.MarkedTag(user = self.user, tag = tag, reason = 'good')
     mt.save()
     self.assertFalse(
         self.user.has_affinity_to_question(
             question = self.question,
             affinity_type = 'like'
         )
     )
Beispiel #43
0
 def test_civic_duty_badge(self):
     settings.update('CIVIC_DUTY_BADGE_MIN_VOTES', 2)
     question = self.post_question(user = self.u1)
     answer = self.post_answer(user = self.u2, question = question)
     answer2 = self.post_answer(user = self.u1, question = question)
     self.u3.upvote(question)
     self.u3.downvote(answer)
     self.assert_have_badge('civic-duty', recipient = self.u3)
     self.u3.upvote(answer2)
     self.assert_have_badge('civic-duty', recipient = self.u3, expected_count = 1)
     self.u3.downvote(answer)
     self.assert_have_badge('civic-duty', recipient = self.u3, expected_count = 1)
    def forwards(self, orm):
        """reads category tree saved as string,
        translates it to json and saves back"""
        old_data = askbot_settings.CATEGORY_TREE

        #this special value is our new default,
        #we don't want to create a tag with this name
        if old_data.replace(' ', '') == '[["dummy",[]]]':
            old_data = ''

        json_data = parse_tree(old_data)
        json_string = simplejson.dumps(json_data)
        askbot_settings.update('CATEGORY_TREE', json_string)
Beispiel #45
0
 def test_user_dislikes_wildcard_and_matching_tag(self):
     """user ignores tag "day" and ignores a wildcard "da*"
     """
     self.set_email_tag_filter_strategy(const.EXCLUDE_IGNORED)
     askbot_settings.update('USE_WILDCARD_TAGS', True)
     self.u1.mark_tags(tagnames=('day', ),
                       wildcards=('da*', ),
                       reason='bad',
                       action='add')
     self.assert_subscribers_are(expected_subscribers=set([
         self.u2,
     ]),
                                 reason='bad')
Beispiel #46
0
 def test_reminder_simple(self):
     """a positive test - user must receive a reminder
     """
     askbot_settings.update('ENABLE_UNANSWERED_REMINDERS', True)
     days_ago = 5*askbot_settings.DAYS_BEFORE_SENDING_UNANSWERED_REMINDER
     long_ago = datetime.datetime.now() - datetime.timedelta(days_ago)
     self.post_question(
         user = self.u1,
         timestamp = long_ago
     )
     management.call_command('send_unanswered_question_reminders')
     outbox = django.core.mail.outbox
     self.assertEqual(len(outbox), 1)
 def test_stellar_badge3(self):
     question = self.post_question(user=self.u1)
     settings.update('STELLAR_QUESTION_BADGE_MIN_STARS', 2)
     self.u2.toggle_favorite_question(question)
     self.assert_have_badge('stellar-question', self.u1, 0)
     self.u3.toggle_favorite_question(question)
     #award now
     self.assert_have_badge('stellar-question', self.u1, 1)
     self.u3.toggle_favorite_question(question)
     #dont take back
     self.assert_have_badge('stellar-question', self.u1, 1)
     self.u3.toggle_favorite_question(question)
     #dont reaward
     self.assert_have_badge('stellar-question', self.u1, 1)
Beispiel #48
0
        def wrapped(*args, **kwargs):
            from askbot.conf import settings as askbot_settings
            backup_settings_dict = dict()
            for key, value in settings_dict.items():
                backup_settings_dict[key] = getattr(askbot_settings, key)
                askbot_settings.update(key, value)

            try:
                return func(*args, **kwargs)
            except:
                raise
            finally:
                for key, value in backup_settings_dict.items():
                    askbot_settings.update(key, value)
Beispiel #49
0
 def test_stellar_badge3(self):
     exercise = self.post_exercise(user=self.u1)
     settings.update('STELLAR_EXERCISE_BADGE_MIN_STARS', 2)
     self.u2.toggle_favorite_exercise(exercise)
     self.assert_have_badge('stellar-exercise', self.u1, 0)
     self.u3.toggle_favorite_exercise(exercise)
     #award now
     self.assert_have_badge('stellar-exercise', self.u1, 1)
     self.u3.toggle_favorite_exercise(exercise)
     #dont take back
     self.assert_have_badge('stellar-exercise', self.u1, 1)
     self.u3.toggle_favorite_exercise(exercise)
     #dont reaward
     self.assert_have_badge('stellar-exercise', self.u1, 1)
Beispiel #50
0
 def test_categories_off(self):
     """AJAX category-related views shouldn't be published when master switch is off."""
     askbot_settings.update('ENABLE_CATEGORIES', False)
     r = self.ajax_post_json(reverse('add_category'), {
         'name': u'Entertainment',
         'parent': self.root.id
     })
     self.assertEqual(r.status_code, 404)
     askbot_settings.update('ENABLE_CATEGORIES', True)
     r = self.ajax_post_json(reverse('add_category'), {
         'name': u'Family',
         'parent': self.root.id
     })
     self.assertEqual(r.status_code, 200)
Beispiel #51
0
    def test_localized_setting(self):
        translation.activate('de')
        askbot_settings.as_dict()  #hit settings in German
        backup = askbot_settings.WORDS_ASK_YOUR_QUESTION

        translation.activate('en')
        askbot_settings.update('WORDS_ASK_YOUR_QUESTION', 'Stelle deine frage',
                               'de')
        self.assertSettingEquals('WORDS_ASK_YOUR_QUESTION',
                                 'Ask Your Question')
        translation.activate('de')
        self.assertSettingEquals('WORDS_ASK_YOUR_QUESTION',
                                 'Stelle deine frage')

        askbot_settings.update('WORDS_ASK_YOUR_QUESTION', backup, 'de')
Beispiel #52
0
 def setUp(self):
     self.groups_enabled_backup = askbot_settings.GROUPS_ENABLED
     askbot_settings.update('GROUPS_ENABLED', True)
     self.admin = self.create_user('admin', status='d')
     self.user = self.create_user('user',
                                  notification_schedule={
                                      'q_ask': 'i',
                                      'q_all': 'i',
                                      'q_ans': 'i',
                                      'q_sel': 'i',
                                      'm_and_c': 'i'
                                  })
     self.group = models.Group.objects.get_or_create(name='jockeys')
     self.admin.edit_group_membership(group=self.group,
                                      user=self.admin,
                                      action='add')
Beispiel #53
0
 def test_subject_line(self):
     """loops through various forms of the subject line
     and makes sure that tags and title are parsed out"""
     setting_backup = askbot_settings.TAGS_ARE_REQUIRED
     askbot_settings.update('TAGS_ARE_REQUIRED', True)
     for test_case in SUBJECT_LINE_CASES:
         self.data['subject'] = test_case[0]
         form = forms.AskByEmailForm(self.data)
         output = test_case[1]
         if output is None:
             self.assertFalse(form.is_valid())
         else:
             self.assertTrue(form.is_valid())
             self.assertEquals(form.cleaned_data['tagnames'], output[0])
             self.assertEquals(form.cleaned_data['title'], output[1])
     askbot_settings.update('TAGS_ARE_REQUIRED', setting_backup)
Beispiel #54
0
 def test_civic_duty_badge(self):
     settings.update('CIVIC_DUTY_BADGE_MIN_VOTES', 2)
     exercise = self.post_exercise(user=self.u1)
     problem = self.post_problem(user=self.u2, exercise=exercise)
     problem2 = self.post_problem(user=self.u1, exercise=exercise)
     self.u3.upvote(exercise)
     self.u3.downvote(problem)
     self.assert_have_badge('civic-duty', recipient=self.u3)
     self.u3.upvote(problem2)
     self.assert_have_badge('civic-duty',
                            recipient=self.u3,
                            expected_count=1)
     self.u3.downvote(problem)
     self.assert_have_badge('civic-duty',
                            recipient=self.u3,
                            expected_count=1)
 def test_wildcard_catches_new_tag(self):
     """users asks a question with a brand new tag
     and other user subscribes to it by wildcard
     """
     askbot_settings.update('USE_WILDCARD_TAGS', True)
     self.user1.email_tag_filter_strategy = const.INCLUDE_INTERESTING
     self.user1.save()
     self.user1.mark_tags(wildcards=('some*', ),
                          reason='good',
                          action='add')
     self.user2.post_question(title='some title',
                              body_text='some text for the question',
                              tags='something')
     outbox = django.core.mail.outbox
     self.assertEqual(len(outbox), 1)
     self.assertEqual(len(outbox[0].recipients()), 1)
     self.assertTrue(self.user1.email in outbox[0].recipients())
    def setUp(self):
        self.u1 = self.create_user(username='******')
        self.u2 = self.create_user(username='******')
        askbot_settings.update('ENABLE_UNANSWERED_REMINDERS', True)
        askbot_settings.update('MAX_UNANSWERED_REMINDERS', 5)
        askbot_settings.update('UNANSWERED_REMINDER_FREQUENCY', 1)
        askbot_settings.update('DAYS_BEFORE_SENDING_UNANSWERED_REMINDER', 2)

        self.wait_days = askbot_settings.DAYS_BEFORE_SENDING_UNANSWERED_REMINDER
        self.recurrence_days = askbot_settings.UNANSWERED_REMINDER_FREQUENCY
        self.max_emails = askbot_settings.MAX_UNANSWERED_REMINDERS
    def setUp(self):
        self.u1 = self.create_user(username = '******')
        self.u2 = self.create_user(username = '******')
        askbot_settings.update(self.enable_setting_name, True)
        askbot_settings.update(self.max_reminder_setting_name, 5)
        askbot_settings.update(self.frequency_setting_name, 1)
        askbot_settings.update(self.days_before_setting_name, 2)

        self.wait_days = getattr(askbot_settings, self.days_before_setting_name)
        self.recurrence_days = getattr(askbot_settings, self.frequency_setting_name)
        self.max_emails = getattr(askbot_settings, self.max_reminder_setting_name)
 def test_associate_editor_badge(self):
     self.u2.set_status('m')
     question = self.post_question(user=self.u1)
     settings.update('ASSOCIATE_EDITOR_BADGE_MIN_EDITS', 2)
     self.u2.edit_question(question=question,
                           title='hahaha',
                           body_text='sdgsdjghsldkfshd',
                           revision_comment='sdgdfgsgfs')
     self.assert_have_badge('strunk-and-white', self.u2, 0)
     self.u2.edit_question(question=question,
                           title='hahaha',
                           body_text='sdgsdjghsldkfshd',
                           revision_comment='sdgdfgsgfs')
     self.assert_have_badge('strunk-and-white', self.u2, 1)
     self.u2.edit_question(question=question,
                           title='hahaha',
                           body_text='sdgsdjghsldkfshd',
                           revision_comment='sdgdfgsgfs')
     self.assert_have_badge('strunk-and-white', self.u2, 1)
 def tearDown(self):
     askbot_settings.update(
         'REPLY_BY_EMAIL', self.reply_by_email
     )
     askbot_settings.update(
         'CONTENT_MODERATION_MODE',
         self.content_moderation_mode
     )
     askbot_settings.update(
         'SELF_NOTIFY_EMAILED_POST_AUTHOR_WHEN',
         self.self_notify_when
     )