def testGetRedditData(self): model.retrieve_data(True, 100) model.populate_reddit_data(model.reddit_cache) data = model.get_reddit_data() data2 = model.get_reddit_data("score") self.assertEqual(data2[0], data[0]) data3 = model.get_reddit_data("date") self.assertNotEqual(data3[0], data[0]) data4 = model.get_reddit_data("subreddit") self.assertNotEqual(data4[0], data[0]) data5 = model.get_reddit_data("postid") self.assertNotEqual(data5[0], data[0]) self.assertEqual(len(data[0]), 7) self.assertEqual(len(data2[0]), 7) self.assertEqual(len(data3[0]), 2) self.assertEqual(len(data4[0]), 2) self.assertEqual(len(data5[0]), 1)
def results(): if request.method == 'POST': use_cache = bool(int(request.form['getdata'])) number_posts = int(request.form['numberposts']) print(number_posts) model.retrieve_data(use_cache, number_posts) model.populate_reddit_data(model.reddit_cache) return render_template("results.html")
def testRedditLimit(self): model.retrieve_data(False, 100) model.populate_reddit_data(model.reddit_cache) data = model.get_reddit_data() self.assertEqual(len(data), 100) model.retrieve_data(False, 150) model.populate_reddit_data(model.reddit_cache) data = model.get_reddit_data() self.assertEqual(len(data), 150) model.retrieve_data(False, 200) model.populate_reddit_data(model.reddit_cache) data = model.get_reddit_data() self.assertEqual(len(data), 200)
def testRedditCache(self): model.retrieve_data(False, 100) model.populate_reddit_data(model.reddit_cache) data = model.get_reddit_data() self.assertEqual(len(data), 100) model.retrieve_data(True, 200) model.populate_reddit_data(model.reddit_cache) data2 = model.get_reddit_data() self.assertEqual(len(data2), len(data)) self.assertEqual(data2[0], data[0]) self.assertEqual(data2[1], data[1]) model.retrieve_data(False, 101) model.populate_reddit_data(model.reddit_cache) data3 = model.get_reddit_data() self.assertNotEqual(len(data3), len(data))
def get_data(): payload = request.json data = retrieve_data(payload) return json.dumps(data)