Esempio n. 1
0
    def test_topic_notification_notify_new_comment(self):
        """
        Should set is_read=False to all notifiers/users
        """
        creator = utils.create_user()
        subscriber = utils.create_user()
        topic = utils.create_topic(self.category)
        comment = utils.create_comment(user=creator, topic=topic)
        TopicNotification.objects.create(user=creator,
                                         topic=topic,
                                         comment=comment,
                                         is_active=True,
                                         is_read=True)
        TopicNotification.objects.create(user=subscriber,
                                         topic=topic,
                                         comment=comment,
                                         is_active=True,
                                         is_read=True)

        TopicNotification.notify_new_comment(comment)
        notification = TopicNotification.objects.get(user=subscriber,
                                                     topic=topic)
        self.assertTrue(notification.is_active)
        self.assertFalse(notification.is_read)
        self.assertEqual(notification.action, COMMENT)

        # Author should not be notified of its own comment
        notification2 = TopicNotification.objects.get(user=creator,
                                                      topic=topic)
        self.assertTrue(notification2.is_read)
Esempio n. 2
0
    def setUp(self):
        utils.cache_clear()
        self.user = utils.create_user()
        self.user2 = utils.create_user()
        self.category = utils.create_category()
        self.topic = utils.create_topic(self.category)
        self.comment = utils.create_comment(topic=self.topic)

        # comment notification
        self.topic_notification = TopicNotification.objects.create(
            user=self.user,
            topic=self.topic,
            comment=self.comment,
            is_active=True,
            action=COMMENT)
        self.topic_notification2 = TopicNotification.objects.create(
            user=self.user2,
            topic=self.topic,
            comment=self.comment,
            is_active=True,
            action=COMMENT)

        # subscription to topic
        self.topic2 = utils.create_topic(self.category)
        self.comment2 = utils.create_comment(topic=self.topic2)
        self.topic_subscrption = TopicNotification.objects.create(
            user=self.user,
            topic=self.topic2,
            comment=self.comment2,
            is_active=True)
Esempio n. 3
0
 def setUp(self):
     utils.cache_clear()
     self.user = utils.create_user()
     self.user2 = utils.create_user()
     self.category = utils.create_category()
     self.topic = utils.create_topic(self.category, user=self.user2)
     self.topic2 = utils.create_topic(self.category)
Esempio n. 4
0
 def test_login(self):
     """
     Should login the user
     """
     utils.create_user(username="******", password="******")
     form_data = {'username': "******", 'password': "******"}
     form = LoginForm(data=form_data)
     self.assertTrue(form.is_valid())
Esempio n. 5
0
 def test_login_email_case_sensitive(self):
     """
     Should login the user by email
     """
     utils.create_user(email="*****@*****.**", password="******")
     form_data = {'username': "******", 'password': "******"}
     form = LoginForm(data=form_data)
     self.assertTrue(form.is_valid())
Esempio n. 6
0
 def test_login_username_invalid(self):
     """
     Should not login invalid user
     """
     utils.create_user(username="******", password="******")
     form_data = {'username': "******", 'password': "******"}
     form = LoginForm(data=form_data)
     self.assertFalse(form.is_valid())
Esempio n. 7
0
 def test_registration_email_duplication_allowed(self):
     """
     Duplicated email allowed
     """
     utils.create_user(email='*****@*****.**')
     form_data = {'username': '******', 'email': '*****@*****.**',
                  'email2': '*****@*****.**', 'password': '******'}
     form = RegistrationForm(data=form_data)
     self.assertEqual(form.is_valid(), True)
Esempio n. 8
0
 def test_resend_activation_email_case_sensitive(self):
     """
     Should NOT lower the email before checking it
     """
     utils.create_user(email="*****@*****.**")
     form_data = {'email': '*****@*****.**', }
     form = ResendActivationForm(form_data)
     self.assertFalse(form.is_valid())
     self.assertRaises(AttributeError, form.get_user)
Esempio n. 9
0
 def test_email_auth_backend_email_duplication(self):
     """
     it should NOT authenticate when the email is not unique (current behaviour, sorry)
     """
     utils.create_user(email="*****@*****.**", password="******")
     utils.create_user(email="*****@*****.**", password="******")
     user = EmailAuthBackend().authenticate(
         request=None, username="******", password="******")
     self.assertIsNone(user)
