Exemplo n.º 1
0
    def setUp(self):
        ''' your setup code here
        '''
        # use your test database
        self.db = SimpleDB(os.path.join(os.getcwd(), 'test.db'))

        # get eternity data
        with open(os.path.join(os.getcwd()), 'test_eternity.csv') as f:
            headers = ('day','start_time','stop_time',
                       'duration', 'parent','activity','note','tags')
            d = remove_duplicates([tuple(x) for x in unicode_csv_reader(f)])
            self.eternity_data = tablib.Dataset(*d, headers=headers)
            del(d)

        # get GPS csv data
        with open(os.path.join(os.getcwd()), 'test_gps.csv') as f:
            headers = ('latitude','longitude','elevation','timestamp')
            d = remove_duplicates([tuple(x) for x in unicode_csv_reader(f)])
            self.gps_data = tablib.Dataset(*d, headers=headers)
        'test_gps.csv'
Exemplo n.º 2
0
class MylifeTest(unittest.TestCase):

    def setUp(self):
        ''' your setup code here
        '''
        # use your test database
        self.db = SimpleDB(os.path.join(os.getcwd(), 'test.db'))

        # get eternity data
        with open(os.path.join(os.getcwd()), 'test_eternity.csv') as f:
            headers = ('day','start_time','stop_time',
                       'duration', 'parent','activity','note','tags')
            d = remove_duplicates([tuple(x) for x in unicode_csv_reader(f)])
            self.eternity_data = tablib.Dataset(*d, headers=headers)
            del(d)

        # get GPS csv data
        with open(os.path.join(os.getcwd()), 'test_gps.csv') as f:
            headers = ('latitude','longitude','elevation','timestamp')
            d = remove_duplicates([tuple(x) for x in unicode_csv_reader(f)])
            self.gps_data = tablib.Dataset(*d, headers=headers)
        'test_gps.csv'


    def test_is_duplicate(self):
        ''' Test to see if the duplicate data detection is working
        TODO: rig the data so that duplicate data should be detected
              right now your testing to see if there are no duplicates,
              and if a dupe is found then your test fails.
        '''
        # replacement dicts
        parent_dict = {
            u'Media>':                        u'MEDIA',
            u'MISC - Real Life>':             u'REAL_LIFE',
            u'Basic Routine>Meals & Snacks>': u'BASIC',
            u'Basic Routine>':                u'BASIC',
            u'Salubrious Living>':            u'HEALTH',
        }
        activity_dict = {
            u'RL - MISC - Home':    u'HOME',
            u'RL - MISC - Outside': u'OUTSIDE',
            u'へんたい':              u'HENTAI',
            u'アニメ':               u'ANIME',
            u'Grocery Shopping':    u'GROCERY-SHOPPING',
            u'Restaurant':          u'RESTAURANT',
            u'Shower & Bathroom':   u'SHOWER-BATHROOM'
        }

        # test for duplicates in data (skip over the first row to avoid headers)
        for row in self.eternity_data.dict[1:]:
            # replace the Eternity data with your formatting
            row['parent']   = replace_txt(row['parent'], parent_dict)
            row['activity'] = replace_txt(row['activity'], activity_dict)

            # check to see if the row is already in the database
            sql = self.db.is_duplicate('logs', row)

            self.assertIsNotNone(sql)

            # if it's not a duplicate, insert it into DB
            #if sql:
            #    self.db.query(sql)

        # check to make sure it works on the location table too
        for row in self.gps_data.dict[1:]:
            sql = self.db.is_duplicate('location', row)
            # if its not a duplicate, insert it into DB
            self.assertISNotNone(sql)