test_organization_socialapp.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from allauth.socialaccount.models import SocialApp
  2. from django import db
  3. from django.contrib.auth import get_user_model
  4. from django.test import TestCase
  5. from model_bakery import baker
  6. class OrganizationSocialAppTestCase(TestCase):
  7. @classmethod
  8. def setUpTestData(cls):
  9. cls.user = baker.make(get_user_model())
  10. cls.socialApp1 = baker.make(SocialApp)
  11. cls.socialApp2 = baker.make(SocialApp)
  12. cls.organization1 = baker.make("organizations_ext.Organization")
  13. cls.organization2 = baker.make("organizations_ext.Organization")
  14. cls.organization_social_app1 = baker.make(
  15. "organizations_ext.OrganizationSocialApp",
  16. organization=cls.organization1,
  17. social_app=cls.socialApp1,
  18. )
  19. cls.organization_social_app2 = baker.make(
  20. "organizations_ext.OrganizationSocialApp",
  21. organization=cls.organization1,
  22. social_app=cls.socialApp2,
  23. )
  24. def test_organization_social_app_association(self):
  25. retrieved_organization_socialapps = (
  26. self.organization1.organizationsocialapp_set.all()
  27. )
  28. self.assertEqual(retrieved_organization_socialapps.count(), 2)
  29. self.assertIn(self.organization_social_app1, retrieved_organization_socialapps)
  30. self.assertIn(self.organization_social_app2, retrieved_organization_socialapps)
  31. def test_social_app_organization_association(self):
  32. with self.assertRaises(db.utils.IntegrityError) as integrity_error:
  33. baker.make(
  34. "organizations_ext.OrganizationSocialApp",
  35. organization=self.organization2,
  36. social_app=self.socialApp1,
  37. )
  38. self.assertIn("unique constraint", str(integrity_error.exception))