pharmacy dashboard
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import requests
|
||||
|
||||
s = requests.Session()
|
||||
|
||||
# 1. Login as admin 'dmh'
|
||||
login = s.post('http://127.0.0.1:5000/login', json={'username': 'dmh', 'password': 'dmh123'})
|
||||
assert login.status_code == 200, f"Admin login failed: {login.text}"
|
||||
print("✅ Admin login successful")
|
||||
|
||||
# 2. Check /dashboard for Admin Panel button above and in sidebar
|
||||
dash = s.get('http://127.0.0.1:5000/dashboard')
|
||||
dash_html = dash.text
|
||||
assert 'Admin Panel' in dash_html, "Admin Panel button missing in topbar actions"
|
||||
assert '/admin' in dash_html, "Link to /admin missing in dashboard"
|
||||
assert 'topbar-actions' in dash_html
|
||||
print("✅ Verified: 'Admin Panel' button is prominently rendered above on /dashboard for admin")
|
||||
|
||||
# 3. Check /admin (Admin Portal)
|
||||
admin_res = s.get('http://127.0.0.1:5000/admin')
|
||||
assert admin_res.status_code == 200, f"Admin portal failed: {admin_res.status_code}"
|
||||
admin_html = admin_res.text
|
||||
|
||||
assert '/static/logo.png' in admin_html, "DMH logo missing in admin portal"
|
||||
assert 'Back to Pharmacy Hub' in admin_html, "Back button missing in admin portal"
|
||||
assert 'Total Invoices Processed' in admin_html, "Stat 1 missing"
|
||||
assert 'Pending PO Numbers' in admin_html, "Stat 2 missing"
|
||||
assert 'Pending Item Codes' in admin_html, "Stat 3 missing"
|
||||
assert 'Drug Master Catalog' in admin_html, "Stat 4 missing"
|
||||
assert 'Registered Accounts' in admin_html, "Stat 5 missing"
|
||||
assert 'id="addUserModal"' in admin_html, "Add user modal missing"
|
||||
assert 'id="resetPasswordModal"' in admin_html, "Reset password modal missing"
|
||||
assert 'id="codeModal"' in admin_html, "Code modal missing"
|
||||
assert 'System & VPS' not in admin_html, "System & VPS section should be removed"
|
||||
assert 'testIntegrations' not in admin_html, "testIntegrations should be removed"
|
||||
assert 'id="analytics"' in admin_html, "Analytics tab missing"
|
||||
assert 'id="users"' in admin_html, "Users tab missing"
|
||||
assert 'id="catalog"' in admin_html, "Catalog tab missing"
|
||||
assert 'id="quality"' in admin_html, "Quality tab missing"
|
||||
print("✅ Verified: Redesigned Admin Portal HTML contains DMH logo, Back button, 5 stat cards, 4 tabs (System & VPS completely removed), and modern modals")
|
||||
|
||||
# 4. Test password reset endpoint
|
||||
reset_res = s.post('http://127.0.0.1:5000/api/admin/reset-password', json={
|
||||
'username': 'dmh9',
|
||||
'new_password': 'NewPassword123!'
|
||||
})
|
||||
assert reset_res.status_code == 200, f"Password reset failed: {reset_res.text}"
|
||||
print("✅ Verified: /api/admin/reset-password works seamlessly")
|
||||
|
||||
# Test logging in with new password
|
||||
s_user = requests.Session()
|
||||
login_new = s_user.post('http://127.0.0.1:5000/login', json={'username': 'dmh9', 'password': 'NewPassword123!'})
|
||||
assert login_new.status_code == 200, f"Login with new password failed: {login_new.text}"
|
||||
print("✅ Verified: Staff user logged in with newly reset password")
|
||||
|
||||
# 5. Check regular staff user cannot access /admin
|
||||
staff_dash = s_user.get('http://127.0.0.1:5000/dashboard').text
|
||||
assert 'Admin Panel' not in staff_dash, "Staff should NOT see Admin Panel button in topbar"
|
||||
staff_admin_try = s_user.get('http://127.0.0.1:5000/admin', allow_redirects=False)
|
||||
assert staff_admin_try.status_code == 302, f"Staff should be redirected with 302, got {staff_admin_try.status_code}"
|
||||
assert '/login' in staff_admin_try.headers.get('Location', '')
|
||||
print("✅ Verified: Regular staff cannot see Admin button and is redirected away from /admin (302 -> /login)")
|
||||
|
||||
print("\n🎉 ALL ADMIN VERIFICATION TESTS PASSED 100%!")
|
||||
Reference in New Issue
Block a user