diff --git a/src/identity.cc b/src/identity.cc index b7ec03c..a941a6a 100644 --- a/src/identity.cc +++ b/src/identity.cc @@ -125,7 +125,7 @@ namespace pEp { return (int) rating; } - int Identity::color() + PEP_color Identity::color() { return _color(rating()); } diff --git a/src/identity.hh b/src/identity.hh index 0690831..cb423bf 100644 --- a/src/identity.hh +++ b/src/identity.hh @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -57,7 +58,7 @@ namespace pEp { void flags(identity_flags_t flags) { _ident->flags = flags; } int rating(); - int color(); + PEP_color color(); Identity copy(); Identity deepcopy(dict& memo); diff --git a/src/message.cc b/src/message.cc index 9f4e5dc..92cbb95 100644 --- a/src/message.cc +++ b/src/message.cc @@ -333,7 +333,7 @@ namespace pEp { return (int) rating; } - int Message::outgoing_color() + PEP_color Message::outgoing_color() { return _color(outgoing_rating()); } diff --git a/src/message.hh b/src/message.hh index 7dec7bf..56dc67a 100644 --- a/src/message.hh +++ b/src/message.hh @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "str_attr.hh" #include "identity.hh" @@ -132,7 +133,7 @@ namespace pEp { boost::python::tuple decrypt(int flags=0); int outgoing_rating(); - int outgoing_color(); + PEP_color outgoing_color(); Message deepcopy(dict& memo); Message copy(); }; diff --git a/src/message_api.cc b/src/message_api.cc index e73053b..09a8aec 100644 --- a/src/message_api.cc +++ b/src/message_api.cc @@ -62,9 +62,9 @@ namespace pEp { return boost::python::make_tuple(dst, keylist, _rating, _flags); } - int _color(int rating) + PEP_color _color(int rating) { - return (int) ::color_from_rating((PEP_rating) rating); + return ::color_from_rating((PEP_rating) rating); } boost::python::tuple sync_decode(object buffer) diff --git a/src/message_api.hh b/src/message_api.hh index b6afcba..ecc3a02 100644 --- a/src/message_api.hh +++ b/src/message_api.hh @@ -10,7 +10,7 @@ namespace pEp { Message encrypt_message(Message src, boost::python::list extra = boost::python::list(), int enc_format = 4, int flags = 0); boost::python::tuple decrypt_message(Message src, int flags=0); - int _color(int rating); + PEP_color _color(int rating); object sync_search(string name); object distribution_search(string name); } diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 4c29469..32b89c1 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -241,7 +241,7 @@ BOOST_PYTHON_MODULE(pEp) (void(pEp::PythonAdapter::Identity::*)(identity_flags_t)) &pEp::PythonAdapter::Identity::flags, "flags (p≡p internal)") .add_property("rating", &pEp::PythonAdapter::Identity::rating, "rating of Identity") - .add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity") + .add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity as PEP_color") .add_property("is_pEp_user", &pEp::PythonAdapter::Identity::is_pEp_user, "True if this is an identity of a pEp user") .def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy) .def("update", &pEp::PythonAdapter::Identity::update, "update Identity") @@ -391,7 +391,7 @@ BOOST_PYTHON_MODULE(pEp) " flags flags set while decryption\n" ) .add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have") - .add_property("outgoing_color", &Message::outgoing_color, "color outgoing message will have") + .add_property("outgoing_color", &Message::outgoing_color, "color outgoing message will have as PEP_color") .def("__deepcopy__", &Message::deepcopy) .def("__copy__", &Message::copy); @@ -477,6 +477,13 @@ BOOST_PYTHON_MODULE(pEp) .value("PEP_rating_b0rken", PEP_rating_b0rken) .value("PEP_rating_under_attack", PEP_rating_under_attack); + enum_("PEP_color") + .value("PEP_color_no_color", PEP_color_no_color) + .value("PEP_color_yellow", PEP_color_yellow) + .value("PEP_color_green", PEP_color_green) + .value("PEP_color_red", PEP_color_red); + + def("incoming_message", &incoming_message, "msg = incoming_message(mime_text)\n" "\n" @@ -490,7 +497,7 @@ BOOST_PYTHON_MODULE(pEp) def("color", &_color, "c = color(rating)\n" "\n" - "calculate color value out of rating" + "calculate color value out of rating. Returns PEP_color" ); def("trustwords", &_trustwords, "text = trustwords(ident_own, ident_partner)\n" diff --git a/test/doctest_PYADPT-55.py b/test/doctest_PYADPT-55.py new file mode 100644 index 0000000..592eb81 --- /dev/null +++ b/test/doctest_PYADPT-55.py @@ -0,0 +1,50 @@ +# Regression test against API breakage +# colors used to be represented as a simple int +# NEW: colors are represented by PEP_color enum +# Test for equal resolution of colors using int (OLD) vs using PEP_color (NEW) + +""" +>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_no_color) +True +>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_yellow) +True +>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_green) +True +>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_red) +True +""" + + + +import pEp +# resolves a color represented as int, the OLD way +# returns PEP_color +def resolveColorOLD(col): + ret = pEp.PEP_color() + + c = pEp.PEP_color(col) + if(c == 0): + ret = pEp.PEP_color.PEP_color_no_color + if(c == 1): + ret = pEp.PEP_color.PEP_color_yellow + if(c == 2): + ret = pEp.PEP_color.PEP_color_green + if(c == -1): + ret = pEp.PEP_color.PEP_color_red + + return ret + +# resolves a color represented as PEP_color, the NEW way +# returns PEP_color +def resolveColorNEW(col): + c = pEp.PEP_color(col) + return col + +# Compare color resolution OLD vs NEW way +# return True if results are equal +def resolveOLDvsNEW(col): + return resolveColorOLD(col) == resolveColorNEW(col) + +if __name__ == "__main__": + import doctest + doctest.testmod()