-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix double-escaping of the curl and Python example code (#709)
* Fix double-escaping of the curl and Python example code These code fragments are escaped when they are substituted into the `silk/request.html` template, so they should not be escaped an extra time when they are constructed. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1cb4623
commit 508ba34
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import shlex | ||
from unittest import TestCase | ||
|
||
from silk.code_generation.curl import curl_cmd | ||
|
||
|
||
class TestCodeGenCurl(TestCase): | ||
def test_post_json(self): | ||
result = curl_cmd( | ||
url="https://example.org/alpha/beta", | ||
method="POST", | ||
body={"gamma": "delta"}, | ||
content_type="application/json", | ||
) | ||
|
||
result_words = shlex.split(result) | ||
|
||
self.assertEqual(result_words, [ | ||
'curl', '-X', 'POST', | ||
'-H', 'content-type: application/json', | ||
'-d', '{"gamma": "delta"}', | ||
'https://example.org/alpha/beta' | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
from django.test import TestCase | ||
import textwrap | ||
from unittest import TestCase | ||
|
||
from silk.code_generation.django_test_client import gen | ||
|
||
|
||
class TestCodeGenDjango(TestCase): | ||
def test_post(self): | ||
result = gen( | ||
path="/alpha/beta", | ||
method="POST", | ||
data={"gamma": "delta", "epsilon": "zeta"}, | ||
content_type="application/x-www-form-urlencoded", | ||
) | ||
|
||
pass | ||
self.assertEqual(result, textwrap.dedent("""\ | ||
from django.test import Client | ||
c = Client() | ||
response = c.post(path='/alpha/beta', | ||
data={'gamma': 'delta', 'epsilon': 'zeta'}, | ||
content_type='application/x-www-form-urlencoded') | ||
""")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters