def test_from_db(self): tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo2") limits = tcxparser.get_limits_from_db('bar') expected_results = {u'test_9trackpoints': {'start': 2, 'end': 6}, u'test_all_trackpoints': {'start': 900, 'end': 1500}} self.assertEqual(limits,expected_results) tcxparser.process_files(summation_type="avg",limits=limits,bucket_size=2) tcxparser.persist() database = Database('foo',True) with database: _,rows,_ = tbl_query(database,'select watts from foo2 where filename=\"test_9trackpoints\"') self.assertListEqual(rows,self.wattsavg_points)
class TestTcxParserPersistWithLimits(unittest.TestCase): def setUp(self): self.test_file_name = "test_9trackpoints.tcx" self.test_file_name2 = "test_all_trackpoints.tcx" row = _quotestrs([["00:02","00:06","test_9trackpoints","foo_title","z2"], ["15:00","25:00","test_all_trackpoints","foo2_title","z2"]]) self.dtr_tcx = DownloadTrainerRoadTcx() self.dtr_tcx._write_to_db(row,'foo', 'bar',DB_COLUMN_DEFN,DB_COLUMN_NAMES) self.tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo") limits = self.tcxparser.get_limits_from_db('bar') self.tcxparser.process_files(summation_type="avg",bucket_size=3,limits=limits) def test(self): self.tcxparser.persist(self.test_file_name2) database = Database('foo',True) with database: _,rows,_ = tbl_query(database,'select count(*) from foo where filename=\"'+os.path.splitext(self.test_file_name2)[0]+'\"') self.assertEqual(200,rows[0][0])
class TestTcxParserPersist(unittest.TestCase): def setUp(self): self.test_file_name = "test_9trackpoints.tcx" self.test_file_name2 = "test_all_trackpoints.tcx" self.expected_results = [[0,0, 264, 91, u'test_9trackpoints'], [1,1, 275, 92, u'test_9trackpoints'], [2,2, 280, 94, u'test_9trackpoints']] self.tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo") self.tcxparser.process_files(summation_type="avg",bucket_size=3) def test_1file_no_limits(self): self.tcxparser.persist(self.test_file_name) database = Database('foo',True) with database: _,rows,_ = tbl_rows_get(database,'foo') self.assertListEqual(self.expected_results,rows) def test_1file_no_limits_fail_to_write_to_db(self): self.tcxparser.persist(self.test_file_name, column_names =["id","foobar","watts","hr","filename"]) database = Database('foo',True) with database: _,rows,_ = tbl_rows_get(database,'foo') self.assertListEqual([],rows) def test_2files(self): self.tcxparser.persist(self.test_file_name) self.tcxparser.persist(self.test_file_name2) database = Database('foo',True) with database: _,rows,_ = tbl_query(database,'select count(*) from foo where filename=\"'+os.path.splitext(self.test_file_name2)[0]+'\"') self.assertEqual(1238,rows[0][0])