Skip to content

Commit 82fd76a

Browse files
committed
autoflake8 black isort
Signed-off-by: Mihai Criveti <[email protected]>
1 parent 7545fb3 commit 82fd76a

11 files changed

+70
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
debug_login_page.png
12
docs/pstats.png
23
mcp.prof
34
mcp.pstats

Makefile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@
1010
# help: 🐍 MCP CONTEXT FORGE (An enterprise-ready Model Context Protocol Gateway)
1111
#
1212
# ──────────────────────────────────────────────────────────────────────────
13-
# Project variables
13+
SHELL := /bin/bash
14+
.SHELLFLAGS := -eu -o pipefail -c
15+
1416
# Read values from .env.make
1517
-include .env.make
1618

19+
# Project variables
1720
PROJECT_NAME = mcpgateway
1821
DOCS_DIR = docs
1922
HANDSDOWN_PARAMS = -o $(DOCS_DIR)/ -n $(PROJECT_NAME) --name "MCP Gateway" --cleanup
2023

2124
TEST_DOCS_DIR ?= $(DOCS_DIR)/docs/test
2225

26+
# -----------------------------------------------------------------------------
2327
# Project-wide clean-up targets
28+
# -----------------------------------------------------------------------------
2429
DIRS_TO_CLEAN := __pycache__ .pytest_cache .tox .ruff_cache .pyre .mypy_cache .pytype \
2530
dist build site .eggs *.egg-info .cache htmlcov certs \
2631
$(VENV_DIR) $(VENV_DIR).sbom $(COVERAGE_DIR) \
@@ -41,13 +46,21 @@ METRICS_MD ?= $(DOCS_DIR)/docs/metrics/loc.md
4146

4247
# -----------------------------------------------------------------------------
4348
# Container resource configuration
49+
# -----------------------------------------------------------------------------
4450
CONTAINER_MEMORY = 2048m
4551
CONTAINER_CPUS = 2
4652

4753
# Virtual-environment variables
4854
VENVS_DIR := $(HOME)/.venv
4955
VENV_DIR := $(VENVS_DIR)/$(PROJECT_NAME)
5056

57+
# -----------------------------------------------------------------------------
58+
# OS Specific
59+
# -----------------------------------------------------------------------------
60+
# The -r flag for xargs is GNU-specific and will fail on macOS
61+
XARGS_FLAGS := $(shell [ "$$(uname)" = "Darwin" ] && echo "" || echo "-r")
62+
63+
5164
# =============================================================================
5265
# 📖 DYNAMIC HELP
5366
# =============================================================================
@@ -98,10 +111,7 @@ venv:
98111

99112
.PHONY: activate
100113
activate:
101-
@echo -e "💡 Enter the venv using:\n . $(VENV_DIR)/bin/activate\n"
102-
@. $(VENV_DIR)/bin/activate
103-
@echo "export MYPY_CACHE_DIR=/tmp/cache/mypy/$(PROJECT_NAME)"
104-
@echo "export PYTHONPYCACHEPREFIX=/tmp/cache/$(PROJECT_NAME)"
114+
@echo "💡 Enter the venv using:\n. $(VENV_DIR)/bin/activate\n"
105115

106116
.PHONY: install
107117
install: venv
@@ -225,7 +235,7 @@ coverage:
225235
--md-report --md-report-output=$(DOCS_DIR)/docs/test/unittest.md \
226236
--dist loadgroup -n 8 -rA --cov-append --capture=tee-sys -v \
227237
--durations=120 --doctest-modules app/ --cov-report=term \
228-
--cov=app --ignore=test.py tests/ || true"
238+
--cov=mcpgateway --ignore=test.py tests/ || true"
229239
@printf '\n## Coverage report\n\n' >> $(DOCS_DIR)/docs/test/unittest.md
230240
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
231241
coverage report --format=markdown -m --no-skip-covered \
@@ -1319,7 +1329,7 @@ image-clean:
13191329
@echo "🧹 Removing all $(IMAGE_BASE) images..."
13201330
@$(CONTAINER_RUNTIME) images --format "{{.Repository}}:{{.Tag}}" | \
13211331
grep -E "(localhost/)?$(IMAGE_BASE)" | \
1322-
xargs -r $(CONTAINER_RUNTIME) rmi -f 2>/dev/null || true
1332+
xargs $(XARGS_FLAGS) $(CONTAINER_RUNTIME) rmi -f 2>/dev/null
13231333
@echo "✅ Images cleaned"
13241334

