def test_condition_reflects_enum_member_of_object_after_init(self): e = nonza.StreamError() self.assertEqual( errors.StreamErrorCondition.UNDEFINED_CONDITION, e.condition, )
def test_default_init(self): obj = nonza.StreamError() self.assertEqual( (namespaces.streams, "undefined-condition"), obj.condition ) self.assertIsNone(obj.text)
def test_init(self): obj = nonza.StreamError(condition=errors.StreamErrorCondition.RESET, text="foobar") self.assertEqual(errors.StreamErrorCondition.RESET, obj.condition) self.assertEqual("foobar", obj.text)
def test_default_init(self): obj = nonza.StreamError() self.assertEqual(errors.StreamErrorCondition.UNDEFINED_CONDITION, obj.condition) self.assertIsNone(obj.text)
def test_condition_reflects_enum_member_of_object_after_change(self): e = nonza.StreamError() e.condition_obj = errors.StreamErrorCondition.HOST_GONE.xso_class() self.assertEqual( errors.StreamErrorCondition.HOST_GONE, e.condition, )
def test_to_exception(self): obj = nonza.StreamError() obj.condition = (namespaces.streams, "restricted-xml") obj.text = "foobar" exc = obj.to_exception() self.assertIsInstance(exc, errors.StreamError) self.assertEqual((namespaces.streams, "restricted-xml"), exc.condition) self.assertEqual("foobar", exc.text)
def test_setting_condition_replaces_object(self): e = nonza.StreamError() e.condition = errors.StreamErrorCondition.UNDEFINED_CONDITION self.assertEqual(e.condition, errors.StreamErrorCondition.UNDEFINED_CONDITION) self.assertIsInstance( e.condition_obj, errors.StreamErrorCondition.UNDEFINED_CONDITION.xso_class, )
def test_init(self): obj = nonza.StreamError( condition=(namespaces.streams, "reset"), text="foobar" ) self.assertEqual( (namespaces.streams, "reset"), obj.condition ) self.assertEqual( "foobar", obj.text )
def test_to_exception(self): obj = nonza.StreamError() obj.condition = errors.StreamErrorCondition.RESTRICTED_XML obj.text = "foobar" exc = obj.to_exception() self.assertIsInstance(exc, errors.StreamError) self.assertEqual(errors.StreamErrorCondition.RESTRICTED_XML, exc.condition) self.assertEqual("foobar", exc.text)
def test_init_works_with_tuple_and_warns(self): with self.assertWarnsRegex( DeprecationWarning, r"as of aioxmpp 1\.0, stream error conditions must be members " r"of the aioxmpp\.errors\.StreamErrorCondition " r"enumeration") as ctx: e = nonza.StreamError( errors.StreamErrorCondition.INTERNAL_SERVER_ERROR.value) self.assertEqual( e.condition, errors.StreamErrorCondition.INTERNAL_SERVER_ERROR, ) self.assertTrue(ctx.filename.endswith("test_nonza.py"))
def test_accepts_tuple_instead_of_enum_for_condition_and_warns(self): e = nonza.StreamError() with self.assertWarnsRegex( DeprecationWarning, r"as of aioxmpp 1\.0, stream error conditions must be members " r"of the aioxmpp\.errors\.StreamErrorCondition " r"enumeration") as ctx: e.condition = errors.StreamErrorCondition.HOST_GONE.value self.assertEqual( errors.StreamErrorCondition.HOST_GONE, e.condition, ) self.assertIsInstance( e.condition_obj, errors.StreamErrorCondition.HOST_GONE.xso_class, ) self.assertTrue(ctx.filename.endswith("test_nonza.py"))
def test_initialises_with_undefined_condition(self): e = nonza.StreamError() self.assertIsInstance( e.condition_obj, errors.StreamErrorCondition.UNDEFINED_CONDITION.xso_class, )
def test_setting_condition_keeps_object_if_condition_matches(self): e = nonza.StreamError() old = e.condition_obj e.condition = errors.StreamErrorCondition.UNDEFINED_CONDITION self.assertIs(e.condition_obj, old)