class APITest(unittest.TestCase): ''' Тестирование работоспособности класса для работы с API ''' def __init__(self, *args, **kwargs): super(APITest, self).__init__(*args, **kwargs) api = API(TOKEN) try: api.friends.get() except APIError: print "Token is invalid or expires. Try to refresh token by using this url " + REFRESH_TOKEN_URL except URLError: print "No connection" def setUp(self): self.api = API(TOKEN) logging.basicConfig(level=logging.DEBUG) def test_basic(self): answer = self.api.getProfiles(uids='durov,andrew') self.assertEqual(answer[0]['uid'], 1) self.assertEqual(answer[1]['uid'], 6492) self.assertEqual(self.api.isAppUser(), "1") def test_wall(self): # Add post post = self.api.wall.post(message='You are welcome!') post_id = post['post_id'] # Get my ID wall = self.api.wall.get() mid = wall[1]['to_id'] post_id = str(mid) + '_' + str(post_id) print post_id # Get post self.assertEqual(self.api.wall.getById(posts=post_id)[0]['id'], post['post_id']) # Remove post self.api.wall.delete(post_id=post['post_id'])
def setUp(self): self.api = API(TOKEN) logging.basicConfig(level=logging.DEBUG)