From 894c087fdcbfd6b9763109c1d5fb7d127f4d2a6e Mon Sep 17 00:00:00 2001 From: Wassilios Lytras Date: Sat, 4 May 2024 23:53:10 +0200 Subject: [PATCH] Adding tests for invalid callback function combination --- pyas2lib/tests/test_basic.py | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pyas2lib/tests/test_basic.py b/pyas2lib/tests/test_basic.py index 87f09cb..e1dc83a 100644 --- a/pyas2lib/tests/test_basic.py +++ b/pyas2lib/tests/test_basic.py @@ -248,6 +248,47 @@ def test_invalid_message_id_length_raises_error(self): in str(excinfo.value) ) + def test_invalid_cb_function_passed(self): + """Checking allowed combination of CB functions""" + + # Create AS2 message and parse with wrong combination of callback functions + + as2_message = as2.Message() + with pytest.raises( + TypeError, + match="Incorrect arguments passed: either find_org_cb and find_partner_cb " + "or only find_org_partner_cb must be passed.", + ): + + _, _, _ = as2_message.parse( + "abc", + find_org_partner_cb=self.find_org_partner, + find_partner_cb=self.find_partner, + ) + + with pytest.raises( + TypeError, + match="Incorrect arguments passed: either find_org_cb and find_partner_cb " + "or only find_org_partner_cb must be passed.", + ): + _, _, _ = as2_message.parse( + "abc", + find_org_partner_cb=self.find_org_partner, + find_org_cb=self.find_org, + ) + + with pytest.raises( + TypeError, + match="Incorrect arguments passed: either find_org_cb and find_partner_cb " + "or only find_org_partner_cb must be passed.", + ): + _, _, _ = as2_message.parse( + "abc", + find_org_partner_cb=self.find_org_partner, + find_org_cb=self.find_org, + find_partner_cb=self.find_partner, + ) + def find_org(self, as2_id): return self.org