# Path: test_abstract/models.py
# class CustomOrganization(AbstractOrganization):
#     street_address = models.CharField(max_length=100, default="")
#     city = models.CharField(max_length=100, default="")
# 
# Path: test_accounts/models.py
# class Account(OrganizationBase):
#     monthly_subscription = models.IntegerField(default=1000)
# 
# Path: test_accounts/models.py
# class AccountInvitation(OrganizationInvitationBase):
# 
#     def get_absolute_url(self):
#         """Returns the invitation URL"""
#         return reverse(
#             "test_accounts:account_invitations:invitations_register",
#             kwargs={"guid": str(self.guid)},
#         )
# 
# Path: test_vendors/models.py
# class Vendor(OrganizationBase):
#     street_address = models.CharField(max_length=100, default="")
#     city = models.CharField(max_length=100, default="")


from django.contrib.auth.models import User
from django.core import mail
from organizations.backends.defaults import InvitationBackend
from organizations.backends.modeled import ModelInvitation
from organizations.base import OrganizationInvitationBase
from organizations.utils import create_organization
from test_abstract.models import CustomOrganization
from test_accounts.models import Account
from test_accounts.models import AccountInvitation
from test_vendors.models import Vendor
import pytest
def invitee_user():
    yield User.objects.create_user(
        "newmember", email="jd@123.com", password="password123"
    )


@pytest.fixture
def invitation_backend():
    yield ModelInvitation(org_model=Account)


@pytest.fixture
def email_invitation(invitation_backend, account_account, account_user, invitee_user):
    yield invitation_backend.invite_by_email(
        invitee_user.email, user=account_user, organization=account_account
    )


class TestCustomModelBackend:
    """
    The default backend should provide the same basic functionality
    irrespective of the organization model.
    """

    def test_activate_orgs_vendor(self, account_user):
        """Ensure no errors raised because correct relation name used"""
        backend = InvitationBackend(org_model=Vendor)
        backend.activate_organizations(account_user)

    def test_activate_orgs_abstract(self, account_user):

# Path: test_abstract/models.py
# class CustomOrganization(AbstractOrganization):
#     street_address = models.CharField(max_length=100, default="")
#     city = models.CharField(max_length=100, default="")
# 
# Path: test_accounts/models.py
# class Account(OrganizationBase):
#     monthly_subscription = models.IntegerField(default=1000)
# 
# Path: test_accounts/models.py
# class AccountInvitation(OrganizationInvitationBase):
# 
#     def get_absolute_url(self):
#         """Returns the invitation URL"""
#         return reverse(
#             "test_accounts:account_invitations:invitations_register",
#             kwargs={"guid": str(self.guid)},
#         )
# 
# Path: test_vendors/models.py
# class Vendor(OrganizationBase):
#     street_address = models.CharField(max_length=100, default="")
#     city = models.CharField(max_length=100, default="")


# Path: tests/backends/test_model_based_backend.py
from django.contrib.auth.models import User
from django.core import mail
from organizations.backends.defaults import InvitationBackend
from organizations.backends.modeled import ModelInvitation
from organizations.base import OrganizationInvitationBase
from organizations.utils import create_organization
from test_abstract.models import CustomOrganization
from test_accounts.models import Account
from test_accounts.models import AccountInvitation
from test_vendors.models import Vendor
import pytest

def invitee_user():
    yield User.objects.create_user(
        "newmember", email="jd@123.com", password="password123"
    )


@pytest.fixture
def invitation_backend():
    yield ModelInvitation(org_model=Account)


@pytest.fixture
def email_invitation(invitation_backend, account_account, account_user, invitee_user):
    yield invitation_backend.invite_by_email(
        invitee_user.email, user=account_user, organization=account_account
    )


class TestCustomModelBackend:
    """
    The default backend should provide the same basic functionality
    irrespective of the organization model.
    """

    def test_activate_orgs_vendor(self, account_user):
        """Ensure no errors raised because correct relation name used"""
        backend = InvitationBackend(org_model=Vendor)
        backend.activate_organizations(account_user)

    def test_activate_orgs_abstract(self, account_user):

        backend = InvitationBackend(org_model=CustomOrganization)