def statistics_updates_by_fqdn(): db = UpdatesDB() out = [] for fqdn in db.get_fqdns(): rows = db.get_updates_by_fqdn(fqdn) table = flask.render_template('table-updates-by-fqdn.html', fqdn=fqdn, rows=rows) out.append(table) return template_base('Updates by FQDN', '\n'.join(out))
def statistics_latest_submissions(): db = UpdatesDB() results = [] db.cursor.execute('SELECT * FROM updates ORDER BY update_time DESC ' 'LIMIT 50;') rows = db.cursor.fetchall() for row in rows: results.append(db.normalize_row(row)) content = flask.render_template('table-latest-submissions.html', rows=results) return template_base('Latest submissions', content)
def get_updates_db(): db = UpdatesDB() arguments_list = ( (True, 'c.example.com', 'a', '1.2.3.4'), (False, 'c.example.com', 'a', '1.2.3.4'), (True, 'c.example.com', 'a', '2.2.3.4'), (True, 'c.example.com', 'a', '3.2.3.4'), (True, 'c.example.com', 'aaaa', '1::2'), (True, 'c.example.com', 'aaaa', '1::3'), (True, 'b.example.com', 'a', '1.2.3.4'), (False, 'b.example.com', 'a', '1.2.3.4'), (True, 'a.example.com', 'a', '1.2.3.4'), (True, 'a.example.com', 'a', '1.2.3.3'), (True, 'a.example.com', 'a', '1.2.3.2'), (False, 'a.example.com', 'a', '1.2.3.2'), ) for arguments in arguments_list: db.log_update(*arguments) return db
def test_method_log_update(self): db = UpdatesDB() db.log_update(True, 'www.example.com', 'a', '1.2.3.4') db.cursor.execute('SELECT * FROM updates;') rows = db.cursor.fetchall() row = rows[0] dt = DateTime(row[0]) self.assertEqual(dt.datetime.year, datetime.datetime.now().year) self.assertEqual(row[1], 1) self.assertEqual(row[2], 'www.example.com') self.assertEqual(row[3], 'a') self.assertEqual(row[4], '1.2.3.4') db.cursor.execute('SELECT fqdn FROM fqdns;') row = db.cursor.fetchone() self.assertEqual(row[0], 'www.example.com') # Add second entry db.log_update(True, 'www.example.com', 'a', '1.2.3.4') # fqdn gets entered only one time db.cursor.execute('SELECT fqdn FROM fqdns;') rows = db.cursor.fetchall() self.assertEqual(len(rows), 1) db.cursor.execute('SELECT * FROM updates;') rows = db.cursor.fetchall() self.assertEqual(len(rows), 2)
def __init__(self, nameserver, names, ipaddresses=None, ttl=None): self.nameserver = nameserver #: The nameserver self.names = names self.ipaddresses = ipaddresses self.ttl = ttl if not self.ttl: self.ttl = 300 else: self.ttl = int(ttl) self._tsigkeyring = self._build_tsigkeyring( self.names.zone_name, self.names.tsig_key, ) self._dns_update = dns.update.Update(self.names.zone_name, keyring=self._tsigkeyring) self._updates_db = UpdatesDB() self.log_update = self._updates_db.log_update
def test_method_is_fqdn_stored(self): db = UpdatesDB() self.assertFalse(db._is_fqdn_stored('example.com')) db.log_update(True, 'example.com', 'a', '1.2.3.2') self.assertTrue(db._is_fqdn_stored('example.com'))
def test_init(self): db = UpdatesDB() self.assertTrue(db.db_file)