13251335
# Fix image naming issues

playwright.config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# -*- coding: utf-8 -*-
2+
# Standard
23
import os
4+
5+
# Third-Party
36
from playwright.sync_api import Playwright
47

8+
59
def pytest_configure(config):
610
"""Configure Playwright for pytest runs."""
711
os.environ.setdefault("PLAYWRIGHT_BROWSERS_PATH", os.path.expanduser("~/.cache/ms-playwright"))

tests/playwright/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
# Standard
88
import base64
99
import os
10+
import re
1011
from typing import Generator
1112

1213
# Third-Party
1314
from playwright.sync_api import APIRequestContext, Page, Playwright
1415
import pytest
15-
import re
16-
from playwright.sync_api import Page, Browser, BrowserContext
1716

1817
# Get configuration from environment
1918
BASE_URL = os.getenv("TEST_BASE_URL", "http://localhost:8000")
@@ -78,6 +77,7 @@ def authenticated_page(page: Page) -> Page:
7877
"""Alias for page fixture."""
7978
return page
8079

80+
8181
@pytest.fixture
8282
def admin_page(page: Page):
8383
"""Provide a logged-in admin page for UI tests."""
@@ -87,10 +87,13 @@ def admin_page(page: Page):
8787
page.wait_for_url(re.compile(r".*admin"))
8888
return page
8989

90+
9091
@pytest.fixture
9192
def test_tool_data():
9293
"""Provide test data for tool creation."""
94+
# Standard
9395
import uuid
96+
9497
unique_id = uuid.uuid4()
9598
return {
9699
"name": f"test-api-tool-{unique_id}",
@@ -99,9 +102,10 @@ def test_tool_data():
99102
"integrationType": "REST",
100103
"requestType": "GET",
101104
"headers": '{"Authorization": "Bearer test-token"}',
102-
"input_schema": '{"type": "object", "properties": {"query": {"type": "string"}}}'
105+
"input_schema": '{"type": "object", "properties": {"query": {"type": "string"}}}',
103106
}
104107

108+
105109
@pytest.fixture(autouse=True)
106110
def setup_test_environment(page: Page):
107111
"""Set viewport and default timeout for consistent UI tests."""

tests/playwright/entities/test_tools.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# -*- coding: utf-8 -*-
2-
import pytest
3-
from playwright.sync_api import Page, expect
2+
# Third-Party
3+
from playwright.sync_api import expect, Page
4+
45

56
class TestToolsCRUD:
67
"""CRUD tests for Tools entity in MCP Gateway Admin UI.
78
89
Examples:
910
pytest tests/playwright/entities/test_tools.py
1011
"""
12+
1113
def test_create_new_tool(self, page: Page, test_tool_data, admin_page):
1214
"""Test creating a new tool with debug screenshots and waits."""
1315
# Go to the Global Tools tab (if not already there)
1416
page.click('[data-testid="tools-tab"]')
1517

1618
# Wait for the tools panel to be visible
17-
page.wait_for_selector('#tools-panel:not(.hidden)')
19+
page.wait_for_selector("#tools-panel:not(.hidden)")
1820

1921
# Add a small delay to ensure the UI has time to update
2022
page.wait_for_timeout(500)
@@ -41,7 +43,7 @@ def test_delete_tool(self, page: Page, test_tool_data, admin_page):
4143
page.click('[data-testid="tools-tab"]')
4244

4345
# Wait for the tools panel to be visible
44-
page.wait_for_selector('#tools-panel:not(.hidden)')
46+
page.wait_for_selector("#tools-panel:not(.hidden)")
4547

4648
# Create tool first
4749
page.locator('#add-tool-form [name="name"]').fill(test_tool_data["name"])

tests/playwright/test_admin_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"""Test cases for admin UI."""
33

44
# Third-Party
5-
import pytest
65
from playwright.sync_api import expect, Page
6+
import pytest
77

88
# Local
99
from .pages.admin_page import AdminPage

tests/playwright/test_api_endpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"""Test API endpoints through UI interactions."""
33

44
# Third-Party
5-
import pytest
65
from playwright.sync_api import APIRequestContext, expect, Page
6+
import pytest
77

88

99
class TestAPIEndpoints:

