def test_uses_provided_settings(self):
        random_key = "some random key %d" % random.randint(100, 200)
        random_secret = "ssh, some random secret %d" % random.randint(100, 200)

        my_settings = settings
        my_settings.D51_DJANGO['APPS']['TWITTER']['CONSUMER_KEY'] = random_key
        my_settings.D51_DJANGO['APPS']['TWITTER']['CONSUMER_SECRET'] = random_secret

        twitter = utils.get_twitter(my_settings)
        self.assertTrue(isinstance(twitter, dolt.Twitter), "sanity check")
        self.assertTrue(isinstance(twitter._http, oauth2.Client))

        self.assertEqual(random_key, twitter._http.consumer.key)
        self.assertEqual(random_secret, twitter._http.consumer.secret)
def create(request, id=None, twitter=None, format='json'):
    if request.method != 'POST':
        return HttpResponseNotAllowed(['POST', ])

    twitter = twitter if twitter else utils.get_twitter(token=request.user.twitter.get_oauth_token())
    if id:
        result = getattr(twitter.friendships.create, id).POST()
    else:
        get_params = {}
        user_id = request.GET.get('user_id')
        if user_id:
            get_params['user_id'] = user_id
        screen_name = request.GET.get('screen_name')
        if screen_name:
            get_params['screen_name'] = screen_name
        result = twitter.friendships.create.POST(**get_params)

    # TODO: add support for serializing to XML
    return HttpResponse(simplejson.dumps(result))
 def test_uses_provided_token_if_supplied(self):
     token = oauth2.Token('foobar', 'barfoo')
     twitter = utils.get_twitter(token=token)
     self.assertEqual(token, twitter._http.token)
 def test_does_not_have_token_by_default(self):
     twitter = utils.get_twitter()
     self.assertEqual(None, twitter._http.token)
 def test_uses_default_credentials_when_none_are_provided(self):
     twitter = utils.get_twitter()
     self.assertEqual("foobar", twitter._http.consumer.key)
     self.assertEqual("barfoo", twitter._http.consumer.secret)