Esempio n. 1
0
class WorkerTestCase(unittest.TestCase):
    def setUp(self):
        self.spdownloader = StackExchangeDownloader('stackoverflow')
    def test_answers_save_and_get_from_datastore(self):
        answers = ['dict1', 'dict2', 'dict3', 'dict4']
        question_id = 1
        service = 'foo'
        deferred_store_answers_to_cache(question_id, service, answers)
        answers_from_cache = dbquestion.get_answers(question_id, service)
        self.assertEquals(answers, answers_from_cache)
        
        #636 answers
        answers = self.spdownloader.get_answers(58640)
        deferred_store_answers_to_cache(58640, 'stackoverflow', answers)
        answers_from_cache = dbquestion.get_answers(58640, 'stackoverflow')
        self.assertEquals(answers, answers_from_cache)
        
        #148 answers
        answers = self.spdownloader.get_answers(101268)
        deferred_store_answers_to_cache(101268, 'stackoverflow', answers)
        answers_from_cache = dbquestion.get_answers(101268, 'stackoverflow')
        self.assertEquals(answers, answers_from_cache)
        
        #0 answers
        answers = self.spdownloader.get_answers(3940165)
        deferred_store_answers_to_cache(3940165, 'stackoverflow', answers)
        answers_from_cache = dbquestion.get_answers(3940165, 'stackoverflow')
        self.assertEquals(answers, answers_from_cache)
    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)
Esempio n. 2
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
Esempio 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