def create_t2_task(test_case, book_id, task_t1):
    # creating an answer for the T1 app
    task_run = dict(app_id=task_t1.app_id, task_id=task_t1.id, info="Yes")

    # Anonymous submission
    submit_answer(test_case.base_url, task_run)
    
    # FB authenticated user submission
    task_run['facebook_user_id'] = '12345'
    submit_answer(test_case.base_url, task_run)
    
    # Signalling the T1 task completion
    done_task(test_case.app, task_t1.id)
    time.sleep(5)
    
    # check if T1 task is closed
    task_t1 = pbclient.get_tasks(task_t1.app_id, sys.maxint)[0]
    test_case.assertTrue(task_t1.state == "completed")
    
    # one task from T2 app should exist
    app_t2 = pbclient.find_app(short_name=book_id + "_tt2")
    test_case.assertTrue(len(app_t2) > 0, "Error tt_app was not created")
    
    t2_tasks = pbclient.get_tasks(app_t2[0].id, sys.maxint)
    test_case.assertTrue(len(t2_tasks) == 1)
    
    return t2_tasks[0]
def create_t4_task(test_case, book_id, task_t3, number_of_expected_t4_tasks):
    # creating an answer for the T3 app
    answer_t3 = '{\"img_url\":\"https://localhost/mb-static/books/rpparaiba1918/metadados/tabelasBaixa/image0_0.png\",\"linhas\":[[0,0,507,0],[0,54,507,54],[0,103,507,103],[0,178,507,178]],\"colunas\":[[0,0,0,178],[239,0,239,178],[507,0,507,178]],\"maxX\":507,\"maxY\":178}'
    task_run = dict(app_id=task_t3.app_id, task_id=task_t3.id, info=answer_t3)
    
    # Anonymous submission
    submit_answer(test_case.base_url, task_run)
    
    # FB authenticated user submission
    task_run['facebook_user_id'] = '12345'
    submit_answer(test_case.base_url, task_run)
    
    # Signalling the T3 task completion
    done_task(test_case.app, task_t3.id)
    time.sleep(10)
    
    # check if T3 task is closed
    task_t3 = pbclient.get_tasks(task_t3.app_id, sys.maxint)[0]
    test_case.assertTrue(task_t3.state == "completed")
    
    # one task from T4 app should exist
    app_t4 = pbclient.find_app(short_name=book_id + "_tt4")
    test_case.assertTrue(len(app_t4) > 0, "Error tt_app was not created")
    
    t4_tasks = pbclient.get_tasks(app_t4[0].id, sys.maxint)
    test_case.assertTrue(len(t4_tasks) == number_of_expected_t4_tasks)
    
    return t4_tasks
