Ejemplo n.º 1
0
 def GET(self):
     try:
         render = web.render
         question_id = web.input()['question']
         service = web.input()['service']
         
         se_downloader = StackExchangeDownloader(service)
         question = se_downloader.get_question_quicklook(question_id)
         if not question:
             return render.oops(NOT_FOUND_ERROR)
             
         if question.has_key('accepted_answer_id'):
             accepted_answer = se_downloader.get_answer_quicklook(question['accepted_answer_id'])
         else:
             accepted_answer = None
             
         return render.quicklook(service, question, accepted_answer)
     except (sepy.ApiRequestError, UnsupportedServiceError), exception:
         logging.error(exception)
         return render.oops(exception.message)
Ejemplo n.º 2
0
    def GET(self):
        try:
            render = web.render
            question_id = web.input()['question']
            service = web.input()['service']

            se_downloader = StackExchangeDownloader(service)
            question = se_downloader.get_question_quicklook(question_id)
            if not question:
                return render.oops(NOT_FOUND_ERROR)

            if question.has_key('accepted_answer_id'):
                accepted_answer = se_downloader.get_answer_quicklook(
                    question['accepted_answer_id'])
            else:
                accepted_answer = None

            return render.quicklook(service, question, accepted_answer)
        except (sepy.ApiRequestError, UnsupportedServiceError), exception:
            logging.error(exception)
            return render.oops(exception.message)
Ejemplo n.º 3
0
class StackprinterDownloaderTestCase(unittest.TestCase):
    
    def setUp(self):
        self.spdownloader = StackExchangeDownloader('stackoverflow') 
        #self.spdownloader.retriever = MockRetriever() #Comment to test ONLINE
        
    def test_get_question(self):     
        assert self.spdownloader.get_question(9) is not None
        assert self.spdownloader.get_question(0) is None
        assert self.spdownloader.get_question(9)['creation_date'] == 1217547659
        assert self.spdownloader.get_question(9)['title'] == "How do I calculate someone's age in C#?"
  
    def test_get_question_title(self):     
        assert self.spdownloader.get_question_title(9)== "How do I calculate someone's age in C#?"  
        assert self.spdownloader.get_question_title(0) is None       
        
    def test_get_answer_quicklook(self):
        assert self.spdownloader.get_answer_quicklook(22) is not None
        assert self.spdownloader.get_answer_quicklook(22)['title'] != ''
        assert self.spdownloader.get_answer_quicklook(0) is None
                
    def test_get_questions_by_tags(self):
        assert len(self.spdownloader.get_questions_by_tags('python', 1)[0]) > 0
        assert self.spdownloader.get_questions_by_tags('python', 1)[1].total > 0
        assert len(self.spdownloader.get_questions_by_tags('atagthedoesnotexist', 1)[0]) == 0 
        assert self.spdownloader.get_questions_by_tags('atagthedoesnotexist', 1)[1].total == 0
        assert self.spdownloader.get_questions_by_tags('python', 1)[0][0].question_id > 0
        assert self.spdownloader.get_questions_by_tags('python', 1)[0][0].url.startswith('http')
        assert self.spdownloader.get_questions_by_tags('python', 1)[0][0].service != ''

    def test_get_questions_by_votes(self):
        assert len(self.spdownloader.get_questions_by_votes(page = 1)[0]) > 0
        assert self.spdownloader.get_questions_by_votes(page = 1)[1].total > 0
        assert self.spdownloader.get_questions_by_votes(page = 1)[0][0].question_id > 0
        assert self.spdownloader.get_questions_by_votes(page = 1)[0][0].url.startswith('http')
        assert self.spdownloader.get_questions_by_votes(page = 1)[0][0].service != ''

    def test_get_answers(self):
        assert len(self.spdownloader.get_answers(656155)) == 3
        assert self.spdownloader.get_answers(656155)[0]['title'] != ''
        assert len(self.spdownloader.get_answers(9033)) == 303
        assert len(self.spdownloader.get_answers(656155)) == 3
        assert len(self.spdownloader.get_answers(37671)) == 51
        assert len(self.spdownloader.get_answers(209015)) == 49
        assert len(self.spdownloader.get_answers(347584)) == 50
        
    def test_get_users_by_id(self):   
        assert len(self.spdownloader.get_users_by_id(130929)) == 1
        assert self.spdownloader.get_users_by_id(130929)[0]['display_name'] == 'systempuntoout'
        
    def test_get_users(self):    
        assert len(self.spdownloader.get_users('systempuntoout')) == 1
        
    def test_get_favorites_questions(self): 
        assert len(self.spdownloader.get_favorites_questions(130929, 1)[0]) > 0
        assert self.spdownloader.get_favorites_questions(130929, 1)[0][0].title !=''
        assert self.spdownloader.get_favorites_questions(130929, 1)[1].total > 0
        assert self.spdownloader.get_favorites_questions(130929, 1)[0][0].question_id > 0
        assert self.spdownloader.get_favorites_questions(130929, 1)[0][0].url.startswith('http')
        assert self.spdownloader.get_favorites_questions(130929, 1)[0][0].service != ''
        
    def test_get_tags(self):
        assert len(self.spdownloader.get_tags('python')) > 0
