Beispiel #1
0
    def test_post_question_facebook(self):
        c = SocialClient()
        c.login(self.user, backend='facebook')
        u = User.objects.get(email='*****@*****.**')
        u.profile.locality = self.entity
        u.profile.save()
        post_url = reverse('post_question', args=(self.entity.slug, ))
        self.mock_request.return_value.content = json.dumps({'id': 1})
        response = c.post(
            post_url, {
                'subject': "Where?",
                'facebook_publish': 'on',
                'entity': self.entity.id,
            })
        self.assertEquals(response.status_code, 302)
        new_q = Question.objects.get(subject="Where?")

        self.mock_request.assert_called_with(
            'POST',
            'https://graph.facebook.com/me/localshot:ask',
            files={},
            data={
                'question': 'http://example.com%s' % new_q.get_absolute_url(),
                'access_token': 'dummyToken'
            })
Beispiel #2
0
    def test_post_question_facebook(self):
        c = SocialClient()
        c.login(self.user, backend='facebook')
        u=User.objects.get(email='*****@*****.**')
        u.profile.locality = self.home
        u.profile.is_candidate = True
        u.profile.save()
        post_url = reverse('post_answer', args=(self.q.id, ))
        self.mock_request.return_value.content = json.dumps({
            'id': 1
        })
        response = c.post(post_url, {'content':"42",
                        })
        self.assertEquals(response.status_code, 302)
        new_a=Answer.objects.get(content="42")

        self.mock_request.assert_called_with(
            'POST',
            'https://graph.facebook.com/me/localshot:answer',
            files={},
            data={
                'question': 'http://example.com%s' % new_a.get_absolute_url(),
                'access_token': 'dummyToken'
            }
        )
Beispiel #3
0
    def test_post_question_facebook(self):
        c = SocialClient()
        c.login(self.user, backend='facebook')
        u=User.objects.get(email='*****@*****.**')
        u.profile.locality = self.entity
        u.profile.is_candidate = True
        u.profile.save()
        post_url = reverse('post_answer', args=(self.q.id, ))
        self.mock_request.return_value.content = json.dumps({
            'id': 1
        })
        response = c.post(post_url, {'content':"42",
                        })
        self.assertEquals(response.status_code, 302)
        new_a=Answer.objects.get(content="42")

        self.mock_request.assert_called_with(
            'POST',
            'https://graph.facebook.com/me/localshot:answer',
            files={},
            data={
                'question': 'http://example.com%s' % new_a.get_absolute_url(),
                'access_token': 'dummyToken'
            }
        )
Beispiel #4
0
    def test_post_question_facebook(self):
        c = SocialClient()
        c.login(self.user, backend='facebook')
        u=User.objects.get(email='*****@*****.**')
        u.profile.locality = self.home
        u.profile.save()
        post_url = reverse('post_question')
        self.mock_request.return_value.content = json.dumps({
            'id': 1
        })
        response = c.post(post_url, {'subject':"Where?",
                        'facebook_publish': 'on',
                        'home': self.home.id,
                        })
        self.assertEquals(response.status_code, 302)
        new_q=Question.objects.get(subject="Where?")

        self.mock_request.assert_called_with(
            'POST',
            'https://graph.facebook.com/me/localshot:ask',
            files={},
            data={
                'question': 'http://example.com%s' % new_q.get_absolute_url(),
                'access_token': 'dummyToken'
            }
        )
Beispiel #5
0
    def test_upvote(self):
        c = SocialClient()
        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertEquals(response.status_code, 302)
        c.login(self.user, backend='facebook')
        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertEquals(response.status_code, 200)

        u = User.objects.get(email='*****@*****.**')
        u.profile.locality = self.common_user.profile.locality
        u.profile.save()
        self.mock_request.return_value.content = json.dumps({'id': 1})
        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertEquals(response.status_code, 403)
        self.assertEquals(response.content,
                          'You already upvoted this question')
        self.mock_request.assert_called_with(
            'POST',
            'https://graph.facebook.com/me/localshot:join',
            files={},
            data={
                'question': 'http://example.com%s' % self.q.get_absolute_url(),
                'access_token': 'dummyToken'
            })

        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertEquals(response.status_code, 403)
        self.assertEquals(response.content,
                          'You already upvoted this question')
 def _social_user(self):
     client = SocialClient()
     user = {'username': self.username,
             'first_name': self.full_name.split()[0],
             'last_name': self.full_name.split()[1],
             'email': self.email,
             'id': '53233',
             }
     backends = ('social_auth.backends.facebook.FacebookBackend',)
     backends += settings.AUTHENTICATION_BACKENDS
     with self.settings(AUTHENTICATION_BACKENDS=backends):
         client.login(user, backend='facebook')
     # Make sure associated user was created
     social_user = UserSocialAuth.objects.all()[0]
     return social_user.user
