def test_tw_api(self): # auth token = tw_api.get_authtoken() self.assertTrue(token) print token # top-tweets res = tw_api.get_toptweets(token, "New Spiderman") self.assertEqual(type(res), tuple) self.assertEqual(res[0], 200) self.assertTrue(isinstance(res[1], list))
def toptweets(): """ request: /GET /api/tweets/top?q=Query response: 200, { tweets:[tweet] } | 400, {reason:"error message"} """ q = request.args.get('q', '') if not q: return err("Empty query is not valid") token = get_token() status, res = tw_api.get_toptweets(token, q) if status != 200: return err(res) return jsonify(dict(tweets=res))