def test_find_friends(self): """ Test find_friend method find_friend returns friends whose name starts with user inputted string """ httpretty.register_uri(httpretty.GET, FRIENDS_URL % (sample_user['username'], SAMPLE_ACCESS_TOKEN), body=json.dumps({'data' : sample_friends}), content_type='application/json') self.assertEquals(len(Venmo.findFriends('And')), 2) self.assertEquals(len(Venmo.findFriends('Andrew Staub')), 1) self.assertEquals(len(Venmo.findFriends('Nobody')), 0)
def test_exchange_token(self): """ Test exchange_token method exchange_token exchanges code for response with access_token """ httpretty.register_uri(httpretty.POST, TOKEN_URL, body='{"access_token" : "string", "user" : {"username": "******"}}', content_type='application/json') self.assertIsInstance(Venmo.exchange_token('code'), dict)
def test_show_options(self): """ Test show_options show_options shows list of options based on user inputted string """ wf._items = [] Venmo.show_options('') self.assertEquals(len(wf._items), 3) self.assertEquals(wf._items[0].title, LOGIN['title']) self.assertEquals(wf._items[1].title, LOGOUT['title']) self.assertEquals(wf._items[2].title, CLEAR_CACHE['title']) wf._items = [] Venmo.show_options('login') self.assertEquals(wf._items[0].title, LOGIN['title']) self.assertEquals(wf._items[0].arg, LOGIN['arg']) self.assertEquals(wf._items[0].autocomplete, LOGIN['autocomplete']) wf._items = [] Venmo.show_options('logout') self.assertEquals(wf._items[0].title, LOGOUT['title']) self.assertEquals(wf._items[0].arg, LOGOUT['arg']) self.assertEquals(wf._items[0].autocomplete, LOGOUT['autocomplete']) wf._items = [] Venmo.show_options('clear cache') self.assertEquals(wf._items[0].title, CLEAR_CACHE['title']) self.assertEquals(wf._items[0].arg, CLEAR_CACHE['arg']) self.assertEquals(wf._items[0].autocomplete, CLEAR_CACHE['autocomplete']) wf._items = [] Venmo.show_options('not result') self.assertEquals(wf._items[0].title, INVALID['title']) wf._items = []
def test_get_friends(self): """ Test get_friends method get_friends returns a list of friends from Venmo API """ httpretty.register_uri(httpretty.GET, FRIENDS_URL % (sample_user['username'], SAMPLE_ACCESS_TOKEN), body=json.dumps({'data' : sample_friends}), content_type='application/json') friends = Venmo.get_friends() self.assertTrue(isinstance(friends, list))
def test_show_formatting(self): """ Test show_formatting method show_formatting accepts user inputted string and displays options """ httpretty.register_uri(httpretty.GET, FRIENDS_URL % (sample_user['username'], SAMPLE_ACCESS_TOKEN), body=json.dumps({'data' : sample_friends}), content_type='application/json') wf._items = [] Venmo.show_formatting('Andrew Kortina') self.assertEquals(wf._items[0].title, 'Andrew Kortina [amount] [note]') wf._items = [] Venmo.show_formatting('Andrew Kortina ') self.assertEquals(wf._items[0].title, 'Andrew Kortina [amount] [note]') wf._items = [] Venmo.show_formatting('Andrew Kortina 1') self.assertEquals(wf._items[0].title, 'pay Andrew Kortina $1.00 [note]') wf._items = [] Venmo.show_formatting('Andrew Kortina -') self.assertEquals(wf._items[0].title, 'Andrew Kortina [amount] [note]') wf._items = [] Venmo.show_formatting('Andrew Kortina -1') self.assertEquals(wf._items[0].title, 'charge Andrew Kortina $1.00 [note]') wf._items = [] Venmo.show_formatting('Andrew Kortina 1 food') self.assertEquals(wf._items[0].title, 'pay Andrew Kortina $1.00 for food') wf._items = [] Venmo.show_formatting('Andrew Kortina -11.0 test') self.assertEquals(wf._items[0].title, 'charge Andrew Kortina $11.00 for test') wf._items = [] Venmo.show_formatting('Andrew Kortina food') self.assertEquals(wf._items[0].title, INVALID_FORMAT['title']) wf._items = []