mockstack 0.11.2__tar.gz → 0.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. {mockstack-0.11.2 → mockstack-0.12.0}/PKG-INFO +1 -1
  2. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/routers/catchall.py +3 -1
  3. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/strategies/test_proxyrules.py +22 -1
  4. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/test_rules.py +41 -11
  5. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack.egg-info/PKG-INFO +1 -1
  6. {mockstack-0.11.2 → mockstack-0.12.0}/.dockerignore +0 -0
  7. {mockstack-0.11.2 → mockstack-0.12.0}/.env.example +0 -0
  8. {mockstack-0.11.2 → mockstack-0.12.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  9. {mockstack-0.11.2 → mockstack-0.12.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  10. {mockstack-0.11.2 → mockstack-0.12.0}/.github/workflows/ci.yml +0 -0
  11. {mockstack-0.11.2 → mockstack-0.12.0}/.github/workflows/publish-docs.yml +0 -0
  12. {mockstack-0.11.2 → mockstack-0.12.0}/.github/workflows/publish-to-pypi.yml +0 -0
  13. {mockstack-0.11.2 → mockstack-0.12.0}/.gitignore +0 -0
  14. {mockstack-0.11.2 → mockstack-0.12.0}/.pre-commit-config.yaml +0 -0
  15. {mockstack-0.11.2 → mockstack-0.12.0}/CODE_OF_CONDUCT.md +0 -0
  16. {mockstack-0.11.2 → mockstack-0.12.0}/CONTRIBUTING.md +0 -0
  17. {mockstack-0.11.2 → mockstack-0.12.0}/Dockerfile +0 -0
  18. {mockstack-0.11.2 → mockstack-0.12.0}/LICENSE +0 -0
  19. {mockstack-0.11.2 → mockstack-0.12.0}/README.md +0 -0
  20. {mockstack-0.11.2 → mockstack-0.12.0}/SECURITY.md +0 -0
  21. {mockstack-0.11.2 → mockstack-0.12.0}/docker-entrypoint.sh +0 -0
  22. {mockstack-0.11.2 → mockstack-0.12.0}/docs/assets/favicon.ico +0 -0
  23. {mockstack-0.11.2 → mockstack-0.12.0}/docs/assets/logo.png +0 -0
  24. {mockstack-0.11.2 → mockstack-0.12.0}/docs/assets/mockstack.png +0 -0
  25. {mockstack-0.11.2 → mockstack-0.12.0}/docs/configuration.md +0 -0
  26. {mockstack-0.11.2 → mockstack-0.12.0}/docs/ollama.md +0 -0
  27. {mockstack-0.11.2 → mockstack-0.12.0}/docs/strategies/base.md +0 -0
  28. {mockstack-0.11.2 → mockstack-0.12.0}/docs/strategies/filefixtures.md +0 -0
  29. {mockstack-0.11.2 → mockstack-0.12.0}/docs/strategies/proxyrules.md +0 -0
  30. {mockstack-0.11.2 → mockstack-0.12.0}/examples/filefixtures-with-templates/.env.example +0 -0
  31. {mockstack-0.11.2 → mockstack-0.12.0}/examples/filefixtures-with-templates/README.md +0 -0
  32. {mockstack-0.11.2 → mockstack-0.12.0}/examples/filefixtures-with-templates/templates/servicename-api-v1-items.j2 +0 -0
  33. {mockstack-0.11.2 → mockstack-0.12.0}/examples/filefixtures-with-templates/templates/servicename2-api-v2-user.533ec889-7c68-45c8-b21e-4a7e455d1234.j2 +0 -0
  34. {mockstack-0.11.2 → mockstack-0.12.0}/examples/llm/README.md +0 -0
  35. {mockstack-0.11.2 → mockstack-0.12.0}/examples/llm/mockstack-langchain-example.ipynb +0 -0
  36. {mockstack-0.11.2 → mockstack-0.12.0}/examples/llm/templates/ollama-openai-v1-chat-completions.j2 +0 -0
  37. {mockstack-0.11.2 → mockstack-0.12.0}/examples/llm/templates/openai-v1-chat-completions.j2 +0 -0
  38. {mockstack-0.11.2 → mockstack-0.12.0}/examples/llm/templates/openai-v1-deployments-gpt-4o-chat-completions.j2 +0 -0
  39. {mockstack-0.11.2 → mockstack-0.12.0}/examples/proxyrules-with-rules-file/.env.example +0 -0
  40. {mockstack-0.11.2 → mockstack-0.12.0}/examples/proxyrules-with-rules-file/README.md +0 -0
  41. {mockstack-0.11.2 → mockstack-0.12.0}/examples/proxyrules-with-rules-file/rules.yml +0 -0
  42. {mockstack-0.11.2 → mockstack-0.12.0}/mkdocs.yml +0 -0
  43. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/__init__.py +0 -0
  44. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/config.py +0 -0
  45. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/constants.py +0 -0
  46. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/display.py +0 -0
  47. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/exceptions.py +0 -0
  48. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/identifiers.py +0 -0
  49. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/intent.py +0 -0
  50. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/lifespan.py +0 -0
  51. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/llm/__init__.py +0 -0
  52. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/llm/ollama.py +0 -0
  53. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/main.py +0 -0
  54. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/middleware.py +0 -0
  55. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/routers/__init__.py +0 -0
  56. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/routers/homepage.py +0 -0
  57. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/rules.py +0 -0
  58. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/strategies/__init__.py +0 -0
  59. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/strategies/base.py +0 -0
  60. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/strategies/create_mixin.py +0 -0
  61. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/strategies/factory.py +0 -0
  62. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/strategies/filefixtures.py +0 -0
  63. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/strategies/proxyrules.py +0 -0
  64. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/telemetry.py +0 -0
  65. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/templating.py +0 -0
  66. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/__init__.py +0 -0
  67. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/conftest.py +0 -0
  68. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/fixtures/__init__.py +0 -0
  69. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/fixtures/proxyrules.yml +0 -0
  70. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/fixtures/templates/__init__.py +0 -0
  71. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/fixtures/templates/example-template.j2 +0 -0
  72. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/llm/__init__.py +0 -0
  73. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/llm/test_ollama.py +0 -0
  74. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/routers/__init__.py +0 -0
  75. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/routers/test_catchall.py +0 -0
  76. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/routers/test_homepage.py +0 -0
  77. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/strategies/__init__.py +0 -0
  78. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/strategies/test_create_mixin.py +0 -0
  79. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/strategies/test_filefixtures.py +0 -0
  80. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/test_display.py +0 -0
  81. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/test_identifiers.py +0 -0
  82. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/test_intent.py +0 -0
  83. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/test_middleware.py +0 -0
  84. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/test_telemetry.py +0 -0
  85. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack/tests/test_templating.py +0 -0
  86. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack.egg-info/SOURCES.txt +0 -0
  87. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack.egg-info/dependency_links.txt +0 -0
  88. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack.egg-info/entry_points.txt +0 -0
  89. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack.egg-info/requires.txt +0 -0
  90. {mockstack-0.11.2 → mockstack-0.12.0}/mockstack.egg-info/top_level.txt +0 -0
  91. {mockstack-0.11.2 → mockstack-0.12.0}/pyproject.toml +0 -0
  92. {mockstack-0.11.2 → mockstack-0.12.0}/setup.cfg +0 -0
  93. {mockstack-0.11.2 → mockstack-0.12.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mockstack
3
- Version: 0.11.2
3
+ Version: 0.12.0
4
4
  Summary: An API mocking workhorse
5
5
  Author-email: Adam Ever-Hadani <mockstack.contact@gmail.com>
6
6
  License-Expression: MIT
@@ -8,7 +8,9 @@ from mockstack.config import Settings
8
8
  def catchall_router_provider(app: FastAPI, settings: Settings) -> None:
9
9
  """Create the catch-all routes for the mockstack app."""
10
10
 
11
- @app.route("/{full_path:path}", methods=["GET", "PATCH", "POST", "PUT", "DELETE"])
11
+ @app.api_route(
12
+ "/{full_path:path}", methods=["GET", "PATCH", "POST", "PUT", "DELETE"]
13
+ )
12
14
  async def catch_all(request: Request):
13
15
  """Catch all requests and delegate to the strategy."""
14
16
  return await app.state.strategy.apply(request)
@@ -7,7 +7,7 @@ import httpx
7
7
  import pytest
8
8
  from fastapi import Request, status
9
9
  from fastapi.responses import RedirectResponse
10
- from starlette.datastructures import Headers
10
+ from starlette.datastructures import Headers, URL
11
11
 
12
12
  from mockstack.constants import ProxyRulesRedirectVia
13
13
  from mockstack.strategies.proxyrules import (
@@ -79,6 +79,27 @@ async def test_proxy_rules_strategy_apply(settings, span):
79
79
  assert response.headers["location"] == "/projects/123"
80
80
 
81
81
 
82
+ @pytest.mark.asyncio
83
+ async def test_proxy_rules_strategy_apply_with_fragment(settings, span):
84
+ """Test applying a rule to a request with URL fragment."""
85
+ strategy = ProxyRulesStrategy(settings)
86
+ request = Request(
87
+ scope={
88
+ "type": "http",
89
+ "method": "GET",
90
+ "path": "/api/v1/projects/123",
91
+ "query_string": b"",
92
+ "headers": [],
93
+ }
94
+ )
95
+ # Set URL with fragment (fragments are client-side only in HTTP, but we test the logic)
96
+ request._url = URL("http://testserver/api/v1/projects/123#section")
97
+ request.state.span = span
98
+ response = await strategy.apply(request)
99
+ assert isinstance(response, RedirectResponse)
100
+ assert response.headers["location"] == "/projects/123%23section"
101
+
102
+
82
103
  @pytest.mark.asyncio
83
104
  async def test_proxy_rules_strategy_apply_no_match(settings, span):
84
105
  """Test applying strategy when no rule matches."""
@@ -2,6 +2,7 @@
2
2
 
3
3
  import pytest
4
4
  from fastapi import Request
5
+ from starlette.datastructures import URL
5
6
 
6
7
  from mockstack.rules import Rule, TemplateRuleResult, URLRuleResult
7
8
 
@@ -79,34 +80,63 @@ def test_rule_matches_with_method(pattern, path, method, expected):
79
80
 
80
81
 
81
82
  @pytest.mark.parametrize(
82
- "pattern,replacement,path,expected_url",
83
+ "pattern,replacement,path,fragment,expected_url",
83
84
  [
84
85
  (
85
86
  r"/api/v1/projects/(\d+)",
86
87
  r"/projects/\1",
87
88
  "/api/v1/projects/123",
89
+ None,
88
90
  "/projects/123",
89
91
  ),
90
92
  (
91
93
  r"/api/v1/users/([^/]+)",
92
94
  r"/users/\1",
93
95
  "/api/v1/users/john",
96
+ None,
94
97
  "/users/john",
95
98
  ),
99
+ (
100
+ r"/api/v1/projects/(\d+)",
101
+ r"/projects/\1",
102
+ "/api/v1/projects/123",
103
+ "section",
104
+ "/projects/123%23section",
105
+ ),
106
+ (
107
+ r"/api/v1/users/([^/]+)",
108
+ r"/users/\1",
109
+ "/api/v1/users/john",
110
+ "profile",
111
+ "/users/john%23profile",
112
+ ),
113
+ (
114
+ r"/api/v1/projects/(\d+)",
115
+ r"/projects/\1",
116
+ "/api/v1/projects/456",
117
+ "top",
118
+ "/projects/456%23top",
119
+ ),
96
120
  ],
97
121
  )
98
- def test_rule_apply(pattern, replacement, path, expected_url):
122
+ def test_rule_apply(pattern, replacement, path, fragment, expected_url):
99
123
  """Test the rule application logic."""
100
124
  rule = Rule(pattern=pattern, replacement=replacement)
101
- request = Request(
102
- scope={
103
- "type": "http",
104
- "method": "GET",
105
- "path": path,
106
- "query_string": b"",
107
- "headers": [],
108
- }
109
- )
125
+ scope = {
126
+ "type": "http",
127
+ "method": "GET",
128
+ "path": path,
129
+ "query_string": b"",
130
+ "headers": [],
131
+ }
132
+ request = Request(scope=scope)
133
+
134
+ # If fragment is specified, we need to manually set the URL with the fragment
135
+ # since fragments are not part of standard HTTP requests (they're client-side)
136
+ if fragment:
137
+ url_with_fragment = f"http://testserver{path}#{fragment}"
138
+ request._url = URL(url_with_fragment)
139
+
110
140
  result = rule.apply(request)
111
141
  assert isinstance(result, URLRuleResult)
112
142
  assert result.get_result_type() == "url"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mockstack
3
- Version: 0.11.2
3
+ Version: 0.12.0
4
4
  Summary: An API mocking workhorse
5
5
  Author-email: Adam Ever-Hadani <mockstack.contact@gmail.com>
6
6
  License-Expression: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes