def test_rset(self): """External resources: prefixes from AS-SET via bgpq3""" rset = RSet(["AS-RIPENCC"], 4, False, bgpq3_path="bgpq3", **cache_cfg) rset.load_data() self.assertTrue(len(rset.prefixes) > 0) self.assertTrue( any([p for p in rset.prefixes if p["prefix"] == "193.0.0.0"]))
def setup_obj(self, object_names, allow_longer_prefixes=False, cache_expiry=10): self.obj = RSet(object_names, 4, allow_longer_prefixes, cache_dir=self.temp_dir, cache_expiry=cache_expiry, bgpq3_path="false")
class TestIRRDBInfo_RSet(TestIRRDBInfo_Base): __test__ = True def setup_obj(self, object_names, allow_longer_prefixes=False, cache_expiry=10): self.obj = RSet( object_names, 4, allow_longer_prefixes, cache_dir=self.temp_dir, cache_expiry=cache_expiry, bgpq3_path="false" ) @mock.patch.object(RSet, "_run_cmd", return_value=load("rset_test_10.json")) def test_010_simple(self, run_cmd): """IRRDB info: RSets, simple""" exp_res = json.loads(load("rset_test_10.expected.json").decode("utf-8")) self.setup_obj(["AS-ONE"]) self.obj.load_data() self.assertEqual(self.obj.prefixes, exp_res) self.file_exists("AS_ONE-r_set-ipv4.json") run_cmd.assert_called_once() @mock.patch.object(RSet, "_run_cmd", return_value=load("rset_test_10.json")) def test_011_from_cache(self, run_cmd): """IRRDB info: RSets, from cache""" exp_res = json.loads(load("rset_test_10.expected.json").decode("utf-8")) for i in [1, 2]: self.setup_obj(["AS-ONE"]) self.obj.load_data() self.assertEqual(self.obj.prefixes, exp_res) self.file_exists("AS_ONE-r_set-ipv4.json") run_cmd.assert_called_once() @mock.patch.object(RSet, "_run_cmd", return_value=load("rset_test_10.json")) def test_012_cache_expired(self, run_cmd): """IRRDB info: RSets, cache expired""" exp_res = json.loads(load("rset_test_10.expected.json").decode("utf-8")) for i in [1, 2]: self.setup_obj(["AS-ONE"], cache_expiry=1) self.obj.load_data() self.assertEqual(self.obj.prefixes, exp_res) self.file_exists("AS_ONE-r_set-ipv4.json") if i == 1: run_cmd.assert_called_once() time.sleep(1) else: self.assertEqual(run_cmd.call_count, 2)