File: //home/arjun/projects/buyercall_forms/buyercall/buyercall/tests/partnership/test_views.py
from flask import url_for, json
from flask_babel import gettext as _
from buyercall.blueprints.agents.models import Agent
from buyercall.blueprints.partnership.models import Partnership, PartnershipAccount
from buyercall.blueprints.user.models import User
from buyercall.extensions import mail
from buyercall.tests.lib.util import ViewTestMixin
from buyercall.tests.lib.assertions import assert_status_with_message
class TestPartnershipViews(ViewTestMixin):
def test_accounts_logged_out(self):
"""Accounts page redirects to login page."""
response = self.client.get(url_for('partnership.accounts'))
assert_status_with_message(302, response, _('login'))
assert b'accounts' in response.data
def test_accounts_admin(self, users):
"""Accounts page redirects to settings page."""
self.login()
response = self.client.get(url_for('partnership.accounts'), follow_redirects=True)
assert_status_with_message(
200,
response,
_('Increase your sales call and marketing efforts immediately')
)
def test_accounts_partner(self):
"""Accounts page redirects to settings page."""
self.login(identity='partner@localhost.com')
response = self.client.get(url_for('partnership.accounts'))
assert_status_with_message(200, response, _('Admin - Accounts List'))
def test_company_accounts_logged_out(self):
"""Company accounts page redirects to login page."""
response = self.client.get(url_for('partnership.company_accounts'))
assert_status_with_message(302, response, _('company_accounts'))
assert b'accounts' in response.data
def test_company_accounts_admin(self, users):
"""Company accounts page redirects to settings page."""
self.login()
response = self.client.get(url_for('partnership.company_accounts'), follow_redirects=True)
assert_status_with_message(
200,
response,
_('Increase your sales call and marketing efforts immediately')
)
def test_company_accounts_partner(self):
"""Company accounts page redirects to settings page."""
self.login(identity='partner@localhost.com')
response = self.client.get(
url_for('partnership.company_accounts'),
follow_redirects=True
)
assert_status_with_message(200, response, _('Admin - Accounts List'))
def test_admins_page_logged_out(self):
"""Admin page redirects to login page."""
response = self.client.get(url_for('partnership.admins'))
assert_status_with_message(302, response, _('login'))
assert b'all_admins' in response.data
def test_admin_page_admin(self, users):
"""Admin page redirects to settings page."""
self.login()
response = self.client.get(url_for('partnership.admins'), follow_redirects=True)
assert_status_with_message(
200,
response,
_('Increase your sales call and marketing efforts immediately')
)
def test_admin_page_partner(self):
"""Admin page renders successfully."""
self.login(identity='partner@localhost.com')
response = self.client.get(
url_for('partnership.admins'),
follow_redirects=True
)
assert_status_with_message(200, response, _('Admin - Accounts List'))
def test_account_admins_logged_out(self):
"""Account admins page redirects to login page."""
response = self.client.get(url_for('partnership.account_admins', id=1))
assert_status_with_message(302, response, _('login'))
assert b'accounts' in response.data
def test_account_admins(self):
"""Accounts Admin page renders successfully."""
self.login(identity='partner@localhost.com')
account = PartnershipAccount.query.first()
response = self.client.get(
url_for('partnership.account_admins', id=account.id),
follow_redirects=True
)
assert_status_with_message(200, response, _('Admin - Account Users List'))
def test_account_edit_logged_out(self):
"""Accounts edit page redirects to login page."""
response = self.client.get(url_for('partnership.account_edit', id=1))
assert_status_with_message(302, response, _('login'))
assert b'account' in response.data
assert b'edit' in response.data
def test_account_edit_page(self):
"""Accounts edit page renders successfully."""
self.login(identity='partner@localhost.com')
account = PartnershipAccount.query.first()
response = self.client.get(
url_for('partnership.account_edit', id=account.id),
follow_redirects=True
)
assert_status_with_message(200, response, _('Partnership Account Edit'))
def test_account_edit(self):
"""Accounts editing is successful."""
self.login(identity='partner@localhost.com')
params = {
"name": "edited_name"
}
account = PartnershipAccount.query.first()
response = self.client.post(
url_for('partnership.account_edit', id=account.id),
data=params,
follow_redirects=True
)
edited_account = PartnershipAccount.query.filter(PartnershipAccount.id == account.id).first()
assert edited_account.name == 'edited_name'
assert_status_with_message(200, response, _('Admin - Accounts List'))