import pytest import asyncio from playwright.async_api import expect @pytest.mark.asyncio class TestAdmin: async def test_01_admin_login(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Admin should see admin nav links await expect(page.locator('a.nav-link[data-view="admin"]')).to_be_visible() await expect(page.locator('a.nav-link[data-view="admin-billing"]')).to_be_visible() async def test_02_navigate_to_admin_dashboard(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin"]') await page.wait_for_timeout(1000) await expect(page.locator('admin-dashboard')).to_be_visible() async def test_03_view_user_management(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin"]') await page.wait_for_timeout(1000) # Should show user list await expect(page.locator('.user-list')).to_be_visible() await expect(page.locator('text=e2etestuser')).to_be_visible() async def test_04_view_system_statistics(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin"]') await page.wait_for_timeout(1000) # Should show system stats await expect(page.locator('.system-stats')).to_be_visible() await expect(page.locator('.stat-item')).to_be_visible() async def test_05_manage_user_permissions(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin"]') await page.wait_for_timeout(1000) # Click on user to manage await page.click('.user-item:has-text("e2etestuser")') await page.wait_for_timeout(500) # Should show user details modal await expect(page.locator('.user-details-modal')).to_be_visible() # Change permissions await page.select_option('select[name="role"]', 'moderator') await page.click('button:has-text("Save")') await page.wait_for_timeout(1000) async def test_06_view_storage_usage(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin"]') await page.wait_for_timeout(1000) # Should show storage usage await expect(page.locator('.storage-usage')).to_be_visible() async def test_07_navigate_to_admin_billing(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin-billing"]') await page.wait_for_timeout(1000) await expect(page.locator('admin-billing')).to_be_visible() async def test_08_view_billing_statistics(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin-billing"]') await page.wait_for_timeout(1000) # Should show billing stats await expect(page.locator('.billing-stats')).to_be_visible() async def test_09_manage_pricing(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin-billing"]') await page.wait_for_timeout(1000) # Click pricing management await page.click('button:has-text("Manage Pricing")') await page.wait_for_timeout(500) # Should show pricing form await expect(page.locator('.pricing-form')).to_be_visible() # Update a price await page.fill('input[name="storage_per_gb_month"]', '0.005') await page.click('button:has-text("Update")') await page.wait_for_timeout(1000) async def test_10_generate_invoice(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'adminuser') await page.fill('#login-form input[name="password"]', 'adminpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="admin-billing"]') await page.wait_for_timeout(1000) # Click generate invoice await page.click('button:has-text("Generate Invoice")') await page.wait_for_timeout(500) # Select user await page.select_option('select[name="user"]', 'e2etestuser') await page.click('button:has-text("Generate")') await page.wait_for_timeout(1000) # Should show success message await expect(page.locator('text=Invoice generated')).to_be_visible()