tests/playwright/test_api_integration.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
# -*- coding: utf-8 -*-
2+
# Third-Party
3+
from playwright.sync_api import APIRequestContext, expect, Page
24
import pytest
3-
from playwright.sync_api import Page, expect, APIRequestContext
5+
46

57
class TestAPIIntegration:
68
"""API integration tests for MCP protocol and REST endpoints.
79
810
Examples:
911
pytest tests/playwright/test_api_integration.py
1012
"""
13+
1114
@pytest.mark.skip(reason="Temporarily disabled for demonstration purposes")
1215
def test_should_handle_mcp_protocol_requests(self, page: Page, admin_page):
1316
"""Test MCP protocol API integration via UI."""
1417
api_calls = []
18+
1519
def handle_request(route):
1620
api_calls.append(route.request.url)
1721
route.continue_()
22+
1823
page.route("/api/mcp/**", handle_request)
1924
page.click("#tab-tools")
2025
page.wait_for_selector("#tools-panel")
@@ -33,17 +38,10 @@ def test_mcp_initialize_endpoint(self, page: Page, request: APIRequestContext, a
3338
cookies = page.context.cookies()
3439
jwt_cookie = next((c for c in cookies if c["name"] == "jwt_token"), None)
3540
assert jwt_cookie is not None
36-
response = request.post("/api/mcp/initialize",
41+
response = request.post(
42+
"/api/mcp/initialize",
3743
headers={"Cookie": f"jwt_token={jwt_cookie['value']}"},
38-
data={
39-
"jsonrpc": "2.0",
40-
"method": "initialize",
41-
"params": {
42-
"protocolVersion": "2025-03-26",
43-
"capabilities": {}
44-
},
45-
"id": 1
46-
}
44+
data={"jsonrpc": "2.0", "method": "initialize", "params": {"protocolVersion": "2025-03-26", "capabilities": {}}, "id": 1},
4745
)
4846
assert response.ok
4947
data = response.json()

tests/playwright/test_auth.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# -*- coding: utf-8 -*-
2+
# Standard
23
import os
34
import re
4-
import pytest
5+
6+
# Third-Party
57
from playwright.sync_api import expect
68

79
BASE_URL = os.getenv("TEST_BASE_URL", "http://localhost:8000")
810
BASIC_AUTH_USER = os.getenv("BASIC_AUTH_USER", "admin")
911
BASIC_AUTH_PASSWORD = os.getenv("BASIC_AUTH_PASSWORD", "changeme")
1012

13+
1114
class TestAuthentication:
1215
"""Authentication tests for MCP Gateway Admin UI.
1316
@@ -16,6 +19,7 @@ class TestAuthentication:
1619
Examples:
1720
pytest tests/playwright/test_auth.py
1821
"""
22+
1923
def test_should_login_with_valid_credentials(self, browser):
2024
"""Test successful access with valid HTTP Basic Auth credentials."""
2125
context = browser.new_context(
@@ -27,7 +31,7 @@ def test_should_login_with_valid_credentials(self, browser):
2731
page = context.new_page()
2832
# Go directly to admin - HTTP Basic Auth handles authentication
2933
page.goto(f"{BASE_URL}/admin")
30-
page.screenshot(path="debug_login_page.png")
34+
#page.screenshot(path="debug_login_page.png")
3135

3236
# Verify we successfully accessed the admin page
3337
expect(page).to_have_url(re.compile(r".*admin"))

tests/playwright/test_htmx_interactions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# -*- coding: utf-8 -*-
2-
import re
2+
# Third-Party
3+
from playwright.sync_api import expect, Page
34
import pytest
4-
from playwright.sync_api import Page, expect
5+
56

67
class TestHTMXInteractions:
78
"""HTMX and UI interaction tests for MCP Gateway Admin UI.
89
910
Examples:
1011
pytest tests/playwright/test_htmx_interactions.py
1112
"""
13+
1214
@pytest.fixture(autouse=True)
1315
def setup(self, admin_page):
1416
"""Login before each test."""
@@ -48,6 +50,8 @@ def test_htmx_polling_updates(self, page: Page, admin_page):
4850
page.wait_for_selector("#servers-table")
4951
# Wait for polling (simulate with sleep or wait for content change)
5052
# This is a placeholder; in real test, use a more robust polling check
53+
# Standard
5154
import time
55+
5256
time.sleep(2)
5357
expect(page.locator("#servers-table")).to_be_visible()

0 commit comments

Comments
 (0)