def test_get_not_neighbours(self): n1 = Server('n1', port=8000, id='22cd859d-ee91-4079-a112-000000000001') n2 = Server('n2', port=8000, id='22cd859d-ee91-4079-a112-000000000002') n3 = Server('n3', port=8000, id='22cd859d-ee91-4079-a112-000000000003') n3.route = None r1 = Server('r1', port=8000, id='22cd859d-ee91-4079-a112-000000000011') Route(destination=n1, cost=0) Route(destination=n2, proxy_server_or_gate=n2.gates[0]) Route(destination=r1, proxy_server_or_gate=n1, cost=1) me = Server('me', port=8000, me=True) db.session.add_all([n1, n2, n3, r1, me]) self.assertListEqual([n3, r1], me.get_not_neighbours())
def test_sqlalchemy_entity_events_server(self, mock_now): mock_now.return_value = dt.datetime(2019, 4, 1, tzinfo=dt.timezone.utc) s = Server('source', port=5000) d = Server('destination', port=5000) db.session.add_all([s, d]) db.session.commit() mock_now.return_value = dt.datetime(2019, 4, 2, tzinfo=dt.timezone.utc) s.route = Route(destination=d, proxy_server_or_gate=d.gates[0], cost=0) db.session.commit() self.assertEqual(dt.datetime(2019, 4, 1, tzinfo=dt.timezone.utc), s.last_modified_at) g = s.add_new_gate(dns_or_ip='dns', port=5000) db.session.add(g) db.session.commit() self.assertEqual(dt.datetime(2019, 4, 1, tzinfo=dt.timezone.utc), s.last_modified_at)
def test_get_reachable_servers(self): n1 = Server('n1', port=8000, id='22cd859d-ee91-4079-a112-000000000001') n2 = Server('n2', port=8000, id='22cd859d-ee91-4079-a112-000000000002') n3 = Server('n3', port=8000, id='22cd859d-ee91-4079-a112-000000000003') n3.route = None n4 = Server('n4', port=8000, id='22cd859d-ee91-4079-a112-000000000004') r1 = Server('r1', port=8000, id='22cd859d-ee91-4079-a112-000000000011') Route(destination=n1, cost=0) Route(destination=n2, proxy_server_or_gate=n2.gates[0]) Route(destination=n4) Route(destination=r1, proxy_server_or_gate=n1, cost=1) me = Server('me', port=8000, me=True) db.session.add_all([n1, n2, n3, n4, r1, me]) self.assertListEqual([n1, n2, r1], me.get_reachable_servers()) self.assertListEqual([n2, r1], me.get_reachable_servers(exclude=n1)) self.assertListEqual([n2, r1], me.get_reachable_servers(exclude=n1.id)) self.assertListEqual([r1], me.get_reachable_servers(exclude=[n1.id, n2]))