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_forms/buyercall/buyercall/tests/phonenumbers/test_models.py
from buyercall.blueprints.phonenumbers.models import Phone
from buyercall.blueprints.user.models import User


class TestPhoneNumber(object):

    def test_phone_create(self, users):
        """test creating a new phonenumber."""

        user_account = User.query.filter(User.email == 'admin@localhost.com').first()

        phonenumber_params = {
            'partnership_account_id': user_account.partnership_account_id,
            'phonenumber': '1122334455',
            'local': False,
            'tollfree': False,
            'type': 'mobile',
            'active': True,
            'caller_id': False,
            'friendly_name': 'mobile friendly number',
            'source': 'mobile',
            'channel': '',
            'twilio_number_sid': 'PN77f243b287536af37a6f9d058df1795b',
            'routing_config': '{"voicemailMessage": "Please leave a message after the beep.", '
                              '"recordCalls": false, "SMSAutoReplyText": "Are you available tomorrow for a showing?",'
                              ' "SMSAutoReplyImageUrl": "https://s3-us-west-2.amazonaws.com/buyercall-logo/'
                              'logo_buyercall_yellow.png", "greetingMessage": false, "language": "en", '
                              '"whisperMessageType": "text", "routingType": "default", "voicemail": false, '
                              '"SMSAutoReplyImage": false, "defaultRouting": {"retryRouting": 0, '
                              '"callOrder": "sequence", "dialDigit": false, '
                              '"agents": [{"fullName": "Barry White", "contactUsing": "phone", "id": 3}],'
                              ' "digitalPrompt": false}, "configSMSSetup": false, "SMSAutoReply": false, '
                              '"voicemailMessageType": "text", "whisperMessage": "This call will be recorded."}',
            'notifications': '{"notifyLeads": "all", "notifyMissedAgents": false, "notifyAllCustom": "",'
                             ' "notifyMissedMe": true, "notifyAllMe": true, "notifyAllAgents": false,'
                             ' "notifyMissedCustom": ""}',
            'provider': 'twilio',
            'deactivated_on': None,
            'is_deactivated': False
        }

        result = Phone.create(phonenumber_params)
        assert result

    def test_phone_update(self):
        """test creating a new phonenumber."""

        phone = Phone.query.filter(Phone.friendly_name == 'mobile friendly number').first()

        if phone:
            result = phone.update(phone.id, phone.partnership_account_id, '1122334456', 'mobile friendly number',
                                  'PN77f243b287536af37a6f9d058df1795b', 'mobile', 'channel', False, False)

            if result:
                phone_check = Phone.query.filter(Phone.id == phone.id).first()

                if phone_check.phonenumber == '1122334456' and phone_check.friendly_name == 'mobile friendly number' \
                        and phone_check.twilio_number_sid == 'PN77f243b287536af37a6f9d058df1795b' \
                        and phone_check.source == 'mobile' and phone_check.active == False:
                    assert True
            else:
                assert False
        else:
            assert False

    def test_phone_search(self):
        phones = Phone.query.filter(Phone.search('mobile')).all()

        if phones and len(phones) == 1:
            assert True
        else:
            assert False

    def test_deactivate(self):

        phone = Phone.query.first()
        if phone:
            result = Phone.deactivate(phone.id, phone.partnership_account_id)
            if result:
                deactivated_agent = Phone.query.filter(Phone.id == phone.id).first()
                if deactivated_agent.is_deactivated and not deactivated_agent.active and \
                        deactivated_agent.deactivated_on:
                    assert True
                else:
                    assert False
            else:
                assert False
        else:
            assert False