Example #1
0
 def test_write_db(self):
     init_stat(self.cur)
     date = datetime.now()
     name = u'test'
     r = set_stat(self.cur, date, name)
     self.assertTrue(r)
     self.con.commit()
     r = self.cur.execute('select date,name,cnt from visits where name=:name', {'date': date.strftime('%Y-%m-%d'), 'name': name}).fetchone()
     self.assertEqual(r, (date.strftime('%Y-%m-%d'), name, 1))
Example #2
0
 def setUp(self):
     self.con = connect_db(config.TEST_DATABASE_URI)
     self.assertIsInstance(self.con, sqlite3.Connection)
     self.cur = self.con.cursor()
     self.assertIsInstance(self.cur, sqlite3.Cursor)
     r = init_stat(self.cur)
     self.assertTrue(r)
Example #3
0
 def test_csv(self):
     init_stat(self.cur)
     rows = get_data(config.TEST_FTP_URI)
     logs = {}
     cnt = 0
     for row in rows:
         cnt += 1
         self.assertIsInstance(row[0], datetime)
         self.assertIsInstance(row[1], str)
         logs[row[1]] = row[0]
         if cnt == 3:
             self.assertFalse(check_passwd(row[2]))
         else:
             self.assertTrue(check_passwd(row[2]))
     save_log(logs, config.TEST_LOG)
     with open(config.TEST_LOG) as f:
         x = f.read()
         self.assertEqual(x, 'user2\nuser3\nuser1')
     f.closed
Example #4
0
    for row in rows:
        set_stat(cur, row[0], row[1])
        if not check_passwd(row[2]):
            logs[row[1]] = row[0]
    save_log(logs)


if __name__ == '__main__':
    start = timer()

    try:
        parser = argparse.ArgumentParser(description='Check user data.')
        parser.add_argument('--stats', action='store_true', help='show stats')
        args = parser.parse_args()

        con = connect_db()
        cur = con.cursor()
        if args.stats:
            stats = get_stats(cur)
            for stat in stats:
                print(stat[0], stat[1])
            con.close()
        else:
            init_stat(cur)
            main(cur)
            con.commit()
    except KeyboardInterrupt:
        print("Import data interrupted", file=sys.stderr)
    end = timer()
    print ("Execution time:", end - start)