Check that the tenant id is in the list

The comparison was wrong, therefore the code was adding the user to the
tenant when it was already there. This raised an exception.Conflict. Also
added a unittest for this case.

Cherry picked from 029d2ff715f0efa4bf3ab29d8b40aae963e69065 and
55e5002212297d57632fd50d0526472dd0ed2cd9