def test_is_allowed_for_calls_is_allowed_if_defined(self): is_allowed = unittest.mock.Mock() cn = adhoc_service.CommandEntry( "foo", unittest.mock.sentinel.handler, is_allowed=is_allowed, ) result = cn.is_allowed_for( unittest.mock.sentinel.a, unittest.mock.sentinel.b, x=unittest.mock.sentinel.x, ) is_allowed.assert_called_once_with( unittest.mock.sentinel.a, unittest.mock.sentinel.b, x=unittest.mock.sentinel.x, ) self.assertEqual( result, is_allowed(), )
def test_defaults(self): stanza = unittest.mock.Mock() cn = adhoc_service.CommandEntry("foo", unittest.mock.sentinel.handler, features={}) self.assertDictEqual(cn.name, { None: "foo", }) self.assertIsInstance( cn.name, aioxmpp.structs.LanguageMap, ) self.assertEqual(cn.handler, unittest.mock.sentinel.handler) self.assertIn(("automation", "command-node", None, "foo"), list(cn.iter_identities(stanza))) self.assertCountEqual( { namespaces.xep0030_info, namespaces.xep0050_commands, }, cn.iter_features(unittest.mock.sentinel.stanza)) self.assertIsNone(cn.is_allowed) self.assertTrue(cn.is_allowed_for(unittest.mock.sentinel.jid))
def test_is_allowed_inhibits_identities_response(self): stanza = unittest.mock.Mock() is_allowed = unittest.mock.Mock() is_allowed.return_value = False cn = adhoc_service.CommandEntry("foo", unittest.mock.sentinel.handler, features={}, is_allowed=is_allowed) self.assertSequenceEqual([], list(cn.iter_identities(stanza))) is_allowed.assert_called_once_with(stanza.from_, ) is_allowed.reset_mock() is_allowed.return_value = True self.assertIn(("automation", "command-node", None, "foo"), list(cn.iter_identities(stanza)))