def test_no_incompatible_ospf_sessions_no_session(): """Confirm no-incompatible-ospf-sessions assert passes and fails as expected when not specifying a session.""" with patch.object(bfq, "ospfSessionCompatibility", create=True) as ospfSessionCompatibility: # Test success ospfSessionCompatibility.return_value = MockQuestion() assert_no_incompatible_ospf_sessions(nodes="nodes", remote_nodes="remote_nodes") ospfSessionCompatibility.assert_called_with( nodes="nodes", remote_nodes="remote_nodes", statuses=UNESTABLISHED_OSPF_SESSION_STATUS_SPEC, ) # Test failure mock_df = DataFrame.from_records([{ "Session": "found", "More": "data" }]) ospfSessionCompatibility.return_value = MockQuestion( MockTableAnswer(mock_df)) with pytest.raises(BatfishAssertException) as excinfo: assert_no_incompatible_ospf_sessions(nodes="nodes", remote_nodes="remote_nodes") # Ensure found answer is printed assert mock_df.to_string() in str(excinfo.value) ospfSessionCompatibility.assert_called_with( nodes="nodes", remote_nodes="remote_nodes", statuses=UNESTABLISHED_OSPF_SESSION_STATUS_SPEC, )
def assert_no_incompatible_ospf_sessions(self, nodes=None, remote_nodes=None, snapshot=None, soft=False, df_format="table"): # type: (Optional[str], Optional[str], Optional[str], bool, str) -> bool """Assert that there are no incompatible or unestablished OSPF sessions present in the snapshot. :param nodes: search sessions with specified nodes on one side of the sessions. :param remote_nodes: search sessions with specified remote_nodes on other side of the sessions. :param snapshot: the snapshot on which to check the assertion :param soft: whether this assertion is soft (i.e., generates a warning but not a failure) :param df_format: How to format the Dataframe content in the output message. Valid options are 'table' and 'records' (each row is a key-value pairs). """ return assert_no_incompatible_ospf_sessions(nodes, remote_nodes, snapshot, soft, self.session, df_format)