util: fix bug in to_uid function

It must check for string_types, not str only. I've included to assertions in the test, making sure that it accepts both unicode and str.