def create_t3_task(test_case, book_id, task_t2):
    # creating an answer for the T2 app
    answer_t2 = '[{\"id\":\"new\",\"top\":244,\"left\":24,\"width\":506,\"height\":177,\"text\":{\"titulo\":\"test-titulo\",\"subtitulo\":\"test-subtitulo\",\"assunto\":\"0\",\"fontes\":\"test-fontes\",\"outros\":\"\",\"dataInicial\":\"01/01/1901\",\"dataFinal\":\"01/01/1902\",\"girar\":false,\"nao_girar\":true},\"editable\":true}, {\"id\":\"new\",\"top\":100,\"left\":300,\"width\":250,\"height\":230,\"text\":{\"titulo\":\"test-titulo\",\"subtitulo\":\"test-subtitulo\",\"assunto\":\"3\",\"fontes\":\"test-fontes\",\"outros\":\"test-outros\",\"dataInicial\":\"01/01/1901\",\"dataFinal\":\"01/01/1902\",\"girar\":false,\"nao_girar\":true},\"editable\":true}]'
    task_run = dict(app_id=task_t2.app_id, task_id=task_t2.id, info=answer_t2)
    
    # Anonymous submission
    submit_answer(test_case.base_url, task_run)
    
    # FB authenticated user submission
    task_run['facebook_user_id'] = '12345'
    submit_answer(test_case.base_url, task_run)
    
    # Signalling the T2 task completion
    done_task(test_case.app, task_t2.id)
    time.sleep(15)
    
    # check if T2 task is closed
    task_t2 = pbclient.get_tasks(task_t2.app_id, sys.maxint)[0]
    test_case.assertTrue(task_t2.state == "completed")
    
    # one task from T3 app should exist
    app_t3 = pbclient.find_app(short_name=book_id + "_tt3")
    test_case.assertTrue(len(app_t3) > 0, "Error tt_app was not created")
    
    t3_tasks = pbclient.get_tasks(app_t3[0].id, sys.maxint)
    test_case.assertTrue(len(t3_tasks) == 2)
    
    return t3_tasks
 def test_add_next_task_02(self):
     """
        Invalid book
     """
     try:
         book_title = "BLBLB_title"
         app = Apptt_meta(short_name="BLBLB_tt2", title=book_title)
         app.add_task(task_info=dict(link="http://archive.org/download/livro1/n1", page=1))
         app.add_task(task_info=dict(link="http://archive.org/download/livro1/n2", page=2))
          
         tasks = pbclient.get_tasks(app_id=app.app_id)
          
         task1 = TTTask2(tasks[0].id, app_short_name=app.short_name)
         task2 = TTTask2(tasks[1].id, app_short_name=app.short_name)
          
         book_id = "BLBLB"
         data_mngr.record_book(dict(bookid=book_id, title=book_title, contributor="cont1", publisher="pub1", volume="1", img="image1"))
          
         task_run1 = dict(app_id=app.app_id, task_id=task1.task.id, info="[{\"id\":\"new\",\"top\":50,\"left\":9.5,\"width\":525,\"height\":626,\"text\":{\"titulo\":\"\",\"subtitulo\":\"\",\"assunto\":\"4\",\"fontes\":\"\",\"outros\":\"\",\"dataInicial\":\"\",\"dataFinal\":\"\",\"girar\":false,\"nao_girar\":true},\"editable\":true}]")
         task_run2 = dict(app_id=app.app_id, task_id=task1.task.id, info="[{\"id\":\"new\",\"top\":50,\"left\":15.5,\"width\":625,\"height\":626,\"text\":{\"titulo\":\"\",\"subtitulo\":\"\",\"assunto\":\"4\",\"fontes\":\"\",\"outros\":\"\",\"dataInicial\":\"\",\"dataFinal\":\"\",\"girar\":false,\"nao_girar\":true},\"editable\":true}]")
    
         # Anonymous submission
         submit_answer(self.base_url, task_run1)
            
         # FB authenticated user submission
         task_run2['facebook_user_id'] = '12345'
         submit_answer(self.base_url, task_run2)
            
         time.sleep(2)
            
         self.assertFalse(task1.check_answer())
           
         task1.add_next_task()
         
         assert False   
     
     except Meb_exception_tt2 as e:
         self.assertEquals(e.code, 3)
     
     finally:
         next_app = None 
         next_app_list = pbclient.find_app(short_name=app.short_name[:-1] + "3")
         
         if len(next_app_list) > 0:
             next_app = next_app_list[0]
         
             next_task = None
             tasks = pbclient.get_tasks(next_app.id)
             for t in tasks:
                 if t.info["page"] == task1.task.info["page"]: 
                     pbclient.delete_task(task_id=t.id)
      
         pbclient.delete_app(app_id=next_app.id)
         
         pbclient.delete_task(task1.task.id)
         pbclient.delete_task(task2.task.id)
         pbclient.delete_app(app.app_id)
         
         data_mngr.delete_book(book_id="BLBLB")
    def test_04_init_and_close(self):
        # Creating new tt applications
        create_and_close_t1(self.app, "rpparaiba1918")
        time.sleep(40)
        pb_app = pbclient.find_app(short_name="rpparaiba1918_tt1")
        tasks_t1 = pbclient.get_tasks(pb_app[0].id, sys.maxint)

        for task in tasks_t1:
            self.assertTrue(task.state == "completed")

        pb_app = pbclient.find_app(short_name="rpparaiba1918_tt2")
        tasks_t2 = pbclient.get_tasks(pb_app[0].id, sys.maxint)
        self.assertTrue(len(tasks_t1) == len(tasks_t2))
    def test_02_init(self):
        # Creating new tt applications
        create_tt_apps(self.app, "rpparaiba1918")
        pb_app = pbclient.find_app(short_name="rpparaiba1918_tt1")

        # application is already created
        n_app_tasks = len(pbclient.get_tasks(pb_app[0].id, sys.maxint))
        rv = self.app.get("/api/rpparaiba1918/init")

        self.assertTrue(rv.data, "Error tt_app was not created")

        # if application is already created init cant duplicate the tasks
        self.assertEqual(n_app_tasks, len(pbclient.get_tasks(pb_app[0].id, sys.maxint)), "Error duplicated tasks")
    def setUp(self):
        bookinfo = dict(
            bookid="sh",
            title="title1",
            contributor="cont1",
            publisher="pub1",
            volume="1",
            img="http://archive.org/download/livro1/n1",
        )

        self.app = Apptt_select(short_name="sh_tt1", title="title1", book_info=bookinfo)
        self.app.add_task(
            task_info=dict(
                url_m="http://archive.org/download/livro1/n1", url_b="http://archive.org/download/livro1/n1", page=1
            )
        )
        self.app.add_task(
            task_info=dict(
                url_m="http://archive.org/download/livro1/n2", url_b="http://archive.org/download/livro1/n2", page=2
            )
        )

        tasks = pbclient.get_tasks(app_id=self.app.app_id)

        self.task1 = TTTask1(tasks[0].id, app_short_name=self.app.short_name)
        self.task2 = TTTask1(tasks[1].id, app_short_name=self.app.short_name)

        self.base_url = app_flask.config["PYBOSSA_URL"]
        self.fb_user = authenticate_fb_user(self.base_url)
 def setUp(self):
     book_title = "rpparaiba1918_title"
     self.app = Apptt_transcribe(short_name="rpparaiba1918_tt4", title=book_title)
     
     self.app.add_task(task_info=dict(confidences=[43, 57, 95, 54], 
                                      maxX=483, 
                                      maxY=399, 
                                      cells=[[0, 0, 34, 60], [34, 0, 227, 60], [227, 0, 300, 60], [300, 0, 374, 60]], 
                                      values=[".. 1\u00ed\u00c9\u00c9s.:n::l-A-l\u00ed\u00c9:\u00ed-", 
                                               ". IX/I\u00daJSTICI-FI\u00d4S", "", "\u00c0 numzno u\u00a1\\ ELEITIJRES"], 
                                      table_id=0, 
                                      img_url="http://localhost/mb-static/books/rpparaiba1918/metadados/tabelasBaixa/image85_0.png",
                                      page=85))
     
     self.app.add_task(task_info=dict(confidences=[43, 57, 95, 54], 
                                      maxX=483, 
                                      maxY=399, 
                                      cells=[[0, 0, 34, 60], [34, 0, 227, 60], [227, 0, 300, 60], [300, 0, 374, 60]], 
                                      values=[".. 1\u00ed\u00c9\u00c9s.:n::l-A-l\u00ed\u00c9:\u00ed-", 
                                               ". IX/I\u00daJSTICI-FI\u00d4S", "", "\u00c0 numzno u\u00a1\\ ELEITIJRES"], 
                                      table_id=0, 
                                      img_url="http://localhost/mb-static/books/rpparaiba1918/metadados/tabelasBaixa/image85_0.png",
                                      page=85))
     
     tasks = pbclient.get_tasks(app_id=self.app.app_id)
     
     self.task1 = TTTask4(tasks[0].id, app_short_name=self.app.short_name)
     self.task2 = TTTask4(tasks[1].id, app_short_name=self.app.short_name)
     
     self.base_url = app_flask.config['PYBOSSA_URL']
     self.fb_user = authenticate_fb_user(self.base_url)
 def setUp(self):
     book_title = "rpparaiba1918_title"
     self.app = Apptt_struct(short_name="rpparaiba1918_tt3", title=book_title)
     
     self.app.add_task(task_info=dict(
                                      hasZoom=False,
                                      zoom=[], 
                                      coords=[[0, 0, 7, 9], [7, 0, 37, 9], [37, 0, 118, 9], [118, 0, 251, 9], [251, 0, 489, 9], [0, 9, 7, 53], [7, 9, 37, 53], [37, 9, 118, 53], [118, 9, 251, 53], [251, 9, 489, 53], [0, 53, 7, 61], [7, 53, 37, 61], [37, 53, 118, 61], [118, 53, 251, 61], [251, 53, 489, 61], [0, 61, 7, 100], [7, 61, 37, 100], [37, 61, 118, 100], [118, 61, 251, 100], [251, 61, 489, 100], [0, 100, 7, 144], [7, 100, 37, 144], [37, 100, 118, 144], [118, 100, 251, 144], [251, 100, 489, 144], [0, 144, 7, 153], [7, 144, 37, 153], [37, 144, 118, 153], [118, 144, 251, 153], [251, 144, 489, 153], [0, 153, 7, 181], [7, 153, 37, 181], [37, 153, 118, 181], [118, 153, 251, 181], [251, 153, 489, 181], [0, 181, 7, 239], [7, 181, 37, 239], [37, 181, 118, 239], [118, 181, 251, 239], [251, 181, 489, 239], [0, 239, 7, 280], [7, 239, 37, 280], [37, 239, 118, 280], [118, 239, 251, 280], [251, 239, 489, 280], [0, 280, 7, 289], [7, 280, 37, 289], [37, 280, 118, 289], [118, 280, 251, 289], [251, 280, 489, 289], [0, 289, 7, 506], [7, 289, 37, 506], [37, 289, 118, 506], [118, 289, 251, 506], [251, 289, 489, 506]], 
                                      table_id=0, 
                                      img_url="http://localhost/mb-static/books/rpparaiba1918/metadados/tabelasBaixa/image1_0.png", 
                                      page=1
                                      )
                       )
     self.app.add_task(task_info=dict(
                                      hasZoom=False,
                                      zoom=[], 
                                      coords=[[0, 0, 7, 9], [7, 0, 37, 9], [37, 0, 118, 9], [118, 0, 251, 9], [251, 0, 489, 9], [0, 9, 7, 53], [7, 9, 37, 53], [37, 9, 118, 53], [118, 9, 251, 53], [251, 9, 489, 53], [0, 53, 7, 61], [7, 53, 37, 61], [37, 53, 118, 61], [118, 53, 251, 61], [251, 53, 489, 61], [0, 61, 7, 100], [7, 61, 37, 100], [37, 61, 118, 100], [118, 61, 251, 100], [251, 61, 489, 100], [0, 100, 7, 144], [7, 100, 37, 144], [37, 100, 118, 144], [118, 100, 251, 144], [251, 100, 489, 144], [0, 144, 7, 153], [7, 144, 37, 153], [37, 144, 118, 153], [118, 144, 251, 153], [251, 144, 489, 153], [0, 153, 7, 181], [7, 153, 37, 181], [37, 153, 118, 181], [118, 153, 251, 181], [251, 153, 489, 181], [0, 181, 7, 239], [7, 181, 37, 239], [37, 181, 118, 239], [118, 181, 251, 239], [251, 181, 489, 239], [0, 239, 7, 280], [7, 239, 37, 280], [37, 239, 118, 280], [118, 239, 251, 280], [251, 239, 489, 280], [0, 280, 7, 289], [7, 280, 37, 289], [37, 280, 118, 289], [118, 280, 251, 289], [251, 280, 489, 289], [0, 289, 7, 506], [7, 289, 37, 506], [37, 289, 118, 506], [118, 289, 251, 506], [251, 289, 489, 506]], 
                                      table_id=1, 
                                      img_url="http://localhost/mb-static/books/rpparaiba1918/metadados/tabelasBaixa/image1_1.png", 
                                      page=1
                                      )
                       )
     
     tasks = pbclient.get_tasks(app_id=self.app.app_id)
     
     self.task1 = TTTask3(tasks[0].id, app_short_name=self.app.short_name)
     self.task2 = TTTask3(tasks[1].id, app_short_name=self.app.short_name)
     
     self.base_url = app_flask.config['PYBOSSA_URL']
     self.fb_user = authenticate_fb_user(self.base_url)
 def test_05_mbdb_loading(self):
     # Creating new tt applications
     create_tt_apps(self.app, self.book_id)
     app_t1 = pbclient.find_app(short_name=self.book_id + "_tt1")
     self.assertTrue(len(app_t1) > 0, "Error tt_app was not created")
     
     # check if the book was created
     self.assertTrue(get_book(self.book_id))
     
     # check if the workflow transaction (T1) was created
     task_t1 = pbclient.get_tasks(app_t1[0].id, sys.maxint)[0]
     self.assertTrue(len(get_workflow_transaction()) == 74)
     
     workflow_transaction_info = dict(task_id_1=task_t1.id, task_id_2=None, task_id_3=None, task_id_4=None)
     self.assertTrue(get_workflow_transaction(workflow_transaction_info))
     
     task_t2 = create_t2_task(self, self.book_id, task_t1)
     
     # check if the workflow transaction (T2) was created
     workflow_transaction_info = dict(task_id_1=task_t1.id, task_id_2=task_t2.id, task_id_3=None, task_id_4=None)
     self.assertTrue(get_workflow_transaction(workflow_transaction_info))
     
     # check if the page was created
     page = get_page(self.book_id, task_t2.info['page'])
     self.assertTrue(page)
     
     tasks_t3 = create_t3_task(self, self.book_id, task_t2)
     
     # check if the workflow transactions (T3) were created
     workflow_transaction_info = dict(task_id_1=task_t1.id, task_id_2=task_t2.id, task_id_3=tasks_t3[0].id, task_id_4=None)
     self.assertTrue(get_workflow_transaction(workflow_transaction_info))
     workflow_transaction_info = dict(task_id_1=task_t1.id, task_id_2=task_t2.id, task_id_3=tasks_t3[1].id, task_id_4=None)
     self.assertTrue(get_workflow_transaction(workflow_transaction_info))
     
     # check if the page tables were created
     page_tables = get_page_table(self.book_id, page.id)
     self.assertTrue(len(page_tables) == 2)
     
     # check if the metadata was created
     self.assertTrue(get_metadata(page_tables[0].id))
     self.assertTrue(get_metadata(page_tables[1].id))
     
     tasks_t4 = create_t4_task(self, self.book_id, tasks_t3[0], 1)
     close_t4_task(self, self.book_id, tasks_t4[0])
     
     # check if the workflow transactions (T4) were created
     workflow_transaction_info = dict(task_id_1=task_t1.id, task_id_2=task_t2.id, task_id_3=tasks_t3[0].id, task_id_4=tasks_t4[0].id)
     self.assertTrue(get_workflow_transaction(workflow_transaction_info))
     
     tasks_t4 = create_t4_task(self, self.book_id, tasks_t3[1], 2)
     close_t4_task(self, self.book_id, tasks_t4[1])
     
     # check if the workflow transactions (T4) were created
     workflow_transaction_info = dict(task_id_1=task_t1.id, task_id_2=task_t2.id, task_id_3=tasks_t3[1].id, task_id_4=tasks_t4[1].id)
     self.assertTrue(get_workflow_transaction(workflow_transaction_info))
     
     # check if the cells were created
     self.assertTrue(len(get_cell(page_tables[0].id)) == 6)
     self.assertTrue(len(get_cell(page_tables[1].id)) == 6)
 def test_01_t2_creation(self):
     # Creating new tt applications
     create_tt_apps(self.app, self.book_id)
     app_t1 = pbclient.find_app(short_name=self.book_id + "_tt1")
     self.assertTrue(len(app_t1) > 0, "Error tt_app was not created")
     task_t1 = pbclient.get_tasks(app_t1[0].id, sys.maxint)[0]
     
     create_t2_task(self, self.book_id, task_t1)
