def test_domains_sync_from_resolver(self): domains = { 'test.ru': { 'ips' : [ '1.1.1.1', ], 'urls' : [], }, 'ya.ru': { 'ips' : [ '3.3.3.3', ], 'urls' : [], }, 'r1.com': { 'ips': [ '5.5.5.5', ], 'urls': [], }, } Domain.sync_from_rkn(Session, domains) domains_resolver = { 'test.ru': { 'ips' : [ '1.1.1.1', '2.2.2.2', ], }, 'ya.ru': { 'ips' : [ '8.8.8.8', ], }, 'r1.com': { 'ips': [ '5.5.5.5', ], 'urls': [], }, } Domain.sync_from_resolver(Session, domains_resolver) ips_rkn = [ '3.3.3.3', ] ips_resolver = [ '2.2.2.2', '8.8.8.8', ] ips_rkn_resolver = [ '1.1.1.1', '5.5.5.5', ] self.assert_ips_from_rkn(ips_rkn) self.assert_ips_from_resolver(ips_resolver) self.assert_ips_from_all(ips_rkn_resolver) for i in domains: d = Session.query(Domain).filter(Domain.domain==i).one() self.assertEqual(sorted(d.ips_list), sorted(set(domains[i]['ips']+domains_resolver[i]['ips']))) domains_resolver = { 'test.ru': { 'ips' : [ '1.1.1.1', ], }, 'ya.ru': { 'ips' : [ '8.8.8.8', ], }, 'r1.com': { 'ips': [ '5.5.5.5', '2.2.2.2', ], }, } Domain.sync_from_resolver(Session, domains_resolver) ips_rkn = [ '3.3.3.3', ] ips_resolver = [ '2.2.2.2', '8.8.8.8', ] ips_rkn_resolver = [ '1.1.1.1', '5.5.5.5', ] self.assert_ips_from_rkn(ips_rkn) self.assert_ips_from_resolver(ips_resolver) self.assert_ips_from_all(ips_rkn_resolver) for i in domains: d = Session.query(Domain).filter(Domain.domain==i).one() self.assertEqual(sorted(d.ips_list), sorted(set(domains[i]['ips']+domains_resolver[i]['ips'])))
def sync_and_assert(domains): Domain.sync_from_rkn(Session, domains) self.assert_domains_from_rkn(domains)