HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall_new/buyercall/buyercall/tests/partnership/test_models.py
from buyercall.blueprints.partnership.models import (
    Partnership,
    PartnershipAccount,
    PartnershipAccountGroupTie
)
from buyercall.blueprints.phonenumbers.models import Phone
from buyercall.blueprints.user.models import User


class TestPartnershipAccountGroupTie(object):

    def test_partnership_account_group_tie_exists(self, users):
        user = User.find_by_identity('admin@localhost.com')
        if user:
            result = PartnershipAccountGroupTie.exists(
                user.partnership_account_group_id,
                user.partnership_account_id
            )
            assert not result
        else:
            assert False


class TestPartnershipAccount(object):
    def test_partnership_account_create(self, users):
        user = User.find_by_identity('admin@localhost.com')
        if user:
            result = PartnershipAccount.create(
                'partner account name',
                user.partnership_id,
                True,
                'account'
            )
            assert result
        else:
            assert False

    def test_partnership_account_partial_create(self):
        user = User.find_by_identity('admin@localhost.com')
        if user:
            result = PartnershipAccount.create_partial(
                'partner account partial name',
                user.partnership_id,
                True,
                'account_code'
            )
            assert result > 1
        else:
            assert False

    def test_partnership_account_update(self):

        account = PartnershipAccount.query.first()
        if account:
            result = PartnershipAccount.update(account.id, 'edited account name', 'invoice')
            edited_account = PartnershipAccount.query.filter(
                PartnershipAccount.id == account.id
            ).first()
            if edited_account.name == 'edited account name' and edited_account.billing_type == 'invoice':
                assert True
            else:
                assert False
        else:
            assert False

    def test_partnership_account_api_update(self):

        account = PartnershipAccount.query.first()
        if account:
            result = PartnershipAccount.api_update(
                account.id,
                account.partnership_id,
                'edited account name',
                True,
                'edited_code'
            )
            edited_account = PartnershipAccount.query.filter(
                PartnershipAccount.id == account.id
            ).first()
            if edited_account.name == 'edited account name' and edited_account.partner_account_code == 'edited_code':
                assert True
            else:
                assert False
        else:
            assert False

    def test_total_calls_count(self):
        account = PartnershipAccount.query.first()
        if account:
            calls_count = PartnershipAccount.total_calls_count(account.id)
            assert calls_count >= 0
        else:
            assert False

    def test_total_inbound_calls_count(self):
        account = PartnershipAccount.query.first()
        if account:
            inbound_calls_count = PartnershipAccount.total_inbound_calls_count(account.id)
            assert inbound_calls_count >= 0
        else:
            assert False

    def test_monthly_total_inbound_calls_count(self):
        account = PartnershipAccount.query.first()
        if account:
            monthly_total_inbound_calls_count = PartnershipAccount.monthly_total_inbound_calls_count(
                account.id
            )
            assert monthly_total_inbound_calls_count >= 0
        else:
            assert False

    def test_total_priority_phonenumbers(self):
        account = PartnershipAccount.query.first()
        if account:
            total_priority_phonenumbers = PartnershipAccount.monthly_total_inbound_calls_count(
                account.id
            )
            assert total_priority_phonenumbers >= 0
        else:
            assert False

    def test_has_active_subscription(self):
        account = PartnershipAccount.query.first()
        if account:
            assert not account.has_active_subscription
        else:
            assert False


class TestPartnership(object):

    def test_get_partnership_by_token(self):
        partnership = Partnership.query.first()
        if partnership:
            search_partnership = Partnership.get_partnership_by_token(partnership.api_token_id)
            assert partnership.id == search_partnership.id
        else:
            assert False