class GetUserTestCase(unittest.TestCase): def setUp(self): self.sObj = Splitwise('consumerkey', 'consumersecret') def test_getUser_success(self, mockMakeRequest): mockMakeRequest.return_value = '{"user":{"id":12323,"first_name":"Naman","last_name":"Aggarwal","picture":{"small":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/small_mypic.jpg","medium":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/medium_mypic.jpg","large":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/large_mypic.jpg"},"email":"*****@*****.**","registration_status":"confirmed"}}' # noqa: E501 user = self.sObj.getUser(12323) mockMakeRequest.assert_called_with( "https://secure.splitwise.com/api/v3.0/get_user/12323") self.assertEqual(user.getId(), 12323) self.assertEqual(user.getFirstName(), "Naman") self.assertEqual(user.getLastName(), "Aggarwal") self.assertEqual(user.getEmail(), "*****@*****.**") def test_getUser_exception(self, mockMakeRequest): mockMakeRequest.side_effect = Exception( "Invalid response %s. Please check your consumer key and secret." % 404) with self.assertRaises(Exception): self.sObj.getUser(12323) mockMakeRequest.assert_called_with( "https://secure.splitwise.com/api/v3.0/get_user/12323")
consumer_key = 'K2RVWcYTGp0QIzylLWqyzipnDfubTzy06vx7MqKb' consumer_secret = 'AJDC5d3vVX84xiazuZZGBvCfPI9iiu3ZnUVgRvXi' from splitwise import Splitwise import oauth2 as oauth sObj = Splitwise("K2RVWcYTGp0QIzylLWqyzipnDfubTzy06vx7MqKb", "AJDC5d3vVX84xiazuZZGBvCfPI9iiu3ZnUVgRvXi") '''Consumer = oauth.Consumer(consumer_key, consumer_secret) client = oauth.Client(Consumer)''' sObj = Splitwise(Config.consumer_key, Config.consumer_secret) sObj.setAccessToken(session['access_token']) id = 7123 user = sObj.getUser(id)