def test_wrong_type(self): """Assert a useful message is provided if bindings isn't a list or tuple""" with self.assertRaises(ConfigurationException) as cm: msg_config.validate_bindings(TestObj()) self.assertEqual( "Configuration error: bindings must be a list or tuple of dictionaries, " "but was a <class 'fedora_messaging.tests.unit.test_config.TestObj'>", str(cm.exception), )
def test_missing_keys(self): """Assert a useful message is provided if "queue" is missing from the config.""" bindings = [{}] with self.assertRaises(ConfigurationException) as cm: msg_config.validate_bindings(bindings) self.assertIn( "Configuration error: a binding is missing the following keys", str(cm.exception), ) self.assertIn("queue", str(cm.exception)) self.assertIn("exchange", str(cm.exception)) self.assertIn("routing_keys", str(cm.exception))
def test_routing_key_str(self): """Assert a useful message is provided if "routing_keys" is not a list or tuple.""" bindings = [{ "exchange": "e1", "queue": "q1", "routing_keys": TestObj() }] with self.assertRaises(ConfigurationException) as cm: msg_config.validate_bindings(bindings) self.assertEqual( "Configuration error: routing_keys must be a list or tuple, but was a " "<class 'fedora_messaging.tests.unit.test_config.TestObj'>", str(cm.exception), )
def test_valid(self): """Assert no exceptions are raised if the bindings are valid.""" bindings = [ { "queue": "q1", "exchange": "e1", "routing_keys": ["#"] }, { "queue": "q2", "exchange": "e2", "routing_keys": ("#", ) }, ] msg_config.validate_bindings(bindings)