def delete_workflow_transactions(book_id):
    app_t1 = pbclient.find_app(short_name=book_id + "_tt1")
    if len(app_t1) > 0:
        t1_tasks = pbclient.get_tasks(app_t1[0].id, sys.maxint)
        t1_ids = []

        for task in t1_tasks:
            t1_ids.append(task.id)
        return data_mngr.delete_workflow_transactions(t1_ids)
 def get_tasks(self):
     """
        Return tasks from this app
        
        :return list of tasks
        :rtype list
        
     """
     
     return pbclient.get_tasks(self.app_id, sys.maxint)
 def setUp(self):
     book_title = "rpparaiba1918_title"
     self.app = Apptt_meta(short_name="rpparaiba1918_tt2", title=book_title)
     self.app.add_task(task_info=dict(link="http://archive.org/download/livro1/n1", page=1))
     self.app.add_task(task_info=dict(link="http://archive.org/download/livro1/n2", page=2))
     
     tasks = pbclient.get_tasks(app_id=self.app.app_id)
     
     self.task1 = TTTask2(tasks[0].id, app_short_name=self.app.short_name)
     self.task2 = TTTask2(tasks[1].id, app_short_name=self.app.short_name)
     
     self.base_url = app_flask.config['PYBOSSA_URL']
     self.fb_user = authenticate_fb_user(self.base_url)
