def test_add_bite(self):
     table_name = "volleyball_single"
     table_col = 0
     data = {'table': table_name, 'subject_col_id': table_col, 'slice': 0, 'total': 1, 'technique': 'found-majority'}
     Bite.delete().execute()  # delete all Bites
     Apple.delete().execute()  # delete all Apples
     result = self.app.post('/add', data=data, content_type='multipart/form-data')
     self.assertIn('apple', result.json)
     apple_id = result.json['apple']
     self.assertEqual(result.status_code, 200, msg=result.data)
     database.connect(reuse_if_open=True)
     self.assertEqual(len(Bite.select()), 1)
     sleep(sleep_time)
     result = self.app.get('/status')
     self.assertEqual(result.status_code, 200, msg=result.data)
     self.assertTrue(result.is_json)
     j = {
         "apples": [
             {
                 "apple": table_name,
                 "status": STATUS_COMPLETE,
                 "complete": True,
                 "agreement": 1.0,
                 "elected": 0,
             }
         ]
     }
     self.assertEqual(elect(apple_id, 'majority'), None)  # just for the coverage
     self.assertEqual(elect(apple_id, 'found-majority'), None)  # just for the coverage
 def test_add_multiple_bite(self):
     table_name = "volleyball_double"
     table_col = 0
     data = {'table': table_name, 'subject_col_id': table_col, 'slice': 0, 'total': 2, 'technique': 'majority'}
     Bite.delete().execute()  # delete all Bites
     Apple.delete().execute()  # delete all Apples
     result = self.app.post('/add', data=data, content_type='multipart/form-data')
     self.assertEqual(result.status_code, 200, msg=result.data)
     database.connect(reuse_if_open=True)
     self.assertEqual(len(Bite.select()), 1)
     sleep(sleep_time)
     result = self.app.get('/status')
     self.assertEqual(result.status_code, 200, msg=result.data)
     self.assertTrue(result.is_json)
     j = {
         "apples": [
             {
                 "apple": table_name,
                 "status": STATUS_NEW,
                 "complete": False,
                 "elected": None,
                 "agreement": None,
             }
         ]
     }
     self.assertDictEqual(result.get_json(), j)
     data = {'table': table_name, 'subject_col_id': table_col, 'slice': 1, 'total': 2, 'technique': 'majority'}
     result = self.app.post('/add', data=data, content_type='multipart/form-data')
     self.assertEqual(result.status_code, 200, msg=result.data)
     database.connect(reuse_if_open=True)
     self.assertEqual(len(Bite.select()), 2)
     sleep(sleep_time)
     result = self.app.get('/status')
     self.assertEqual(result.status_code, 200, msg=result.data)
     self.assertTrue(result.is_json)
     j = {
         "apples": [
             {
                 "apple": table_name,
                 "status": STATUS_COMPLETE,
                 "complete": True,
                 "agreement": 1.0,
                 "elected": table_col,
             }
         ]
     }
Esempio n. 3
0
 def test_score_with_extra_space(self):
     table_name = 'players'
     players = ["Anouer Taouerghi\n"]
     content = "\t".join(players)
     data = {'table': table_name, 'column': 0, 'slice': 0, 'total': 1, 'addr': ''}
     data['file_slice'] = (StringIO(content), "players.csv")
     Bite.delete().execute()  # delete all instances
     print("after deletiong: "+str(len(Bite.select())))
     result = self.app.post('/score', data=data, content_type='multipart/form-data')
     database.connect(reuse_if_open=True)
     self.assertEqual(result.status_code, 200)
     bites = Bite.select().where(Bite.table==table_name, Bite.column==0)
     self.assertEqual(len(bites), 1)
     data_dir = os.path.join(DATA_DIR, bites[0].fname)
     print("data_dir: "+data_dir)
     data_file_exists = os.path.isfile(data_dir)
     self.assertTrue(data_file_exists, msg="The data file is not found")
     annotated_cells = {"data":
                            {
                                'Anouer Taouerghi': {u'http://dbpedia.org/resource/Anouer_Taouerghi': [
                                u'http://dbpedia.org/ontology/Person',
                                u'http://dbpedia.org/ontology/Agent',
                                u'http://dbpedia.org/ontology/Athlete',
                                u'http://dbpedia.org/ontology/VolleyballPlayer']},
                            }
                        }
     f = open(data_dir)
     computed_data = json.load(f)
     self.assertDictEqual(annotated_cells, computed_data)
     bite = Bite.select()[0]
     graph_file_name = graph_fname_from_bite(bite)
     graph_file_dir = os.path.join(UPLOAD_DIR, graph_file_name)
     tgraph = type_graph.TypeGraph()
     tgraph.load_from_file(graph_file_dir)
     tgraph.set_score_for_graph(coverage_weight=0.1, m=1, fsid=3)
     results = [n for n in tgraph.get_scores()]
     results.sort(key=lambda node: node.path_specificity)
     self.assertEqual(results[0].title, "http://dbpedia.org/ontology/VolleyballPlayer")
     self.assertEqual(bite.status, "complete")