File: //home/arjun/projects/buyercall_forms/buyercall/buyercall/tests/conftest.py
import datetime
from flask_login import login_user
from mock import Mock
import pytest
import pytz
from buyercall.app import create_app
from buyercall.blueprints.agents.models import Agent, AgentSchedule
from buyercall.blueprints.billing.gateways.stripecom import Card as PaymentCard
from buyercall.blueprints.billing.gateways.stripecom import Coupon as PaymentCoupon
from buyercall.blueprints.billing.gateways.stripecom import Event as PaymentEvent
from buyercall.blueprints.billing.gateways.stripecom import Invoice as PaymentInvoice
from buyercall.blueprints.billing.gateways.stripecom import Subscription as PaymentSubscription
from buyercall.blueprints.billing.models.coupon import Coupon
from buyercall.blueprints.billing.models.credit_card import CreditCard
from buyercall.blueprints.billing.models.subscription import Subscription
from buyercall.blueprints.block_numbers.models import Block
from buyercall.blueprints.contacts.models import Contact, ContactNotes
from buyercall.blueprints.form_leads.models import \
ExternalForm, ExternalFormField, FormLeadField, FormLead
from buyercall.blueprints.issue.models import Issue
from buyercall.blueprints.leads.models import Lead, LeadNotes
from buyercall.blueprints.mobile.models import Domain, Endpoint
from buyercall.blueprints.partnership.models import Partnership, PartnershipAccount, \
PartnershipAccountGroup, PartnershipAccountGroupTie
from buyercall.blueprints.phonenumbers.models import Phone
from buyercall.blueprints.reports.models import Report, ReportUserTie
from buyercall.blueprints.sms.models import Message
from buyercall.blueprints.user.models import User
from buyercall.blueprints.widgets.models import Widget, AgentAssignment
from buyercall.extensions import db as _db
from buyercall.lib.util_datetime import timedelta_months
from config import settings
# App and database fixtures ---------------------------------------------------
@pytest.yield_fixture(scope='session')
def app():
"""
Setup our flask test app, this only gets executed once.
:return: Flask app
"""
db_uri = '{0}_test'.format(settings.SQLALCHEMY_DATABASE_URI)
params = {
'DEBUG': False,
'TESTING': True,
'WTF_CSRF_ENABLED': False,
'SQLALCHEMY_DATABASE_URI': db_uri
}
_app = create_app(settings_override=params)
# Establish an application context before running the tests.
with _app.test_request_context():
ctx = _app.app_context()
ctx.push()
yield _app
ctx.pop()
@pytest.yield_fixture(scope='function')
def client(app):
"""
Setup an app client, this gets executed for each test function.
:param app: Pytest fixture
:return: Flask app client
"""
yield app.test_client()
@pytest.fixture(scope='session')
def db(app):
"""
Setup our database, this only gets executed once per session.
:param app: Pytest fixture
:return: SQLAlchemy database session
"""
_db.reflect()
_db.drop_all()
_db.create_all()
# Create a single user because a lot of tests do not mutate this user.
# It will result in quite a bit faster tests.
params = {
'role': 'admin',
'email': 'admin@localhost.com',
'firstname': 'Dev',
'password': 'password',
'two_factor_auth_onboard': True,
}
admin = User(**params)
_db.session.add(admin)
_db.session.commit()
return _db
@pytest.yield_fixture(scope='function')
def session(db):
"""
Allow very fast tests by using rollbacks and nested sessions. This does
require that your database supports SQL savepoints, and postgres does.
Read more about this at:
http://stackoverflow.com/a/26624146
:param db: Pytest fixture
:return: None
"""
db.session.begin_nested()
yield db.session
db.session.rollback()
@pytest.fixture(scope='function')
def admin_authenticated_request(app, db, users):
with app.test_request_context():
# Here we're not overloading the login manager, we're just directly logging in a user
# with whatever parameters we want. The user should only be logged in for the test,
# so you're not polluting the other tests.
admin_user = db.session.query(User).filter(User.email == 'admin@localhost.com').first()
yield login_user(admin_user)
@pytest.fixture(scope='function')
def partner_authenticated_request(app, db, users):
with app.test_request_context():
# Here we're not overloading the login manager, we're just directly logging in a user
# with whatever parameters we want. The user should only be logged in for the test,
# so you're not polluting the other tests.
partner_user = db.session.query(User).filter(User.email == 'partner@localhost.com').first()
yield login_user(partner_user)
@pytest.fixture(scope='function')
def sysadmin_authenticated_request(app, db, users):
with app.test_request_context():
# Here we're not overloading the login manager, we're just directly logging in a user
# with whatever parameters we want. The user should only be logged in for the test,
# so you're not polluting the other tests.
sysadmin_user = db.session.query(User).filter(User.email == 'sysadmin@localhost.com').first()
yield login_user(sysadmin_user)
# Model fixtures --------------------------------------------------------------
@pytest.fixture(scope='function')
def agents(db, users):
"""
Create agent fixtures. They reset per test.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
db.session.query(AgentSchedule).delete()
db.session.query(Agent).delete()
partnership_account = db.session.query(PartnershipAccount).filter(
PartnershipAccount.name == 'Airstrip One'
).first()
# Agent 1 --------------------------------------------------------------
agent_1_params = {
'user_id': None,
'firstname': 'tbd first name',
'lastname': 'tbd last name',
'title': 'mr',
'email': 'tbd.agent.test@buyercall.com',
'phonenumber': '1234567890',
'mobile': '1234567890',
'extension': 0,
'department': 'None',
'timezone': 'US/Central',
'partnership_account_id': partnership_account.id,
'all_hours': False
}
agent_1 = Agent(**agent_1_params)
db.session.add(agent_1)
db.session.flush()
agent_1_id = agent_1.id
db.session.commit()
day0param = {
'day': 0,
'available_from': '05:00 AM',
'available_to': '23:00 PM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_1_id
}
day1param = {
'day': 1,
'available_from': '05:00 AM',
'available_to': '23:00 PM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_1_id
}
day2param = {
'day': 2,
'available_from': '05:00 AM',
'available_to': '23:00 PM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_1_id
}
day3param = {
'day': 3,
'available_from': '05:00 AM',
'available_to': '23:00 PM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_1_id
}
day4param = {
'day': 4,
'available_from': '05:00 AM',
'available_to': '23:00 PM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_1_id
}
day5param = {
'day': 5,
'available_from': '05:00 AM',
'available_to': '23:00 PM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_1_id
}
day6param = {
'day': 6,
'available_from': '05:00 AM',
'available_to': '23:00 PM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_1_id
}
days = [day0param, day1param, day2param, day3param, day4param, day5param, day6param]
for day in days:
db.session.add(AgentSchedule(**day))
db.session.commit()
# Agent 2 --------------------------------------------------------------
agent_2_params = {
'user_id': None,
'firstname': 'the first name',
'lastname': 'the last name',
'title': 'miss',
'email': 'the.agent.test@buyercall.com',
'phonenumber': '1134567899',
'mobile': '1134567899',
'extension': 0,
'department': 'None',
'timezone': 'US/Central',
'partnership_account_id': partnership_account.id,
'all_hours': False,
'is_group': True
}
agent_2 = Agent(**agent_2_params)
db.session.add(agent_2)
db.session.flush()
agent_2_id = agent_2.id
db.session.commit()
day0param = {
'day': 0,
'available_from': '05:00 AM',
'available_to': '06:00 AM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_2_id
}
day1param = {
'day': 1,
'available_from': '05:00 AM',
'available_to': '06:00 AM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_2_id
}
day2param = {
'day': 2,
'available_from': '05:00 AM',
'available_to': '06:00 AM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_2_id
}
day3param = {
'day': 3,
'available_from': '05:00 AM',
'available_to': '06:00 AM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_2_id
}
day4param = {
'day': 4,
'available_from': '05:00 AM',
'available_to': '06:00 AM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_2_id
}
day5param = {
'day': 5,
'available_from': '05:00 AM',
'available_to': '06:00 AM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_2_id
}
day6param = {
'day': 6,
'available_from': '05:00 AM',
'available_to': '06:00 AM',
'is_active': True,
'partnership_account_id': partnership_account.id,
'agent_id': agent_2_id
}
days = [day0param, day1param, day2param, day3param, day4param, day5param, day6param]
for day in days:
db.session.add(AgentSchedule(**day))
db.session.commit()
# Agent 3 --------------------------------------------------------------
agent_3_params = {
'user_id': None,
'firstname': 'new first name',
'lastname': 'new last name',
'title': 'mrs',
'email': 'new.agent.test@buyercall.com',
'phonenumber': '2244668800',
'mobile': '2244668800',
'extension': 0,
'department': 'None',
'timezone': 'US/Central',
'partnership_account_id': partnership_account.id,
'all_hours': False
}
agent_3 = Agent(**agent_3_params)
db.session.add(agent_3)
db.session.flush()
agent_3_id = agent_3.id
db.session.commit()
contact_params = {
'partnership_account_id': partnership_account.id,
'agent_assigned': agent_1.full_name
}
contact = Contact(**contact_params)
db.session.add(contact)
db.session.flush()
contact_id = contact.id
db.session.commit()
lead = Lead(partnership_account_id=partnership_account.id,
status='in-progress',
firstname='test lead first name',
lastname='test lead last name',
email='lead_test_agmail@gmail.com',
phonenumber='9988776655',
duration=0,
agent_id=agent_1_id,
contact_id=contact_id,
call_type='inbound',
# starttime=call.start_time,
# endtime=call.end_time,
call_sid='dont know')
# Save the lead to the database
db.session.add(lead)
db.session.commit()
return db
@pytest.fixture(scope='function')
def contacts(db, users):
"""
Create contacts fixtures. They reset per test.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
db.session.query(ContactNotes).delete()
db.session.query(Contact).delete()
user_account = db.session.query(User).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 message 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
}
message_phonenumber = Phone(**phonenumber_params)
db.session.add(message_phonenumber)
db.session.commit()
message_contact_params_1 = {
'firstname': 'first_message',
'lastname': 'last_message',
'caller_id': 'i dont know',
'phonenumber_1': '1234567891',
'phonenumber_2': '0987654321',
'email': 'message@localhost.com',
'address_1': 'message address 1',
'address_2': 'message address 2',
'city': 'message city',
'state': 'message state',
'zip': 'zip',
'country': 'message country',
'ip': '192.168.0.1',
'partnership_account_id': user_account.partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
message_contact_1 = Contact(**message_contact_params_1)
db.session.add(message_contact_1)
db.session.commit()
sms_params_1 = {
'type': 'sms',
'provider': 'twilio',
'provider_message_id': 'SMfcd539ba8ade4dd7abda96659bad9b86',
'provider_message_date': 'db.Column(db.String(64), nullable=False, server_default='')',
'to': '1122334455',
'from_': '1234567890',
'body_text': 'such a body',
'num_media_files': '',
'media_url': '',
'status': 'delivered',
'delivery_code': 2,
'delivery_description': '',
'direction': 'in',
'inbound_id': message_phonenumber.id,
'partnership_account_id': user_account.partnership_account_id,
'contact_id': message_contact_1.id
}
message_sms_1 = Message(**sms_params_1)
db.session.add(message_sms_1)
db.session.commit()
message_contact_params_2 = {
'firstname': 'first_message',
'lastname': None,
'caller_id': 'i dont know',
'phonenumber_1': '1234567892',
'phonenumber_2': '0987654321',
'email': 'message@localhost.com',
'address_1': 'message address 1',
'address_2': 'message address 2',
'city': 'message city',
'state': 'message state',
'zip': 'zip',
'country': 'message country',
'ip': '192.168.0.1',
'partnership_account_id': user_account.partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
message_contact_2 = Contact(**message_contact_params_2)
db.session.add(message_contact_2)
db.session.commit()
sms_params_2 = {
'type': 'sms',
'provider': 'twilio',
'provider_message_id': 'SMfcd539ba8ade4dd7abda96659bad9b86',
'provider_message_date': 'db.Column(db.String(64), nullable=False, server_default='')',
'to': '1122334455',
'from_': '1234567890',
'body_text': 'such a body',
'num_media_files': '',
'media_url': '',
'status': 'delivered',
'delivery_code': 2,
'delivery_description': '',
'direction': 'in',
'inbound_id': message_phonenumber.id,
'partnership_account_id': user_account.partnership_account_id,
'contact_id': message_contact_2.id
}
message_sms_2 = Message(**sms_params_2)
db.session.add(message_sms_2)
db.session.commit()
message_contact_params_3 = {
'firstname': None,
'lastname': None,
'caller_id': 'dude',
'phonenumber_1': '1234567893',
'phonenumber_2': '0987654321',
'email': 'message@localhost.com',
'address_1': 'message address 1',
'address_2': 'message address 2',
'city': 'message city',
'state': 'message state',
'zip': 'zip',
'country': 'message country',
'ip': '192.168.0.1',
'partnership_account_id': user_account.partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
message_contact_3 = Contact(**message_contact_params_3)
db.session.add(message_contact_3)
db.session.commit()
sms_params_3 = {
'type': 'sms',
'provider': 'twilio',
'provider_message_id': 'SMfcd539ba8ade4dd7abda96659bad9b86',
'provider_message_date': 'db.Column(db.String(64), nullable=False, server_default='')',
'to': '1122334455',
'from_': '1234567890',
'body_text': 'such a body',
'num_media_files': '',
'media_url': '',
'status': 'delivered',
'delivery_code': 2,
'delivery_description': '',
'direction': 'in',
'inbound_id': message_phonenumber.id,
'partnership_account_id': user_account.partnership_account_id,
'contact_id': message_contact_3.id
}
message_sms_3 = Message(**sms_params_3)
db.session.add(message_sms_3)
db.session.commit()
message_contact_params_4 = {
'firstname': None,
'lastname': None,
'caller_id': None,
'phonenumber_1': None,
'phonenumber_2': '0987654321',
'email': 'message@localhost.com',
'address_1': 'message address 1',
'address_2': 'message address 2',
'city': 'message city',
'state': 'message state',
'zip': 'zip',
'country': 'message country',
'ip': '192.168.0.1',
'partnership_account_id': user_account.partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
message_contact_4 = Contact(**message_contact_params_4)
db.session.add(message_contact_4)
db.session.commit()
sms_params_4 = {
'type': 'sms',
'provider': 'twilio',
'provider_message_id': 'SMfcd539ba8ade4dd7abda96659bad9b86',
'provider_message_date': 'db.Column(db.String(64), nullable=False, server_default='')',
'to': '1122334455',
'from_': '1234567890',
'body_text': 'such a body',
'num_media_files': '',
'media_url': '',
'status': 'delivered',
'delivery_code': 2,
'delivery_description': '',
'direction': 'in',
'inbound_id': message_phonenumber.id,
'partnership_account_id': user_account.partnership_account_id,
'contact_id': message_contact_4.id
}
message_sms_4 = Message(**sms_params_4)
db.session.add(message_sms_4)
db.session.commit()
note_params_1 = {
'created_on': '2019-10-16 00:00',
'updated_on': '2019-10-16 00:00',
'contact_id': message_contact_1.id,
'is_enabled': True,
'text': 'Text bro 1',
'user_id': user_account.id,
'partnership_account_id': user_account.partnership_account_id
}
note_1 = ContactNotes(**note_params_1)
db.session.add(note_1)
db.session.commit()
note_params_2 = {
'created_on': '2019-10-16 00:00',
'updated_on': '2019-10-16 00:00',
'contact_id': message_contact_1.id,
'is_enabled': True,
'text': 'Text bro 2',
'user_id': user_account.id,
'partnership_account_id': user_account.partnership_account_id
}
note_2 = ContactNotes(**note_params_2)
db.session.add(note_2)
db.session.commit()
# Contact + Lead
lead_contact_params_1 = {
'firstname': 'first_lead',
'lastname': 'last_lead',
'caller_id': 'lead bro',
'phonenumber_1': '1234567891',
'phonenumber_2': '0987654321',
'email': 'lead@localhost.com',
'address_1': 'lead address 1',
'address_2': 'lead address 2',
'city': 'lead city',
'state': 'lead state',
'zip': 'zip',
'country': 'lead country',
'ip': '192.168.0.2',
'partnership_account_id': user_account.partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
lead_agent_1_params = {
'user_id': None,
'firstname': 'tbd first name',
'lastname': 'tbd last name',
'title': 'mr',
'email': 'tbd.agent.test@buyercall.com',
'phonenumber': '1234567890',
'mobile': '1234567890',
'extension': 0,
'department': 'None',
'timezone': 'US/Central',
'partnership_account_id': user_account.partnership_account_id,
'all_hours': False
}
lead_agent_1 = Agent(**lead_agent_1_params)
db.session.add(lead_agent_1)
db.session.flush()
agent_1_id = lead_agent_1.id
db.session.commit()
lead_contact_1 = Contact(**lead_contact_params_1)
db.session.add(lead_contact_1)
db.session.commit()
lead_params_1 = {
'partnership_account_id': user_account.partnership_account_id,
'call_source': '',
'progress_status': '',
'firstname': 'Random FN',
'caller_id': '',
'lastname': 'Random LN',
'email': 'lead@localhost.com',
'phonenumber': '1133557799',
'my_phone': '',
'question': 'Serious?',
'duration': 5,
'starttime': '2019-10-01 03:38:17',
'endtime': '2019-10-02 03:38:17',
'status': 'completed',
'call_type': 'inbound',
'call_sid': 'verylong',
'recording_url': '',
'widget_guid': None,
'inbound_id': message_phonenumber.id,
'agent_id': agent_1_id,
'contact_id': lead_contact_1.id,
'agent_assigned_id': agent_1_id,
'response_time_seconds': 5,
'additional_info': ''
}
lead_1 = Lead(**lead_params_1)
db.session.add(lead_1)
db.session.commit()
return db
@pytest.fixture(scope='function')
def messages(db, users):
db.session.query(Message).delete()
db.session.query(ContactNotes).delete()
db.session.query(Contact).delete()
db.session.query(Phone).delete()
user_account = db.session.query(User).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 message 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
}
message_phonenumber = Phone(**phonenumber_params)
db.session.add(message_phonenumber)
db.session.commit()
message_contact_params_1 = {
'firstname': 'first_message',
'lastname': 'last_message',
'caller_id': 'i dont know',
'phonenumber_1': '1234567891',
'phonenumber_2': '0987654321',
'email': 'message@localhost.com',
'address_1': 'message address 1',
'address_2': 'message address 2',
'city': 'message city',
'state': 'message state',
'zip': 'zip',
'country': 'message country',
'ip': '192.168.0.1',
'partnership_account_id': user_account.partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
message_contact_1 = Contact(**message_contact_params_1)
db.session.add(message_contact_1)
db.session.commit()
sms_params_1 = {
'type': 'sms',
'provider': 'twilio',
'provider_message_id': 'SMfcd539ba8ade4dd7abda96659bad9b86',
'provider_message_date': 'db.Column(db.String(64), nullable=False, server_default='')',
'to': '1122334455',
'from_': '1234567890',
'body_text': 'such a body',
'num_media_files': '',
'media_url': '',
'status': 'delivered',
'delivery_code': 2,
'delivery_description': '',
'direction': 'in',
'inbound_id': message_phonenumber.id,
'partnership_account_id': user_account.partnership_account_id,
'contact_id': message_contact_1.id
}
message_sms_1 = Message(**sms_params_1)
db.session.add(message_sms_1)
db.session.commit()
@pytest.fixture(scope='function')
def leads(db, users):
db.session.query(LeadNotes).delete()
db.session.query(Lead).delete()
db.session.query(Widget).delete()
db.session.query(Phone).delete()
db.session.query(ContactNotes).delete()
db.session.query(Contact).delete()
user_account = db.session.query(User).filter(User.email == 'admin@localhost.com').first()
partnership_account_id = user_account.partnership_account_id
lead_contact_params_1 = {
'firstname': 'first_lead',
'lastname': 'last_lead',
'caller_id': 'lead bro',
'phonenumber_1': '1234567891',
'phonenumber_2': '0987654321',
'email': 'lead@localhost.com',
'address_1': 'lead address 1',
'address_2': 'lead address 2',
'city': 'lead city',
'state': 'lead state',
'zip': 'zip',
'country': 'lead country',
'ip': '192.168.0.2',
'partnership_account_id': partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
lead_agent_1_params = {
'user_id': None,
'firstname': 'tbd first name',
'lastname': 'tbd last name',
'title': 'mr',
'email': 'tbd.agent.test@buyercall.com',
'phonenumber': '1234567890',
'mobile': '1234567890',
'extension': 0,
'department': 'None',
'timezone': 'US/Central',
'partnership_account_id': partnership_account_id,
'all_hours': False
}
lead_agent_1 = Agent(**lead_agent_1_params)
db.session.add(lead_agent_1)
db.session.flush()
agent_1_id = lead_agent_1.id
db.session.commit()
lead_agent_2_params = {
'user_id': None,
'firstname': 'no2 first name',
'lastname': 'no2 last name',
'title': 'mr',
'email': 'no2.agent.test@buyercall.com',
'phonenumber': '3334567000',
'mobile': '3334567000',
'extension': 0,
'department': 'None',
'timezone': 'US/Central',
'partnership_account_id': partnership_account_id,
'all_hours': False
}
lead_agent_2 = Agent(**lead_agent_2_params)
db.session.add(lead_agent_2)
db.session.flush()
agent_2_id = lead_agent_2.id
db.session.commit()
phonenumber_params = {
'partnership_account_id': partnership_account_id,
'phonenumber': '1122334455',
'local': False,
'tollfree': False,
'type': 'mobile',
'active': True,
'caller_id': False,
'friendly_name': 'mobile message 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
}
phonenumber = Phone(**phonenumber_params)
db.session.add(phonenumber)
db.session.commit()
widget_params = {
'guid': 'this is a test',
'name': 'widget name',
'options': '',
'enabled': True,
'inbound_id': phonenumber.id,
'partnership_account_id': partnership_account_id,
'email': 'testing@localhost.com',
'type': 'widget'
}
widget = Widget(**widget_params)
db.session.add(widget)
db.session.commit()
lead_contact_1 = Contact(**lead_contact_params_1)
db.session.add(lead_contact_1)
db.session.commit()
lead_params_1 = {
'partnership_account_id': partnership_account_id,
'call_source': '',
'progress_status': '',
'firstname': 'Random FN',
'caller_id': '',
'lastname': 'Random LN',
'email': 'lead@localhost.com',
'phonenumber': '1133557799',
'my_phone': '',
'question': 'Serious?',
'duration': 5,
'starttime': '2019-10-01 03:38:17',
'endtime': '2019-10-02 03:38:17',
'status': 'completed',
'call_type': 'inbound',
'call_sid': 'verylong',
'recording_url': '',
'widget_guid': None,
'inbound_id': phonenumber.id,
'agent_id': agent_1_id,
'contact_id': lead_contact_1.id,
'agent_assigned_id': agent_2_id,
'response_time_seconds': 5,
'additional_info': ''
}
lead_1 = Lead(**lead_params_1)
db.session.add(lead_1)
db.session.commit()
lead_params_2 = {
'partnership_account_id': partnership_account_id,
'call_source': '',
'progress_status': '',
'firstname': 'Widget FN',
'caller_id': '',
'lastname': 'Widget LN',
'email': 'widget@localhost.com',
'phonenumber': '1122445599',
'my_phone': '',
'question': 'Serious? Yes?',
'duration': 5,
'starttime': '2019-10-01 03:38:17',
'endtime': '2019-10-02 03:38:17',
'status': 'completed',
'call_type': 'inbound',
'call_sid': 'verylong',
'recording_url': '',
'widget_guid': 'this is a test',
'inbound_id': None,
'agent_id': agent_1_id,
'contact_id': lead_contact_1.id,
'agent_assigned_id': agent_2_id,
'response_time_seconds': 15,
'additional_info': ''
}
lead_2 = Lead(**lead_params_2)
db.session.add(lead_2)
db.session.commit()
lead_note_1_params = {
'created_on': datetime.datetime.now(),
'updated_on': datetime.datetime.now(),
'user_id': user_account.id,
'lead_id': lead_1.id,
'text': 'test note 1',
'is_enabled': True
}
lead_note_1 = LeadNotes(**lead_note_1_params)
db.session.add(lead_note_1)
db.session.commit()
lead_note_2_params = {
'created_on': datetime.datetime.now(),
'updated_on': datetime.datetime.now(),
'user_id': user_account.id,
'lead_id': lead_1.id,
'text': 'test note 2',
'is_enabled': True
}
lead_note_2 = LeadNotes(**lead_note_2_params)
db.session.add(lead_note_2)
db.session.commit()
return db
@pytest.fixture(scope='function')
def form_leads(db, users):
db.session.query(FormLeadField).delete()
db.session.query(FormLead).delete()
db.session.query(ExternalFormField).delete()
db.session.query(ExternalForm).delete()
db.session.query(Widget).delete()
db.session.query(Phone).delete()
db.session.query(ContactNotes).delete()
db.session.query(Contact).delete()
user_account = db.session.query(User).filter(User.email == 'admin@localhost.com').first()
partnership_account_id = user_account.partnership_account_id
phonenumber_params = {
'partnership_account_id': partnership_account_id,
'phonenumber': '1122334455',
'local': False,
'tollfree': False,
'type': 'mobile',
'active': True,
'caller_id': False,
'friendly_name': 'mobile message 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
}
widget_phonenumber = Phone(**phonenumber_params)
db.session.add(widget_phonenumber)
db.session.commit()
widget_params = {
'guid': 'this is a test',
'name': 'widget name',
'options': '',
'enabled': True,
'inbound_id': widget_phonenumber.id,
'partnership_account_id': partnership_account_id,
'email': 'testing@localhost.com',
'type': 'widget'
}
widget = Widget(**widget_params)
db.session.add(widget)
db.session.commit()
external_forms_params = {
'public_id': 'form1',
'display_name': 'form1',
'routing_id': widget.id,
#'is_external_api_auto': False,
'partnership_account_id': partnership_account_id,
'email_addresses': '{"emails": "justvuur@gmail.com"}',
'email_subject': '',
'partial_data_email': True,
'full_submit_email': False,
'adf_email_addresses': '{"emails": ""}',
'send_auto_email': False,
'send_auto_email_subject': '',
'send_auto_email_msg': '',
'send_auto_sms': False,
'send_auto_sms_inbound_id': widget_phonenumber.id,
'send_auto_sms_msg': ''
}
external_form = ExternalForm(**external_forms_params)
db.session.add(external_form)
db.session.commit()
external_form_field_1_params = {
'form_id': external_form.id,
'position': 0,
'field_id': 'firstnamefield',
'display_name': 'first name',
'show_in_table': False
}
external_form_field_2_params = {
'form_id': external_form.id,
'position': 1,
'field_id': 'lastnamefield',
'display_name': 'last name',
'show_in_table': False
}
external_form_field_3_params = {
'form_id': external_form.id,
'position': 1,
'field_id': 'privacypolicyfield',
'display_name': 'privacy policy field',
'show_in_table': False
}
external_form_field_1 = ExternalFormField(**external_form_field_1_params)
db.session.add(external_form_field_1)
db.session.commit()
external_form_field_2 = ExternalFormField(**external_form_field_2_params)
db.session.add(external_form_field_2)
db.session.commit()
external_form_field_3 = ExternalFormField(**external_form_field_3_params)
db.session.add(external_form_field_3)
db.session.commit()
form_lead_contact_1_params = {
'firstname': 'first_form_lead',
'lastname': 'last_form_lead',
'caller_id': 'i dont know',
'phonenumber_1': '1234567891',
'phonenumber_2': '0987654321',
'email': 'form_lead@localhost.com',
'address_1': 'form_lead address 1',
'address_2': 'form_lead address 2',
'city': 'form_lead city',
'state': 'form_lead state',
'zip': 'zip',
'country': 'form_lead country',
'ip': '192.168.0.1',
'partnership_account_id': partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
form_lead_contact_1 = Contact(**form_lead_contact_1_params)
db.session.add(form_lead_contact_1)
db.session.commit()
form_lead_contact_2_params = {
'firstname': 'yes_first_form_lead',
'lastname': 'yes_last_form_lead',
'caller_id': 'i dont know',
'phonenumber_1': '1134567891',
'phonenumber_2': '0087654321',
'email': 'yes_form_lead@localhost.com',
'address_1': 'form_lead address 1',
'address_2': 'form_lead address 2',
'city': 'form_lead city',
'state': 'form_lead state',
'zip': 'zip',
'country': 'form_lead country',
'ip': '192.168.0.1',
'partnership_account_id': partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
form_lead_contact_2 = Contact(**form_lead_contact_2_params)
db.session.add(form_lead_contact_2)
db.session.commit()
form_lead_contact_3_params = {
'firstname': 'no_first_form_lead',
'lastname': 'no_last_form_lead',
'caller_id': 'i dont know',
'phonenumber_1': '2234567891',
'phonenumber_2': '8987654321',
'email': 'no_form_lead@localhost.com',
'address_1': 'form_lead address 1',
'address_2': 'form_lead address 2',
'city': 'form_lead city',
'state': 'form_lead state',
'zip': 'zip',
'country': 'form_lead country',
'ip': '192.168.0.1',
'partnership_account_id': partnership_account_id,
'is_do_not_call': False,
'is_unsubscribe': False,
'agent_assigned': 'Agent name',
'status': 'no status'
}
form_lead_contact_3 = Contact(**form_lead_contact_3_params)
db.session.add(form_lead_contact_3)
db.session.commit()
form_lead_1_param = {
'form_id': external_form.id,
# 'external_api_lead_id': '',
'partnership_account_id': partnership_account_id,
'email_sent': False,
'contact_id': form_lead_contact_1.id
}
form_lead_1 = FormLead(**form_lead_1_param)
db.session.add(form_lead_1)
db.session.commit()
new_1 = FormLeadField('firstnamefield', 'the first name')
new_1.lead_id = form_lead_1.id
db.session.add(new_1)
db.session.commit()
new_2 = FormLeadField('lastnamefield', 'the last name')
new_2.lead_id = form_lead_1.id
db.session.add(new_2)
db.session.commit()
form_lead_2_param = {
'form_id': external_form.id,
# 'external_api_lead_id': '',
'partnership_account_id': partnership_account_id,
'email_sent': False,
'contact_id': form_lead_contact_2.id
}
form_lead_2 = FormLead(**form_lead_2_param)
db.session.add(form_lead_2)
db.session.commit()
new_3 = FormLeadField('firstnamefield', 'the first name')
new_3.lead_id = form_lead_2.id
db.session.add(new_3)
db.session.commit()
new_4 = FormLeadField('lastnamefield', 'the last name')
new_4.lead_id = form_lead_2.id
db.session.add(new_4)
db.session.commit()
new_5 = FormLeadField('privacypolicyfield', 'yes')
new_5.lead_id = form_lead_2.id
db.session.add(new_5)
db.session.commit()
form_lead_3_param = {
'form_id': external_form.id,
# 'external_api_lead_id': '',
'partnership_account_id': partnership_account_id,
'email_sent': False,
'contact_id': form_lead_contact_3.id
}
form_lead_3 = FormLead(**form_lead_3_param)
db.session.add(form_lead_3)
db.session.commit()
new_6 = FormLeadField('firstnamefield', 'the first name')
new_6.lead_id = form_lead_3.id
db.session.add(new_6)
db.session.commit()
new_7 = FormLeadField('lastnamefield', 'the last name')
new_7.lead_id = form_lead_3.id
db.session.add(new_7)
db.session.commit()
new_8 = FormLeadField('privacypolicyfield', 'no')
new_8.lead_id = form_lead_3.id
db.session.add(new_8)
db.session.commit()
return db
@pytest.fixture(scope='session')
def token(db):
"""
Serialize a JWS token.
:param db: Pytest fixture
:return: JWS token
"""
user = User.find_by_identity('admin@localhost.com')
return user.serialize_token()
@pytest.fixture(scope='function')
def users(db):
"""
Create user fixtures. They reset per test.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
db.session.query(ReportUserTie).delete()
db.session.query(Report).delete()
db.session.query(Domain).delete()
db.session.query(Endpoint).delete()
db.session.query(FormLeadField).delete()
db.session.query(FormLead).delete()
db.session.query(ExternalFormField).delete()
db.session.query(ExternalForm).delete()
db.session.query(LeadNotes).delete()
db.session.query(Lead).delete()
db.session.query(Message).delete()
db.session.query(Widget).delete()
db.session.query(Phone).delete()
db.session.query(ContactNotes).delete()
db.session.query(Contact).delete()
db.session.query(PartnershipAccountGroupTie).delete()
db.session.query(PartnershipAccountGroup).delete()
db.session.query(AgentSchedule).delete()
db.session.query(Agent).delete()
db.session.query(User).delete()
db.session.query(PartnershipAccount).delete()
db.session.query(Partnership).delete()
db.session.query(Subscription).delete()
partnership_account_group = PartnershipAccountGroup(
name='test'
)
db.session.add(partnership_account_group)
partnership = Partnership(
name='Oceania',
default_billing_type='invoice',
)
# partnership_account_group_tie = PartnershipAccountGroupTie(
# partnership_account_group_id=partnership_account_group.id
# )
db.session.add(partnership)
partnership_account_one = PartnershipAccount(
name='Airstrip One',
partnership=partnership,
billing_type='invoice'
)
partnership_account_two = PartnershipAccount(
name='Airstrip Two',
partnership=partnership,
billing_type='account',
# partnership_account_group=[partnership_account_group_tie,]
)
db.session.add(partnership_account_one)
db.session.add(partnership_account_two)
subscription_one = Subscription(
partnership=partnership,
partnership_account=partnership_account_one,
plan='smallbusinesspackage',
status='active',
coupon='test coupon 1'
)
db.session.add(subscription_one)
subscription_two = Subscription(
partnership=partnership,
partnership_account=partnership_account_two,
plan='bronze',
status='active'
)
db.session.add(subscription_two)
agent = Agent(
partnership_account=partnership_account_one,
email='agent@localhost.com',
)
db.session.add(agent)
users = [
{
'role': 'sysadmin',
'email': 'sysadmin@localhost.com',
'password': 'password',
'two_factor_auth_onboard': True
},
{
'role': 'partner',
'email': 'partner@localhost.com',
'password': 'password',
'partnership': partnership,
'partnership_account': partnership_account_one,
'firstname': 'partner_firstname',
'lastname': 'partner_lastname',
'two_factor_auth_onboard': True
},
{
'role': 'admin',
'email': 'admin@localhost.com',
'password': 'password',
'partnership': partnership,
'partnership_account': partnership_account_one,
'firstname': 'admin_firstname',
'lastname': 'admin_lastname',
'two_factor_auth_onboard': True,
'agent': agent
},
{
'role': 'admin',
'email': 'admin_in_pag@localhost.com',
'password': 'password',
'partnership': partnership,
'partnership_account': partnership_account_two,
'firstname': 'admin_pag_fn',
'lastname': 'admin_pag_ln',
'partnership_account_group_id': partnership_account_group.id
},
{
'role': 'partner',
'email': 'random_partner@localhost.com',
'password': 'password',
'partnership': partnership,
'firstname': 'random_partner_fn',
'lastname': 'random_partner_ln',
'partnership_account': partnership_account_one,
'two_factor_auth_onboard': True
},
{
'active': False,
'email': 'disabled@localhost.com',
'password': 'password',
'two_factor_auth_onboard': True
},
{
'role': 'admin',
'email': 'random_admin@localhost.com',
'firstname': 'random_admin_fn',
'lastname': 'random_admin_ln',
'password': 'password'
}
]
for user in users:
db.session.add(User(**user))
db.session.commit()
return db
@pytest.fixture(scope='function')
def user(db):
"""
Create user fixtures. They reset per test. Scaled down version of the previous fixture.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
db.session.query(FormLeadField).delete()
db.session.query(FormLead).delete()
db.session.query(ExternalFormField).delete()
db.session.query(ExternalForm).delete()
db.session.query(LeadNotes).delete()
db.session.query(Lead).delete()
db.session.query(Message).delete()
db.session.query(Widget).delete()
db.session.query(Phone).delete()
db.session.query(ContactNotes).delete()
db.session.query(Contact).delete()
db.session.query(User).delete()
db.session.query(PartnershipAccount).delete()
db.session.query(Partnership).delete()
db.session.query(Subscription).delete()
partnership = Partnership(
name='Oceania',
default_billing_type='invoice',
)
db.session.add(partnership)
partnership_account_one = PartnershipAccount(
name='Airstrip One',
partnership=partnership,
billing_type='invoice'
)
db.session.add(partnership_account_one)
subscription_one = Subscription(
partnership=partnership,
partnership_account=partnership_account_one,
plan='bronze',
status='active',
coupon='test coupon 1'
)
db.session.add(subscription_one)
users = [
{
'role': 'sysadmin',
'email': 'sysadmin@localhost.com',
'password': 'password',
},
{
'role': 'admin',
'email': 'admin@localhost.com',
'password': 'password',
'partnership': partnership,
'partnership_account': partnership_account_one,
'firstname': 'dev',
},
{
'role': 'partner',
'email': 'partner@localhost.com',
'password': 'password',
'partnership': partnership,
'firstname': 'partner_firstname',
'lastname': 'partner_lastname'
},
{
'active': False,
'email': 'disabled@localhost.com',
'password': 'password'
}
]
for user in users:
db.session.add(User(**user))
db.session.commit()
return db
@pytest.fixture(scope='function')
def blocked_numbers(db, users):
db.session.query(Block).delete()
db.session.query(Phone).delete()
user = User.find_by_identity('admin@localhost.com')
phonenumber = Phone(
partnership_account=user.partnership_account,
phonenumber='+11115551111',
local=True,
friendly_name='Default',
routing_config={
"type": "local",
"routingType": "default",
"defaultRouting": {},
},
provider='bandwidth',
)
db.session.add(phonenumber)
db.session.commit()
blocked_number_params = Block(
phonenumber='+11115551112',
status='blocked',
partnership_accounts_id=user.partnership_account.id,
global_exclusion=True
)
db.session.add(blocked_number_params)
db.session.commit()
return db
@pytest.fixture(scope='function')
def numbers(db, users):
db.session.query(Phone).delete()
user = User.find_by_identity('admin@localhost.com')
agent = User(
partnership=user.partnership,
partnership_account=user.partnership_account,
role='agent',
email='agent@localhost.com',
)
db.session.add(agent)
db.session.commit()
phonenumber = Phone(
partnership_account=user.partnership_account,
phonenumber='+11115551111',
local=True,
friendly_name='Default',
routing_config={
"type": "local",
"routingType": "default",
"defaultRouting": {},
},
provider='bandwidth',
)
db.session.add(phonenumber)
db.session.commit()
return db
@pytest.fixture(scope='function')
def issues(db, users):
"""
Create issue fixtures. They reset per test.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
db.session.query(Issue).delete()
admin_user = db.session.query(User).filter(User.email == 'admin@localhost.com').first()
issues = [
{
'label': 'login',
'email': 'admin@localhost.com',
'question': '42.',
'status': 'unread',
'partnership_account_id': admin_user.partnership_account_id,
'partnership_id': admin_user.partnership_id
},
{
'label': 'billing',
'email': 'admin@localhost.com',
'question': 'Hello.',
'status': 'unread',
'partnership_account_id': admin_user.partnership_account_id,
'partnership_id': admin_user.partnership_id
}
]
for issue in issues:
db.session.add(Issue(**issue))
db.session.commit()
return db
@pytest.fixture(scope='function')
def credit_cards(db):
"""
Create credit card fixtures. They reset per test.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
db.session.query(CreditCard).delete()
may_29_2015 = datetime.date(2015, 5, 29)
june_29_2015 = datetime.datetime(2015, 6, 29, 0, 0, 0)
june_29_2015 = pytz.utc.localize(june_29_2015)
credit_cards = [
{
'brand': 'Visa',
'last4': 4242,
'exp_date': june_29_2015
},
{
'brand': 'Visa',
'last4': 4242,
'exp_date': timedelta_months(12, may_29_2015)
}
]
for card in credit_cards:
db.session.add(CreditCard(**card))
db.session.commit()
return db
@pytest.fixture(scope='function')
def coupons(db):
"""
Create coupon fixtures. They reset per test.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
db.session.query(Coupon).delete()
may_29_2015 = datetime.datetime(2015, 5, 29, 0, 0, 0)
may_29_2015 = pytz.utc.localize(may_29_2015)
june_29_2015 = datetime.datetime(2015, 6, 29)
june_29_2015 = pytz.utc.localize(june_29_2015)
coupons = [
{
'amount_off': 1,
'redeem_by': may_29_2015
},
{
'amount_off': 1,
'redeem_by': june_29_2015
},
{
'amount_off': 1
}
]
for coupon in coupons:
db.session.add(Coupon(**coupon))
db.session.commit()
return db
@pytest.fixture(scope='function')
def subscriptions(db):
"""
Create subscription fixtures. They reset per test.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
subscriber = User.find_by_identity('subscriber@localhost.com')
if subscriber:
subscriber.delete()
db.session.query(Subscription).delete()
partnership = Partnership(name='Test partner', default_billing_type='invoice')
db.session.add(partnership)
partnership_account = PartnershipAccount(
name='Test Partner Account',
partnership=partnership,
billing_type='account',
)
db.session.add(partnership_account)
subscription = Subscription(
partnership=partnership,
partnership_account=partnership_account,
plan='starterpackage',
status='active',
)
db.session.add(subscription)
params = {
'role': 'admin',
'email': 'subscriber@localhost.com',
'firstname': 'Subby',
'password': 'password',
'partnership': partnership,
'partnership_account': partnership_account,
'two_factor_auth_onboard': True
# 'payment_id': 'cus_000'
}
admin = User(**params)
# The account needs to be commit before we can assign a subscription to it.
db.session.add(admin)
db.session.commit()
# Create a subscription.
# params = {
# 'partnership_account': admin.partnership_account,
# 'plan': 'gold'
# }
# subscription = Subscription(**params)
# db.session.add(subscription)
# Create a credit card.
params = {
'subscriptions': [subscription],
'brand': 'Visa',
'last4': '4242',
'exp_date': datetime.date(2015, 6, 1)
}
credit_card = CreditCard(**params)
db.session.add(credit_card)
db.session.commit()
return db
# Service fixtures ------------------------------------------------------------
@pytest.fixture(scope='session')
def mock_stripe():
"""
Mock all of the Stripe API calls.
:return:
"""
PaymentCoupon.create = Mock(return_value={})
PaymentCoupon.delete = Mock(return_value={})
PaymentEvent.retrieve = Mock(return_value={})
PaymentCard.update = Mock(return_value={})
PaymentSubscription.create = Mock(return_value={})
PaymentSubscription.update = Mock(return_value={})
PaymentSubscription.cancel = Mock(return_value={})
upcoming_api = {
'date': 1433018770,
'id': 'in_000',
'period_start': 1433018770,
'period_end': 1433018770,
'lines': {
'data': [
{
'id': 'sub_000',
'object': 'line_item',
'type': 'subscription',
'livemode': True,
'amount': 0,
'currency': 'usd',
'proration': False,
'period': {
'start': 1433161742,
'end': 1434371342
},
'subscription': None,
'quantity': 1,
'plan': {
'interval': 'month',
'name': 'Gold',
'created': 1424879591,
'amount': 500,
'currency': 'usd',
'id': 'gold',
'object': 'plan',
'livemode': False,
'interval_count': 1,
'trial_period_days': 14,
'metadata': {
},
'statement_descriptor': 'GOLD MONTHLY'
},
'description': None,
'discountable': True,
'metadata': {
}
}
],
'total_count': 1,
'object': 'list',
'url': '/v1/invoices/in_000/lines'
},
'subtotal': 0,
'total': 0,
'customer': 'cus_000',
'object': 'invoice',
'attempted': True,
'closed': True,
'forgiven': False,
'paid': True,
'livemode': False,
'attempt_count': 0,
'amount_due': 500,
'currency': 'usd',
'starting_balance': 0,
'ending_balance': 0,
'next_payment_attempt': None,
'webhooks_delivered_at': None,
'charge': None,
'discount': None,
'application_fee': None,
'subscription': 'sub_000',
'tax_percent': None,
'tax': None,
'metadata': {
},
'statement_descriptor': None,
'description': None,
'receipt_number': None
}
PaymentInvoice.upcoming = Mock(return_value=upcoming_api)
@pytest.fixture(scope='function')
def billing(db):
"""
Create user fixtures. They reset per test.
:param db: Pytest fixture
:return: SQLAlchemy database session
"""
db.session.query(User).delete()
db.session.query(PartnershipAccount).delete()
db.session.query(Partnership).delete()
partnership_1 = Partnership(
name='Oceania',
default_billing_type='invoice'
)
db.session.add(partnership_1)
partnership_2 = Partnership(
name='Atlanta',
default_billing_type='invoice'
)
db.session.add(partnership_2)
partnership_account_1 = PartnershipAccount(
name='Airstrip One',
partnership=partnership_1,
billing_type='account',
)
db.session.add(partnership_account_1)
partnership_account_2 = PartnershipAccount(
name='Airstrip Two',
partnership=partnership_2,
billing_type='account',
)
db.session.add(partnership_account_2)
subscription = Subscription(
partnership=partnership_1,
partnership_account=partnership_account_1,
plan='starterpackage',
status='active',
)
db.session.add(subscription)
users = [
{
'role': 'admin',
'email': 'admin@localhost.com',
'password': 'password',
'partnership': partnership_2,
'partnership_account': partnership_account_2,
'two_factor_auth_onboard': True
},
{
'role': 'admin',
'email': 'subscriber@localhost.com',
'password': 'password',
'partnership': partnership_1,
'partnership_account': partnership_account_1,
'two_factor_auth_onboard': True
}
]
for user in users:
db.session.add(User(**user))
db.session.commit()
return db
@pytest.fixture(scope='function')
def reports(db, users):
db.session.query(ReportUserTie).delete()
db.session.query(Report).delete()
user = User.find_by_identity("admin@localhost.com")
report_params = [
{"name": "test_report"},
{'name': 'Daily Leads Report'},
{"name": "List of Interest"}
]
for report in report_params:
report_obj = Report(**report)
db.session.add(report_obj)
db.session.commit()
report_tie_params = {
'user': user,
'partnership_accounts_id': user.partnership_account_id,
'emails': ['test1@gmail.com', 'test2@gmail.com'],
'report': report_obj
}
db.session.add(ReportUserTie(**report_tie_params))
db.session.commit()
@pytest.fixture(scope="function")
def mobiles(db, users):
db.session.query(Domain).delete()
user = User.find_by_identity('admin@localhost.com')
domain_params = {
'domain_id': 'domain_id',
'name': 'domain_name',
'description': 'domain_description',
'provider': 'domain_provider',
'partnership_id': user.partnership_id,
'cloud_id': 'domain_cloud_id'
}
domain = Domain(**domain_params)
db.session.add(domain)
db.session.commit()
phonenumber_params = {
'partnership_account_id': user.partnership_account_id,
'phonenumber': '1122334455',
'local': False,
'tollfree': False,
'type': 'mobile',
'active': True,
'caller_id': False,
'friendly_name': 'mobile message 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
}
phonenumber = Phone(**phonenumber_params)
db.session.add(phonenumber)
db.session.commit()
agent_params = {
'user_id': None,
'firstname': 'tbd first name',
'lastname': 'tbd last name',
'title': 'mr',
'email': 'tbd.agent.test@buyercall.com',
'phonenumber': '1234567890',
'mobile': '1234567890',
'extension': 0,
'department': 'None',
'timezone': 'US/Central',
'partnership_account_id': user.partnership_account_id,
'all_hours': False
}
agent = Agent(**agent_params)
db.session.add(agent)
db.session.commit()
endpoint_params = {
'description': 'description',
'provider': 'provider',
'provider_id': 'provider_id',
'sip_uri': 'sip_uri',
'sip_username': 'sip_username',
'sip_password': 'sip_password',
'enabled': True,
'inbound_id': phonenumber.id,
'agent_id': agent.id,
'partnership_account_id': user.partnership_account_id,
'domain_id': domain.id,
'is_deactivated': False
}
endpoint = Endpoint(**endpoint_params)
db.session.add(endpoint)
db.session.commit()
@pytest.fixture(scope="function")
def widgets(db, users):
user = User.find_by_identity('admin@localhost.com')
phonenumber_params = {
'partnership_account_id': user.partnership_account_id,
'phonenumber': '1122334455',
'local': False,
'tollfree': False,
'type': 'mobile',
'active': True,
'caller_id': False,
'friendly_name': 'mobile message 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
}
phonenumber = Phone(**phonenumber_params)
db.session.add(phonenumber)
db.session.commit()
agent_params = {
'user_id': None,
'firstname': 'tbd first name',
'lastname': 'tbd last name',
'title': 'mr',
'email': 'tbd.agent.test@buyercall.com',
'phonenumber': '1234567890',
'mobile': '1234567890',
'extension': 0,
'department': 'None',
'timezone': 'US/Central',
'partnership_account_id': user.partnership_account_id,
'all_hours': False
}
agent = Agent(**agent_params)
db.session.add(agent)
widget_params = {
'guid': 'this is a test',
'name': 'widget name',
'enabled': True,
'partnership_account_id': user.partnership_account_id,
'email': 'testing@localhost.com',
'type': 'widget'
}
widget = Widget(**widget_params)
db.session.add(widget)
db.session.commit()