test_utils.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from django.contrib.contenttypes.models import ContentType
  2. from sentry.services.hybrid_cloud.user.serial import serialize_rpc_user
  3. from sentry.testutils.cases import TestCase
  4. from sentry.testutils.silo import no_silo_test
  5. from social_auth.utils import ctype_to_model, model_to_ctype
  6. @no_silo_test
  7. class TestSocialAuthUtils(TestCase):
  8. def test_model_to_ctype(self):
  9. val = model_to_ctype(1)
  10. assert val == 1
  11. val = model_to_ctype(None)
  12. assert val is None
  13. user = self.create_user()
  14. val = model_to_ctype(user)
  15. assert val == {"pk": user.id, "ctype": ContentType.objects.get_for_model(user).pk}
  16. rpc_user = serialize_rpc_user(user)
  17. val = model_to_ctype(rpc_user)
  18. assert val == rpc_user.dict()
  19. def test_ctype_to_model(self):
  20. val = ctype_to_model(1)
  21. assert val == 1
  22. val = ctype_to_model(None)
  23. assert val is None
  24. user = self.create_user()
  25. ctype_val = {"pk": user.id, "ctype": ContentType.objects.get_for_model(user).pk}
  26. assert ctype_to_model(ctype_val) == user
  27. rpc_user = serialize_rpc_user(user)
  28. assert ctype_to_model(rpc_user.dict()) == rpc_user