Ejemplo n.º 4
0
class StackprinterDownloaderTestCase(unittest.TestCase):
    def setUp(self):
        self.spdownloader = StackExchangeDownloader('stackoverflow')
        #self.spdownloader.retriever = MockRetriever() #Comment to test ONLINE

    def test_get_question(self):
        assert self.spdownloader.get_question(9) is not None
        assert self.spdownloader.get_question(0) is None
        assert self.spdownloader.get_question(9)['creation_date'] == 1217547659
        assert self.spdownloader.get_question(
            9)['title'] == "How do I calculate someone's age in C#?"

    def test_get_question_title(self):
        assert self.spdownloader.get_question_title(
            9) == "How do I calculate someone's age in C#?"
        assert self.spdownloader.get_question_title(0) is None

    def test_get_answer_quicklook(self):
        assert self.spdownloader.get_answer_quicklook(22) is not None
        assert self.spdownloader.get_answer_quicklook(22)['title'] != ''
        assert self.spdownloader.get_answer_quicklook(0) is None

    def test_get_questions_by_tags(self):
        assert len(self.spdownloader.get_questions_by_tags('python', 1)[0]) > 0
        assert self.spdownloader.get_questions_by_tags('python',
                                                       1)[1].total > 0
        assert len(
            self.spdownloader.get_questions_by_tags('atagthedoesnotexist',
                                                    1)[0]) == 0
        assert self.spdownloader.get_questions_by_tags('atagthedoesnotexist',
                                                       1)[1].total == 0
        assert self.spdownloader.get_questions_by_tags('python',
                                                       1)[0][0].question_id > 0
        assert self.spdownloader.get_questions_by_tags(
            'python', 1)[0][0].url.startswith('http')
        assert self.spdownloader.get_questions_by_tags('python',
                                                       1)[0][0].service != ''

    def test_get_questions_by_votes(self):
        assert len(self.spdownloader.get_questions_by_votes(page=1)[0]) > 0
        assert self.spdownloader.get_questions_by_votes(page=1)[1].total > 0
        assert self.spdownloader.get_questions_by_votes(
            page=1)[0][0].question_id > 0
        assert self.spdownloader.get_questions_by_votes(
            page=1)[0][0].url.startswith('http')
        assert self.spdownloader.get_questions_by_votes(
            page=1)[0][0].service != ''

    def test_get_answers(self):
        assert len(self.spdownloader.get_answers(656155)) == 3
        assert self.spdownloader.get_answers(656155)[0]['title'] != ''
        assert len(self.spdownloader.get_answers(9033)) == 303
        assert len(self.spdownloader.get_answers(656155)) == 3
        assert len(self.spdownloader.get_answers(37671)) == 51
        assert len(self.spdownloader.get_answers(209015)) == 49
        assert len(self.spdownloader.get_answers(347584)) == 50

    def test_get_users_by_id(self):
        assert len(self.spdownloader.get_users_by_id(130929)) == 1
        assert self.spdownloader.get_users_by_id(
            130929)[0]['display_name'] == 'systempuntoout'

    def test_get_users(self):
        assert len(self.spdownloader.get_users('systempuntoout')) == 1

    def test_get_favorites_questions(self):
        assert len(self.spdownloader.get_favorites_questions(130929, 1)[0]) > 0
        assert self.spdownloader.get_favorites_questions(130929,
                                                         1)[0][0].title != ''
        assert self.spdownloader.get_favorites_questions(130929,
                                                         1)[1].total > 0
        assert self.spdownloader.get_favorites_questions(
            130929, 1)[0][0].question_id > 0
        assert self.spdownloader.get_favorites_questions(
            130929, 1)[0][0].url.startswith('http')
        assert self.spdownloader.get_favorites_questions(130929,
                                                         1)[0][0].service != ''

    def test_get_tags(self):
        assert len(self.spdownloader.get_tags('python')) > 0