Skip to content

Commit

Permalink
QA
Browse files Browse the repository at this point in the history
  • Loading branch information
datakurre committed Feb 19, 2024
1 parent ccd6101 commit ffe3a3a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
30 changes: 15 additions & 15 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /Plone/front-page HTTP/1.1
Host: localhost:8080
Expand Down Expand Up @@ -70,7 +70,7 @@ Code
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /Plone/front-page HTTP/1.1
Host: localhost:8080
Expand Down Expand Up @@ -121,7 +121,7 @@ Result

or with inline response starting with just "HTTP " without the HTTP version:

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /Plone/front-page HTTP/1.1
Host: localhost:8080
Expand Down Expand Up @@ -179,7 +179,7 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
POST /Plone/folder HTTP/1.1
Host: localhost:8080
Expand All @@ -195,7 +195,7 @@ Code
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
POST /Plone/folder HTTP/1.1
Host: localhost:8080
Expand All @@ -216,7 +216,7 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
PATCH /Plone/folder/my-document HTTP/1.1
Host: localhost:8080
Expand All @@ -231,7 +231,7 @@ Code
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
PATCH /Plone/folder/my-document HTTP/1.1
Host: localhost:8080
Expand All @@ -252,7 +252,7 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /items?user_id=12&user_id=13 HTTP/1.1
Host: localhost
Expand All @@ -269,7 +269,7 @@ Code
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
GET /items?user_id=12&user_id=13 HTTP/1.1
Host: localhost
Expand All @@ -294,14 +294,14 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/001.request.txt
:response: ../tests/fixtures/001.response.txt
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/001.request.txt
:response: ../tests/fixtures/001.response.txt

Expand All @@ -313,14 +313,14 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/002.request.txt
:response: ../tests/fixtures/002.response.txt
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/002.request.txt
:response: ../tests/fixtures/002.response.txt

Expand All @@ -332,13 +332,13 @@ Code

.. code-block:: rst
.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/003.request.txt
:response: ../tests/fixtures/003.response.txt
Result
``````

.. http:example:: curl wget httpie python-requests
.. http:example:: curl wget httpie python-requests plone-javascript
:request: ../tests/fixtures/003.request.txt
:response: ../tests/fixtures/003.response.txt
16 changes: 10 additions & 6 deletions src/sphinxcontrib/httpexample/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,19 @@ def build_plone_javascript_command(request):
data = maybe_str(request.data())
if data:
if is_json(request.headers.get('Content-Type', '')):
redir_input2 = json.dumps(data, indent=2, sort_keys=True,
separators=(',', ': '))
redir_input2 = json.dumps(
data, indent=2, sort_keys=True,
separators=(',', ': '),
).encode('utf-8')
else:
redir_input2 = data

# Output string
output_string = f"{javascript_code}\n|\nconst aliasesData = {redir_input2};"
output_string =\
"{}\n|\nconst aliasesData = '{}';".format(
maybe_str(javascript_code),
maybe_str(redir_input2),
)

return output_string

Expand Down Expand Up @@ -314,5 +320,3 @@ def astify_json_obj(obj):
tuple(map(ast.Str, token.split(':'))), None)))

return unparse(tree).strip()


9 changes: 5 additions & 4 deletions src/sphinxcontrib/httpexample/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'httpie': (builders.build_httpie_command, 'bash'),
'requests': (builders.build_requests_command, 'python'),
'python-requests': (builders.build_requests_command, 'python'),
'plone_javascript': (builders.build_plone_javascript_command, 'javascript'),
'plone-javascript': (builders.build_plone_javascript_command,
'javascript'),
}

AVAILABLE_FIELDS = [
Expand Down Expand Up @@ -129,9 +130,9 @@ def run(self):
request = parsers.parse_request(raw, config.httpexample_scheme)
builder_, language = AVAILABLE_BUILDERS[name]

#Setting plone JavaScript tab name
name = 'JavaScript' if name == 'plone_javascript' else name
# Setting plone JavaScript tab name
name = 'JavaScript' if name == 'plone-javascript' else name

command = builder_(request)

content = StringList(
Expand Down
14 changes: 7 additions & 7 deletions tests/snapshots/snap_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

snapshots['test_fixture[build_plone_javascript_command-fixture_001] 1'] = '''createAliasesMutation
|
const aliasesData = ;'''
const aliasesData = '';'''

snapshots['test_fixture[build_plone_javascript_command-fixture_002] 1'] = '''createAliasesMutation
|
Expand All @@ -118,23 +118,23 @@

snapshots['test_fixture[build_plone_javascript_command-fixture_004] 1'] = '''createAliasesMutation
|
const aliasesData = ;'''
const aliasesData = '';'''

snapshots['test_fixture[build_plone_javascript_command-fixture_005] 1'] = '''createAliasesMutation
|
const aliasesData = ;'''
const aliasesData = '';'''

snapshots['test_fixture[build_plone_javascript_command-fixture_006] 1'] = '''createAliasesMutation
|
const aliasesData = defgh;'''
const aliasesData = 'defgh';'''

snapshots['test_fixture[build_plone_javascript_command-fixture_007] 1'] = '''createAliasesMutation
|
const aliasesData = ;'''
const aliasesData = '';'''

snapshots['test_fixture[build_plone_javascript_command-fixture_008] 1'] = '''createAliasesMutation
|
const aliasesData = ;'''
const aliasesData = '';'''

snapshots['test_fixture[build_plone_javascript_command-fixture_009] 1'] = '''createAliasesMutation
|
Expand Down Expand Up @@ -174,7 +174,7 @@

snapshots['test_fixture[build_plone_javascript_command-fixture_011] 1'] = '''createAliasesMutation
|
const aliasesData = ;'''
const aliasesData = '';'''

snapshots['test_fixture[build_plone_javascript_command-fixture_012] 1'] = '''createAliasesMutation
|
Expand Down

0 comments on commit ffe3a3a

Please sign in to comment.