Ejemplo n.º 1
0
    def test_connect_calls_create_friendship_on_twitter(self, mocked_twitter):
        api_object = Mock()
        friendship = Mock()
        friendship.following = True
        api_object.CreateFriendship.return_value = friendship
        mocked_twitter.Api.return_value = api_object

        connect = TwitterConnect(self.user)
        connection = connect.connect(self.other_user)
        assert connection is True
        api_object.CreateFriendship.assert_called_once_with(
            user_id=self.other_social_auth.uid, follow=False)
Ejemplo n.º 2
0
    def test_connect_raises_error_if_user_social_auth_does_not_exist(
            self, mocked_twitter):
        api_object = Mock()
        friendship = Mock()
        friendship.following = True
        api_object.CreateFriendship.return_value = friendship
        mocked_twitter.Api.return_value = api_object

        self.other_social_auth.delete()

        connect = TwitterConnect(self.user)
        with pytest.raises(SocialUserNotFound):
            connection = connect.connect(self.other_user)
        api_object.CreateFriendship.assert_not_called()
Ejemplo n.º 3
0
    def test_connect_users(self, mocked_twitter):
        api_object = Mock()
        friend = Mock()
        friends = [self.other_social_auth.uid]
        api_object.GetFriendIDsPaged.return_value = (0, None, friends)
        mocked_twitter.Api.return_value = api_object
        service = TwitterConnect(self.user)
        connections = service.connect_users()

        connection = Connection.objects.first()
        assert connections == [connection]
        assert connection.user_1 == self.user
        assert connection.user_2 == self.other_user
        assert connection.confirmed is True
Ejemplo n.º 4
0
 def test_authenticate_calls_api_with_tokens(self, mocked_twitter):
     connect = TwitterConnect(self.user)
     mocked_twitter.Api.assert_called_once_with(
         consumer_key=settings.SOCIAL_AUTH_TWITTER_KEY,
         consumer_secret=settings.SOCIAL_AUTH_TWITTER_SECRET,
         access_token_key='abcde',
         access_token_secret='acdbe')
Ejemplo n.º 5
0
    def test_connect_users_with_paging_and_unexisting_user(
            self, mocked_twitter):
        api_object = Mock()
        friend_1 = Mock()
        friend_2 = Mock()

        first_friends = [self.other_social_auth.uid]
        last_friends = ['invalid_id']
        api_object.GetFriendIDsPaged.side_effect = [(2, None, first_friends),
                                                    (0, None, last_friends)]
        mocked_twitter.Api.return_value = api_object
        service = TwitterConnect(self.user)
        connections = service.connect_users()

        connection = Connection.objects.first()
        assert connections == [connection]
        assert connection.user_1 == self.user
        assert connection.user_2 == self.other_user
        assert connection.confirmed is True
Ejemplo n.º 6
0
 def test_authenticate_raises_error_if_no_user_credentials(self):
     self.user_social_auth.extra_data = {}
     self.user_social_auth.save()
     with pytest.raises(CredentialsNotFound):
         connect = TwitterConnect(self.user)
Ejemplo n.º 7
0
 def test_authenticate_raises_error_if_no_user_social_auth(self):
     self.user_social_auth.delete()
     with pytest.raises(CredentialsNotFound):
         connect = TwitterConnect(self.user)
Ejemplo n.º 8
0
 def test_initialization_calls_authenticate_for_user_1(self, authenticate):
     connect = TwitterConnect(self.user)
     authenticate.assert_called_once_with(self.user)