Esempio n. 10
0
 def test_registration_email_duplication(self):
     """
     register, don't allow email duplication
     """
     utils.create_user(email='*****@*****.**')
     form_data = {'username': '******', 'email': '*****@*****.**',
                  'email2': '*****@*****.**', 'password': '******'}
     form = RegistrationForm(data=form_data)
     self.assertEqual(form.is_valid(), False)
     self.assertNotIn('email', form.cleaned_data)
Esempio n. 11
0
    def test_resend_activation_email_invalid_email(self):
        """
        resend_activation_email invalid password
        """
        utils.create_user(password="******")

        form_data = {'email': "*****@*****.**", }
        response = self.client.post(reverse('spirit:user:auth:resend-activation'),
                                    form_data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(len(mail.outbox), 0)
Esempio n. 12
0
    def test_topic_notification_ajax_escape(self):
        """
        The receive username and topic title should be escaped
        """
        user = utils.create_user(username="******")
        topic = utils.create_topic(self.category,
                                   title="<tag>Have you met Ted?</tag>")
        notification = TopicNotification.objects.create(
            user=self.user,
            topic=topic,
            comment=utils.create_comment(topic=topic, user=user),
            is_active=True,
            action=COMMENT)

        utils.login(self)
        response = self.client.get(
            reverse('spirit:topic:notification:index-ajax'),
            HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        res = json.loads(response.content.decode('utf-8'))
        expected = {
            'user': "******",
            'action': notification.action,
            'title': "&lt;tag&gt;Have you met Ted?&lt;/tag&gt;",
            'url': notification.get_absolute_url(),
            'is_read': notification.is_read
        }
        self.assertDictEqual(res['n'][0], expected)
Esempio n. 13
0
    def test_topic_notification_ajax_order(self):
        """
        order by is_read=False first then by date
        """
        user = utils.create_user()

        for _ in range(10):
            topic = utils.create_topic(self.category, user=user)
            comment = utils.create_comment(topic=topic, user=user)
            TopicNotification.objects.create(user=self.user,
                                             topic=topic,
                                             comment=comment,
                                             is_active=True,
                                             action=COMMENT)

        TopicNotification.objects.filter(user=self.user).update(is_read=True)
        old_date = timezone.now() - datetime.timedelta(days=10)
        (TopicNotification.objects.filter(
            pk=self.topic_notification.pk).update(is_read=False,
                                                  date=old_date))

        utils.login(self)
        response = self.client.get(
            reverse('spirit:topic:notification:index-ajax'),
            HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        res = json.loads(response.content.decode('utf-8'))
        self.assertFalse(res['n'][0]['is_read'])
        self.assertTrue(res['n'][1]['is_read'])
Esempio n. 14
0
 def setUp(self):
     utils.cache_clear()
     self.user = utils.create_user()
     self.user.st.is_administrator = True
     self.user.st.save()
     self.category = utils.create_category()
     self.topic = utils.create_topic(self.category, user=self.user)
Esempio n. 15
0
    def test_topic_private_bulk_create(self):
        """
        Create notifications for a bunch of users
        """
        TopicNotification.objects.all().delete()
        user = utils.create_user()
        user2 = utils.create_user()
        topic = utils.create_topic(self.category)
        comment = utils.create_comment(topic=topic)
        TopicNotification.bulk_create(users=[user, user2], comment=comment)
        self.assertEqual(len(TopicNotification.objects.all()), 2)

        notification = TopicNotification.objects.get(user=user,
                                                     topic=comment.topic)
        self.assertTrue(notification.is_active)
        self.assertFalse(notification.is_read)
        self.assertEqual(notification.comment, comment)
Esempio n. 16
0
    def test_resend_activation_email_duplication(self):
        """
        Send email to the first *not verified* user found
        """
        utils.create_user(email="*****@*****.**")
        user2 = utils.create_user(email="*****@*****.**")
        user3 = utils.create_user(email="*****@*****.**")
        form_data = {'email': '*****@*****.**', }
        form = ResendActivationForm(form_data)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.get_user(), user3)

        user3.st.is_verified = True
        user3.st.save()
        form = ResendActivationForm(form_data)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.get_user(), user2)
Esempio n. 17
0
 def test_resend_activation_email(self):
     """
     resend activation
     """
     user = utils.create_user(email="*****@*****.**")
     form_data = {'email': '*****@*****.**', }
     form = ResendActivationForm(form_data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.get_user(), user)
Esempio n. 18
0
 def test_resend_activation_email_case_insensitive(self):
     """
     Should lower the email before checking it
     """
     user = utils.create_user(email="*****@*****.**")
     form_data = {'email': '*****@*****.**', }
     form = ResendActivationForm(form_data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.get_user(), user)
Esempio n. 19
0
    def test_topic_notification_notify_new_comment_unactive(self):
        """
        Should do nothing if notification is unactive
        """
        creator = utils.create_user()
        subscriber = utils.create_user()
        topic = utils.create_topic(self.category)
        comment = utils.create_comment(user=creator, topic=topic)
        TopicNotification.objects.create(user=subscriber,
                                         topic=topic,
                                         comment=comment,
                                         is_active=False,
                                         is_read=True)

        TopicNotification.notify_new_comment(comment)
        notification = TopicNotification.objects.get(user=subscriber,
                                                     topic=topic)
        self.assertTrue(notification.is_read)
Esempio n. 20
0
 def test_username_auth_backend_case_sensitive_off(self):
     usr = utils.create_user(
         username="******",
         password="******")
     user = UsernameAuthBackend().authenticate(
         request=None, username="******", password="******")
     self.assertEqual(user.pk, usr.pk)
     user = UsernameAuthBackend().authenticate(
         request=None, username="******", password="******")
     self.assertIsNone(user)
Esempio n. 21
0
 def setUp(self):
     utils.cache_clear()
     self.user = utils.create_user()
     self.user2 = utils.create_user()
     self.category = utils.create_category()
     self.topic = utils.create_topic(self.category)
     self.comment = utils.create_comment(topic=self.topic)
     self.topic_notification = TopicNotification.objects.create(
         user=self.user,
         topic=self.topic,
         comment=self.comment,
         is_active=True,
         action=COMMENT,
         is_read=True)
     self.topic_notification2 = TopicNotification.objects.create(
         user=self.user2,
         topic=self.topic,
         comment=self.comment,
         is_active=True,
         action=COMMENT,
         is_read=True)
Esempio n. 22
0
    def test_resend_activation_email_invalid_previously_logged_in(self):
        """
        resend_activation_email invalid if is_verified was set
        """
        user = utils.create_user(password="******")
        user.st.is_verified = True
        user.st.save()

        form_data = {'email': user.email, 'password': "******"}
        response = self.client.post(
            reverse('spirit:user:auth:resend-activation'), form_data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(len(mail.outbox), 0)
Esempio n. 23
0
 def test_topic_notification_mark_all_as_read(self):
     TopicNotification.objects.all().delete()
     user2 = utils.create_user()
     topic = utils.create_topic(self.category)
     comment = utils.create_comment(topic=topic)
     TopicNotification.objects.create(user=user2,
                                      topic=topic,
                                      comment=comment,
                                      is_active=True,
                                      action=MENTION)
     topic0 = utils.create_topic(self.category)
     comment0 = utils.create_comment(topic=topic0)
     TopicNotification.objects.create(user=self.user,
                                      topic=topic0,
                                      comment=comment0,
                                      is_active=True,
                                      action=COMMENT)
     topic1 = utils.create_topic(self.category)
     comment1 = utils.create_comment(topic=topic1)
     TopicNotification.objects.create(user=self.user,
                                      topic=topic1,
                                      comment=comment1,
                                      is_active=True,
                                      action=COMMENT)
     topic2 = utils.create_topic(self.category)
     comment2 = utils.create_comment(topic=topic2)
     TopicNotification.objects.create(user=self.user,
                                      topic=topic2,
                                      comment=comment2,
                                      is_active=True,
                                      action=MENTION)
     self.assertEqual(
         TopicNotification.objects.filter(user=self.user,
                                          is_read=False).count(), 3)
     self.assertEqual(
         TopicNotification.objects.filter(user=user2,
                                          is_read=False).count(), 1)
     utils.login(self)
     response = self.client.post(
         reverse('spirit:topic:notification:mark-all-as-read'))
     self.assertRedirects(response,
                          reverse('spirit:topic:notification:index'),
                          status_code=302)
     self.assertEqual(
         TopicNotification.objects.filter(user=self.user,
                                          is_read=False).count(), 0)
     self.assertEqual(
         TopicNotification.objects.filter(user=user2,
                                          is_read=False).count(), 1)
Esempio n. 24
0
    def test_topic_notification_update_invalid_user(self):
        """
        test user cant unsubscribe other user
        """
        user = utils.create_user()
        notification = TopicNotification.objects.create(user=user,
                                                        topic=self.topic,
                                                        comment=self.comment)

        utils.login(self)
        form_data = {}
        response = self.client.post(
            reverse('spirit:topic:notification:update',
                    kwargs={
                        'pk': notification.pk,
                    }), form_data)
        self.assertEqual(response.status_code, 404)
Esempio n. 25
0
    def test_resend_activation_email(self):
        """
        resend_activation_email
        """
        user = utils.create_user(password="******")

        form_data = {'email': user.email,
                     'password': "******"}
        response = self.client.post(reverse('spirit:user:auth:resend-activation'),
                                    form_data)
        expected_url = reverse("spirit:user:auth:login")
        self.assertRedirects(response, expected_url, status_code=302)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, _("User activation"))

        # get
        response = self.client.get(reverse('spirit:user:auth:resend-activation'))
        self.assertEqual(response.status_code, 200)
Esempio n. 26
0
    def test_topic_notification_create_maybe(self):
        """
        Should create a notification if does not exists
        """
        user = utils.create_user()
        topic = utils.create_topic(self.category)
        comment = utils.create_comment(topic=topic)
        TopicNotification.create_maybe(user=user, comment=comment)
        notification = TopicNotification.objects.get(user=user, topic=topic)
        self.assertTrue(notification.is_active)
        self.assertTrue(notification.is_read)
        self.assertEqual(notification.action, COMMENT)

        # Creating it again should do nothing
        (TopicNotification.objects.filter(user=user,
                                          topic=topic).update(is_active=False))
        TopicNotification.create_maybe(user=user, comment=comment)
        self.assertFalse(
            TopicNotification.objects.get(user=user, topic=topic).is_active)
Esempio n. 27
0
    def test_topic_active_view_bookmark(self):
        """
        topics with bookmarks
        """
        utils.login(self)
        category = utils.create_category()
        topic = utils.create_topic(category=category, user=self.user)
        bookmark = CommentBookmark.objects.create(topic=topic, user=self.user)

        user2 = utils.create_user()
        CommentBookmark.objects.create(topic=topic, user=user2)

        topic2 = utils.create_topic(category=category, user=self.user)
        CommentBookmark.objects.create(topic=topic2, user=self.user)
        ten_days_ago = timezone.now() - datetime.timedelta(days=10)
        Topic.objects.filter(pk=topic2.pk).update(last_active=ten_days_ago)

        response = self.client.get(reverse('spirit:topic:index-active'))
        self.assertEqual(list(response.context['topics']), [topic, topic2])
        self.assertEqual(response.context['topics'][0].bookmark, bookmark)
Esempio n. 28
0
def test_viewtopic(app):
    user = utils.create_user()
    category = utils.create_category()
    topic = utils.create_topic(category=category, user=user)

    PhpBBForumRefs.objects.create(category=category, phpbb_forum_id=1)
    PhpBBTopicRefs.objects.create(topic=topic, phpbb_forum_id=1, phpbb_topic_id=2)

    # Test success
    app.get('/forum/viewforum.php?f=1')
    app.get('/forum/viewtopic.php?f=1&t=2')

    # Test 404
    app.get('/forum/viewforum.php?f=2', status=404)
    app.get('/forum/viewtopic.php?f=1&t=3', status=404)

    # Test NaN's
    app.get('/forum/viewtopic.php?f=NaN', status=404)
    app.get('/forum/viewtopic.php?t=42NaN', status=404)
    app.get('/forum/viewforum.php?f=42Nan', status=404)
Esempio n. 29
0
    def test_topic_notification_ajax_limit(self):
        """
        get first N notifications
        """
        user = utils.create_user()
        topic = utils.create_topic(self.category, user=user)
        comment = utils.create_comment(topic=topic, user=user)
        TopicNotification.objects.create(user=self.user,
                                         topic=topic,
                                         comment=comment,
                                         is_active=True,
                                         action=COMMENT)

        utils.login(self)
        response = self.client.get(
            reverse('spirit:topic:notification:index-ajax'),
            HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        res = json.loads(response.content.decode('utf-8'))
        self.assertGreater(
            TopicNotification.objects.filter(user=self.user).count(), 1)
        self.assertEqual(len(res['n']), 1)
Esempio n. 30
0
 def setUp(self):
     utils.cache_clear()
     self.user = utils.create_user(
         email="*****@*****.**",
         password="******")
Esempio n. 31
0
 def setUp(self):
     utils.cache_clear()
     self.user = utils.create_user()