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/contacts/test_views.py
from flask import url_for
from flask_babel import gettext as _

from buyercall.tests.lib.util import ViewTestMixin
from buyercall.tests.lib.assertions import assert_status_with_message
from buyercall.blueprints.contacts.models import Contact
from buyercall.blueprints.phonenumbers import Phone


class TestContactViews(ViewTestMixin):

    def test_contact_list_page_logged_out(self):
        """Contact lead page redirects to login."""
        response = self.client.get(url_for('contacts.contact_list'))
        assert_status_with_message(302, response, _('contacts'))

    def test_contact_list_page(self):
        """Contact lead page renders successfully."""
        self.login()
        response = self.client.get(url_for('contacts.contact_list'))
        assert_status_with_message(200, response, _('My Leads'))

    def test_details_view_logged_out(self, contacts):
        """Contact details page redirects to login."""
        contact = Contact.query.first()
        response = self.client.get(url_for('contacts.details_view', contact_id=contact.id))
        assert_status_with_message(302, response, _('details'))

    def test_details_view(self):
        """Retrieve Contact Details."""
        contact = Contact.query.first()
        self.login()
        response = self.client.get(
            url_for('contacts.details_view', contact_id=contact.id),
            follow_redirects=True
        )
        assert response.status_code == 200
        assert b'agentassigned' in response.data
        assert b'agents' in response.data
        assert b'email' in response.data

    def test_contact_edit_logged_out(self):
        """Contact edit page redirects to login."""
        contact = Contact.query.first()
        response = self.client.get(url_for('contacts.contact_edit', id=contact.id))
        assert response.status_code == 302
        assert b'contacts' in response.data
        assert b'edit' in response.data
        assert b'login' in response.data

    def test_contact_edit_page(self):
        """Contact edit page renders successfully."""
        contact = Contact.query.first()
        self.login()
        response = self.client.get(url_for('contacts.contact_edit', id=contact.id))
        assert_status_with_message(200, response, _('Edit Contact'))

    def test_contact_edit(self):
        """Editing a contact is successful."""
        contact = Contact.query.first()
        self.login()
        params = {
            'firstname': 'edited_first_name'
        }
        response = self.client.post(
            url_for('contacts.contact_edit', id=contact.id),
            data=params,
            follow_redirects=True
        )
        edited_contact = Contact.query.filter(Contact.id == contact.id).first()
        assert edited_contact.firstname == 'edited_first_name'
        assert_status_with_message(200, response, _('Edit Contact'))

    def test_contact_lead_page_logged_out(self):
        """Contact Lead Page redirects to login Page."""
        contact = Contact.query.first()
        response = self.client.get(url_for('contacts.contact_lead_page', id=contact.id))
        assert response.status_code == 302
        assert b'contacts' in response.data
        assert b'login' in response.data

    def test_contact_lead_page(self):
        """Contact Lead page renders successfully."""
        self.login()
        contact = Contact.query.first()
        response = self.client.get(url_for('contacts.contact_lead_page', id=contact.id))
        assert_status_with_message(200, response, _('Contact Lead'))

    def test_get_lead_message_info_logged_out(self):
        """Get lead message info redirect to login page."""
        contact = Contact.query.first()
        response = self.client.get(url_for('contacts.get_lead_message_info', lead_id=contact.id))
        assert response.status_code == 302
        assert b'api' in response.data
        assert b'contacts' in response.data
        assert b'login' in response.data

    def test_get_lead_message_info(self):
        """Get lead message info returns data."""
        self.login()
        contact = Contact.query.first()
        response = self.client.get(url_for('contacts.get_lead_message_info', lead_id=contact.id))
        assert response.status_code == 200
        assert b'allRoutingNumbers' in response.data
        assert b'name' in response.data
        assert b'phonenumber' in response.data
        assert b'routingNumber' in response.data

    def test_send_text_message_logged_out(self):
        """Send test message redirects to login."""
        response = self.client.get(url_for('contacts.send_text_message', inbound_id=1))
        assert response.status_code == 302

    def test_send_text_message(self):
        """Send text message successful."""
        self.login()
        contact = Contact.query.first()
        inbound_number = Phone.query.filter().first()
        response = self.client.get(
            url_for('contacts.send_text_message', inbound_id=inbound_number.id)
        )
        assert response.status_code == 200