File: //home/arjun/projects/buyercall_forms/buyercall/buyercall/tests/admin/test_models.py
import pytest
from flask_login import current_user
from buyercall.blueprints.admin.models import Dashboard
class TestDashboard(object):
@pytest.mark.usefixtures("admin_authenticated_request")
def test_group_and_count_coupons(self, users):
group_and_count_coupons = Dashboard.group_and_count_coupons()
if group_and_count_coupons is not None:
if group_and_count_coupons[0] == 1 and group_and_count_coupons[1] == 2 and group_and_count_coupons[2] == 50:
assert True
else:
assert False
else:
assert False
@pytest.mark.usefixtures("partner_authenticated_request")
def test_partner_group_and_count_plans(self, users):
group_and_count_plans = Dashboard.group_and_count_plans(current_user)
if group_and_count_plans is not None:
query = group_and_count_plans['query']
total = group_and_count_plans['total']
if total == 0 and len(query) == 0:
assert True
else:
assert False
@pytest.mark.usefixtures("sysadmin_authenticated_request")
def test_sysadmin_group_and_count_plans(self, users):
group_and_count_plans = Dashboard.group_and_count_plans(current_user)
if group_and_count_plans is not None:
query = group_and_count_plans['query']
total = group_and_count_plans['total']
if total == 2 and len(query) == 2 and query[0][0] == 1 and query[0][1] == 'bronze':
assert True
else:
assert False
def test_group_and_count_users(self):
group_and_count_users = Dashboard.group_and_count_users()
if group_and_count_users['total'] == 7:
failed = False
for user_role in group_and_count_users['query']:
if user_role[1] == 'partner':
if user_role[0] != 2:
failed = True
elif user_role[1] == 'member':
if user_role[0] != 1:
failed = True
elif user_role[1] == 'admin':
if user_role[0] != 3:
failed = True
elif user_role[1] == 'sysadmin':
if user_role[0] != 1:
failed = True
if not failed:
assert True
else:
assert False
else:
assert False
@pytest.mark.usefixtures("admin_authenticated_request")
def test_admin_group_and_count_issues(self, users, issues):
group_and_count_issues = Dashboard.group_and_count_issues(current_user)
if group_and_count_issues['total'] == 2 and group_and_count_issues['query'][0][0] == 2 and\
group_and_count_issues['query'][0][1] == 'unread':
assert True
else:
assert False
@pytest.mark.usefixtures("partner_authenticated_request")
def test_partner_group_and_count_issues(self, users, issues):
group_and_count_issues = Dashboard.group_and_count_issues(current_user)
if group_and_count_issues['total'] == 2 and group_and_count_issues['query'][0][0] == 2 and\
group_and_count_issues['query'][0][1] == 'unread':
assert True
else:
assert False
@pytest.mark.skip(reason="sub method of methods tested above")
def test_group_and_count(self, users):
# filter_exp = User.partnership_id == partnership_account_id
# group_and_count_users = Dashboard.group_and_count(User, User.role, filter_exp)
assert True