def get_tasks_progress(bookid):
    tt_suffix = ['tt1', 'tt2', 'tt3', 'tt4']
    result = dict(tt1=dict(total=0, completed=0), tt2=dict(total=0, completed=0), tt3=dict(total=0, completed=0), tt4=dict(total=0, completed=0))
    
    for suffix in tt_suffix:
        app = pbclient.find_app(short_name=str(bookid) + "_" + suffix)[0]
        tasks = pbclient.get_tasks(app.id, limit=max_limit)
        result[suffix]['total'] = len(tasks)
        
        for task in tasks:
            if task.state == 'completed':
                result[suffix]['completed'] += 1
                
    return result
    def test_get_task_01(self):
        self.app_tt_meta.add_task(task_info={"answer": "Yes", "page": 1})
        self.app_tt_meta.add_task(task_info={"answer": "Yes", "page": 2})
        self.app_tt_meta.add_task(task_info={"answer": "No", "page": 3})

        tasks = pbclient.get_tasks(self.app_tt_meta.app_id)

        try:
            for task in tasks:
                t2 = task_factory.get_task(task.id)
                if task.id == t2.task.id:
                    self.assertEquals(t2.task.info["page"], task.info["page"])
                    self.assertEquals(t2.task.info["answer"], task.info["answer"])
                    self.assertEquals(t2.app_short_name, self.app_tt_meta.short_name)

        except Exception as e:
            print e
            assert False
    def tearDown(self):
        next_app = None
        next_app_list = pbclient.find_app(short_name=self.app.short_name[:-1] + "2")

        if len(next_app_list) > 0:
            next_app = next_app_list[0]

            next_task = None
            tasks = pbclient.get_tasks(next_app.id)
            for t in tasks:
                if t.info["page"] == self.task1.task.info["page"]:
                    pbclient.delete_task(task_id=t.id)

            pbclient.delete_app(app_id=next_app.id)

        pbclient.delete_task(self.task1.task.id)
        pbclient.delete_task(self.task2.task.id)
        pbclient.delete_app(self.app.app_id)

        data_mngr.delete_book(self.task1.get_book_id())
