import logging
logging.basicConfig(level=logging.INFO)
from app import create_app, db
app = create_app()
c = app.test_client()
c.post('/auth/login', data={'email':'admin@vapolyx.gg','password':'Admin@123'}, follow_redirects=False)

from flask import template_rendered
captured = {}
@template_rendered.connect_via(app)
def grab_ctx(sender, template, context, **kw):
    if template.name and 'webapp/base.html' in str(template.name):
        captured['header_teams'] = context.get('header_teams')
        print('BASE TEMPLATE RENDERED, header_teams:', captured['header_teams'])

r = c.get('/home')
print('home:', r.status_code)
print('captured header_teams:', captured.get('header_teams'))
html = r.data.decode('utf-8','replace')
print('YOUR TEAM count:', html.count('YOUR TEAM'))
print('manage teams:', 'Manage Teams' in html)
# count team-drop-item links (not manage teams)
import re
links = re.findall(r'class="team-drop-item"', html)
print('team-drop-item links:', len(links))