Beispiel #7
0
    def test_upvote(self):
        c = SocialClient()
        response = c.post(reverse('upvote_question', kwargs={'q_id':self.q.id}))
        self.assertEquals(response.status_code, 302)
        c.login(self.user, backend='facebook')
        u=User.objects.get(email='*****@*****.**')
        u.profile.locality = self.common_user.profile.locality
        u.profile.save()
        self.mock_request.return_value.content = json.dumps({
            'id': 1
        })
        response = c.post(reverse('upvote_question', kwargs={'q_id':self.q.id}))
        self.assertEquals(response.status_code, 200)

        response = c.post(reverse('upvote_question', kwargs={'q_id':self.q.id}))
        self.assertEquals(response.status_code, 403)
        self.assertEquals(response.content, 'You already upvoted this question')
        self.mock_request.assert_called_with(
            'POST',
            'https://graph.facebook.com/me/localshot:join',
            files={},
            data={
                'question': 'http://example.com%s' % self.q.get_absolute_url(),
                'access_token': 'dummyToken'
            }
        )

        response = c.post(reverse('upvote_question', kwargs={'q_id':self.q.id}))
        self.assertEquals(response.status_code, 403)
        self.assertEquals(response.content, 'You already upvoted this question')
Beispiel #8
0
 def test_social_login(self):
     client = SocialClient()
     user = {'username': self.username,
             'first_name': 'Jane',
             'last_name': 'Doe',
             'email': self.email,
             'id': '53233',
             }
     backends = ('social_auth.backends.facebook.FacebookBackend',)
     backends += settings.AUTHENTICATION_BACKENDS
     with self.settings(AUTHENTICATION_BACKENDS=backends):
         login = client.login(user, backend='facebook')
     # Login was success
     self.assertTrue(login)
     # Make sure associated user was created
     users = User.objects.all()
     self.assertEqual(users.count(), 1)
     # Confirm settings (username, email, and no usable password)
     user = users[0]
     self.assertEqual(user.username, self.username)
     self.assertEqual(user.email, self.email)
     self.assertFalse(user.has_usable_password())
Beispiel #9
0
 def test_upvote(self):
     c = SocialClient()
     response = c.post(
         reverse('upvote_question', kwargs={'q_id': self.q.id}))
     self.assertEquals(response.status_code, 302)
     c.login(self.user, backend='facebook')
     response = c.post(
         reverse('upvote_question', kwargs={'q_id': self.q.id}))
     self.assertEquals(response.status_code, 200)
     self.assertEquals(response.content, "2")
     response = c.post(
         reverse('upvote_question', kwargs={'q_id': self.q.id}))
     self.assertEquals(response.status_code, 403)
Beispiel #10
0
 def test_upvote(self):
     c = SocialClient()
     response = c.post(reverse('upvote_question', kwargs={'q_id':self.q.id}))
     self.assertEquals(response.status_code, 302)
     c.login(self.user, backend='facebook')
     response = c.post(reverse('upvote_question', kwargs={'q_id':self.q.id}))
     self.assertEquals(response.status_code, 200)
     self.assertEquals(response.content, "2")
     response = c.post(reverse('upvote_question', kwargs={'q_id':self.q.id}))
     self.assertEquals(response.status_code, 403)
Beispiel #11
0
    def test_upvote(self):
        c = SocialClient()
        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertEquals(response.status_code, 302)
        c.login(self.user, backend='facebook')
        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertRedirects(
            response, '%s?next=%s' %
            (reverse("edit_profile"),
             reverse('upvote_question', kwargs={'q_id': self.q.id})))

        u = User.objects.get(email='*****@*****.**')
        u.profile.locality = self.common_user.profile.locality
        u.profile.save()
        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(response.content, "2")
        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertEquals(response.status_code, 403)
Beispiel #12
0
    def test_post_not_killing_upvote(self):
        '''
        Related to issue #365:

        When a user add a description to a question it looses all followers.
        '''

        # Create a new question
        c = Client()
        self.assertTrue(c.login(username="******", password="******"))
        post_url = reverse('post_question')
        response = c.get(post_url)
        self.assertEquals(response.status_code, 200)
        self.assertFalse(
            Question.objects.filter(entity_id=self.home.id,
                                    unislug='Why?').count())
        response = c.post(
            post_url, {
                'subject': "What?",
                'entity': self.home.id,
                'content': 'Yes!',
                'tags': '',
            })
        new_q = Question.objects.get(subject="What?")
        self.assertRedirects(response, new_q.get_absolute_url())

        # Upvote the question
        c = SocialClient()
        response = c.post(
            reverse('upvote_question', kwargs={'q_id': self.q.id}))
        self.assertEquals(response.status_code, 302)
        c.login(self.user, backend='facebook')
        u = User.objects.get(email='*****@*****.**')
        u.profile.locality = self.common_user.profile.locality
        u.profile.save()
        self.mock_request.return_value.content = json.dumps({'id': 1})
        response = c.post(reverse('upvote_question', kwargs={'q_id':
                                                             new_q.id}))
        self.assertEquals(response.status_code, 200)

        # Edit the question
        c = Client()
        post_url = reverse('edit_question', kwargs={'slug': new_q.unislug})
        self.assertTrue(c.login(username="******", password="******"))
        response = c.get(post_url)
        self.assertEquals(response.status_code, 200)
        self.assertFalse(
            Question.objects.filter(entity_id=self.home.id,
                                    unislug='Why?').count())
        response = c.post(
            post_url, {
                'id': new_q.id,
                'content': 'Because we like it!',
                'tags': '',
                'subject': new_q.subject,
                'entity': self.home.id,
            })
        self.assertRedirects(response, new_q.get_absolute_url())

        # Check question's rating.
        # Before the bug fix, it used to be 1.
        updated_q = Question.objects.get(subject="What?")
        self.assertEquals(updated_q.rating, 2)