def close_t4_task(test_case, book_id, task_t4):
    # creating an answer for the T4 app
    answer_t4 = '{\"cells\":[[0,0,239,54],[239,0,507,54],[0,54,239,103],[239,54,507,103],[0,103,239,178],[239,103,507,178]],\"computer_values\":[\"PARA\u00cdBA ( ESTADO )\",\"PRES IDENTE\",\"( FRANC|SCO CAM!\",\"\u00a1LLO DE HOLLANDA )\",\"MENSAGEM ..\u00c7 19\",\"DE SETEMBRO DE 1918.\"],\"human_values\":[\"PARA\u00cdBA ( ESTADO )\",\"PRES IDENTE\",\"( FRANC|SCO CAM!\",\"\u00a1LLO DE HOLLANDA )\",\"MENSAGEM ..\u00c7 19\",\"DE SETEMBRO DE 1918.\"],\"confidences\":[83,88,83,81,72,85],\"num_of_confirmations\":[2,2,2,2,2,2]}'
    task_run = dict(app_id=task_t4.app_id, task_id=task_t4.id, info=answer_t4)
    
    # Anonymous submission
    submit_answer(test_case.base_url, task_run)
    
    # FB authenticated user submission
    task_run['facebook_user_id'] = '12345'
    submit_answer(test_case.base_url, task_run)
    
    # Signalling the T3 task completion
    done_task(test_case.app, task_t4.id)
    time.sleep(1)
    
    # check if T4 task is closed
    tasks_t4 = pbclient.get_tasks(task_t4.app_id, sys.maxint)
    
    for task in tasks_t4:
        test_case.assertTrue(task.state == "completed")
 def __get_tasks(self):
     """
      Get tasks with self.app_id
     """
     
     return pbclient.get_tasks(self.task.app_id, sys.maxint)
 def test_add_next_task_03(self):
     """
        Invalid book
     """
     try:
         book_title = "BLABDL_title"
         app = Apptt_struct(short_name="BLABDL_tt3", title=book_title)
     
         app.add_task(task_info=dict(
                                          hasZoom=False,
                                          zoom=[0, 0, 489, 168], 
                                          coords=[[0, 0, 7, 9], [7, 0, 37, 9], [37, 0, 118, 9], [118, 0, 251, 9], [251, 0, 489, 9], [0, 9, 7, 53], [7, 9, 37, 53], [37, 9, 118, 53], [118, 9, 251, 53], [251, 9, 489, 53], [0, 53, 7, 61], [7, 53, 37, 61], [37, 53, 118, 61], [118, 53, 251, 61], [251, 53, 489, 61], [0, 61, 7, 100], [7, 61, 37, 100], [37, 61, 118, 100], [118, 61, 251, 100], [251, 61, 489, 100], [0, 100, 7, 144], [7, 100, 37, 144], [37, 100, 118, 144], [118, 100, 251, 144], [251, 100, 489, 144], [0, 144, 7, 153], [7, 144, 37, 153], [37, 144, 118, 153], [118, 144, 251, 153], [251, 144, 489, 153], [0, 153, 7, 181], [7, 153, 37, 181], [37, 153, 118, 181], [118, 153, 251, 181], [251, 153, 489, 181], [0, 181, 7, 239], [7, 181, 37, 239], [37, 181, 118, 239], [118, 181, 251, 239], [251, 181, 489, 239], [0, 239, 7, 280], [7, 239, 37, 280], [37, 239, 118, 280], [118, 239, 251, 280], [251, 239, 489, 280], [0, 280, 7, 289], [7, 280, 37, 289], [37, 280, 118, 289], [118, 280, 251, 289], [251, 280, 489, 289], [0, 289, 7, 506], [7, 289, 37, 506], [37, 289, 118, 506], [118, 289, 251, 506], [251, 289, 489, 506]], 
                                          table_id=0, 
                                          img_url="http://localhost/mb-static/books/BLABDL/metadados/tabelasBaixa/image2000_0.png", 
                                          page=1
                                          )
                           )
         app.add_task(task_info=dict(
                                          hasZoom=False,
                                          zoom=[0, 0, 489, 168], 
                                          coords=[[0, 0, 7, 9], [7, 0, 37, 9], [37, 0, 118, 9], [118, 0, 251, 9], [251, 0, 489, 9], [0, 9, 7, 53], [7, 9, 37, 53], [37, 9, 118, 53], [118, 9, 251, 53], [251, 9, 489, 53], [0, 53, 7, 61], [7, 53, 37, 61], [37, 53, 118, 61], [118, 53, 251, 61], [251, 53, 489, 61], [0, 61, 7, 100], [7, 61, 37, 100], [37, 61, 118, 100], [118, 61, 251, 100], [251, 61, 489, 100], [0, 100, 7, 144], [7, 100, 37, 144], [37, 100, 118, 144], [118, 100, 251, 144], [251, 100, 489, 144], [0, 144, 7, 153], [7, 144, 37, 153], [37, 144, 118, 153], [118, 144, 251, 153], [251, 144, 489, 153], [0, 153, 7, 181], [7, 153, 37, 181], [37, 153, 118, 181], [118, 153, 251, 181], [251, 153, 489, 181], [0, 181, 7, 239], [7, 181, 37, 239], [37, 181, 118, 239], [118, 181, 251, 239], [251, 181, 489, 239], [0, 239, 7, 280], [7, 239, 37, 280], [37, 239, 118, 280], [118, 239, 251, 280], [251, 239, 489, 280], [0, 280, 7, 289], [7, 280, 37, 289], [37, 280, 118, 289], [118, 280, 251, 289], [251, 280, 489, 289], [0, 289, 7, 506], [7, 289, 37, 506], [37, 289, 118, 506], [118, 289, 251, 506], [251, 289, 489, 506]], 
                                          table_id=1, 
                                          img_url="http://localhost/mb-static/books/BLABDL/metadados/tabelasBaixa/image2000_1.png", 
                                          page=1
                                          )
                           )
           
         tasks = pbclient.get_tasks(app_id=app.app_id)
           
         task1 = TTTask3(tasks[0].id, app_short_name=app.short_name)
         task2 = TTTask3(tasks[1].id, app_short_name=app.short_name)
           
         book_id = "BLABDL"
           
         task_run1 = dict(app_id=app.app_id, task_id=task1.task.id, info='{\"img_url\":\"https://localhost/mb-static/books/BLABDL/metadados/tabelasBaixa/image2000_0.png\",\"linhas\":[[0,0,507,0],[0,54,507,54],[0,103,507,103],[0,178,507,178]],\"colunas\":[[0,0,0,178],[239,0,239,178],[507,0,507,178]],\"maxX\":507,\"maxY\":178}')
         task_run2 = dict(app_id=app.app_id, task_id=task1.task.id, info='{\"img_url\":\"https://localhost/mb-static/books/BLABDL/metadados/tabelasBaixa/image2000_1.png\",\"linhas\":[[0,0,507,0],[0,54,507,54],[0,103,507,103],[0,178,507,178]],\"colunas\":[[0,0,0,178],[239,0,239,178],[507,0,507,178]],\"maxX\":507,\"maxY\":178}')
     
         # Anonymous submission
         submit_answer(self.base_url, task_run1)
             
         # FB authenticated user submission
         task_run2['facebook_user_id'] = '12345'
         submit_answer(self.base_url, task_run2)
             
         time.sleep(2)
             
         self.assertTrue(task1.check_answer())
            
         task1.add_next_task()
          
         assert False   
      
     except Meb_exception_tt3 as e:
         self.assertEquals(e.code, 5)
      
     finally:
         next_app = None 
         next_app_list = pbclient.find_app(short_name=app.short_name[:-1] + "4")
          
         if len(next_app_list) > 0:
             next_app = next_app_list[0]
          
             next_task = None
             tasks = pbclient.get_tasks(next_app.id)
             for t in tasks:
                 if t.info["img_url"] == task1.task.info["img_url"]: 
                     pbclient.delete_task(task_id=t.id)
       
             pbclient.delete_app(app_id=next_app.id)
          
         pbclient.delete_task(task1.task.id)
         pbclient.delete_task(task2.task.id)
         pbclient.delete_app(app.app_id)
          
         data_mngr.delete_book(book_id="BLABDL")