def get_post(self, question_id, bypass_cache = False): """ Return a post object representing the question and the answers list Return None if question/answers are not found from Api call or db cache (deleted questions) """ try: question = self.get_question(question_id) if question: post = Post(question, self.get_answers(question_id, int(question['up_vote_count'])-int(question['down_vote_count']) > VOTES_ENTRY_LEVEL)) else: #StackPrinter loves the legendary deleted questions post = Post(dbquestion.get_question(question_id, self.service), dbquestion.get_answers(question_id, self.service)) post.deleted = True except (sepy.ApiRequestError, urlfetch.DownloadError): post = Post(dbquestion.get_question(question_id, self.service), dbquestion.get_answers(question_id, self.service)) if not post.is_printable(): raise if post.is_printable(): try: deferred.defer(worker.deferred_store_print_statistics, post.question['question_id'], self.service, post.question['title'], post.question['tags'], post.deleted) except: logging.info("%s - defer error trying to store print statistics : %s" % (self.service, question_id)) return post else: return None
def test_question_save_and_get_from_datastore(self): question = ['dict1'] question_id = 1 service = 'foo' deferred_store_question_to_cache(question_id, service, question) question_from_cache = dbquestion.get_question(question_id, service) self.assertEquals(question, question_from_cache) question = self.spdownloader.get_question(3940165) deferred_store_question_to_cache(3940165, 'stackoverflow', question) question_from_cache = dbquestion.get_question(3940165, 'stackoverflow') self.assertEquals(question, question_from_cache)