Example #1
0
    def test_when_query_and_insert_columns_are_different_insertion_and_query_uses_diferent_cols(self):
        db = MongoDB()
        db.query("labsk_test")
        db.insert("to_delete")

        db.saveThread({'id':'1'})
        self.assertIsNone(db.find_one_by('id', '1'))

        db.query("to_delete")
        self.assertIsNotNone(db.find_one_by('id', '1'))

        db.drop("to_delete")
Example #2
0
    def test_search_thread(self):
        db = MongoDB()
        db.query("labsk_merge")
        tmp_col = "labsk_temp_temp"
        db.insert(tmp_col)

        process = ProcessThread()
        process.database = db

        result = process._search_thread(self.obj_thread)

        self.assertIsNotNone(result)

        db.drop(tmp_col)
Example #3
0
class TestPorcessWithMongo(unittest.TestCase):
    """ this test suites verify tje coordination between two collections and the
        detection of an unmodified thead.
    """

    def setUp(self):
        self.obj_thread = ThreadModel(Reports.get_asylum_thread())
        self.obj_thread.set_answers(59)
        self.mock_listener = mock()
        self.db = MongoDB()
        self.db.query("labsk_merge")

    def test_search_thread(self):
        db = MongoDB()
        db.query("labsk_merge")
        tmp_col = "labsk_temp_temp"
        db.insert(tmp_col)

        process = ProcessThread()
        process.database = db

        result = process._search_thread(self.obj_thread)

        self.assertIsNotNone(result)

        db.drop(tmp_col)

    def _create_process(self):
        process = ProcessThread()
        process.database = self.db
        process.listener =  self.mock_listener
        return process

    def test_skip_existing_thread_with_one_msg_and_0_answers(self):
        link = 'http://labsk.net/index.php?topic=127734.0'
        newT = ThreadModel({'link':link, 'msgs': [{}], 'answers':'0'})

        process = self._create_process()
        self.assertIsNotNone(process._search_thread(newT))
        process._evaluate_thread(newT)
        verify(self.mock_listener).skippingUnmodifiedThread(any(), newT)
Example #4
0
    def enteringThread(self, obj_thread):
        print "Thread ", obj_thread.title, ", ", obj_thread.date, " | ", obj_thread.link
        self.thread += 1

    # Override
    def skippingUnmodifiedThread(self, old, new):
        """ Old thread seems to be the same one than the new thread        """
        self.thread -= 1
        print "Skipping ", new.title, ", ", new.date, " | ", new.link

    def __str__(self):
        return ". Threads: " + str(self.thread) \


db = MongoDB()
db.query("labsk_merge")
db.insert("labsk_" + str(datetime.now()))

starttime = datetime.now()

listener = StdListener()
threads = ProcessThreads(db, MsgPageFactory())
threads.setListener(listener)
threads.setPageLimit(1)
threads.setMsgPageLimit(250)  # Nunca bajes este valor o perderas mensajes, al menos mantenlo igual

threads.scrapListOfURL(labsk_urls)
delta = datetime.now() - starttime

print "----------------------------------------------"
print "Total time: ", delta