Skip to content

Commit

Permalink
tests for cookies in commands server and command line
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric05 committed Mar 8, 2022
1 parent b2680ce commit 99718ed
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dotextensions/server/handlers/basic_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def get_request_result(self, command, comp: RequestCompiler):
data = {}
data.update(response_data['response']) # deprecated
data.update(response_data)
if 'cookie' in resp.request.headers:
comp.httpdef.headers['cookie'] = resp.request.headers['cookie']
try:
data.update({"http": self.get_http_from_req(comp.httpdef)})
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion dothttp/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.40a5'
__version__ = '0.0.40a6'
8 changes: 8 additions & 0 deletions test/core/requests/cookie.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@name('set-cookie')
GET https://httpbin.org/cookies/set/dev/ram




@name('confirm-cookie-sent')
GET https://httpbin.org/cookies
29 changes: 28 additions & 1 deletion test/core/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

from dothttp.exceptions import *
from dothttp.request_base import CurlCompiler, HttpFileFormatter
from dothttp.request_base import DOTHTTP_COOKIEJAR, CurlCompiler, HttpFileFormatter, RequestBase
from test import TestBase

dir_path = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -248,6 +248,33 @@ def test_trailing_commas_are_ok(self):
self.assertEqual('https://dev.dothttp.dev/', fourth_one.url)
self.assertEqual('POST', fourth_one.method)

def test_cookie(self):
# This is an integration test
filename = f"{base_dir}/cookie.http"
req_comp = self.get_req_comp(filename, target="set-cookie")
resp = req_comp.get_response()
# confirm cookie is recognized by httpbin.org
self.assertEqual({
"cookies": {
"dev": "ram"
}
}, resp.json())

req_comp2 = self.get_req_comp(filename, target="confirm-cookie-sent")
self.assertEqual("dev=ram", req_comp2.get_request().headers.get('cookie'))
resp = req_comp2.get_response()

self.assertEqual({
"cookies": {
"dev": "ram"
}
}, resp.json())
os.remove(DOTHTTP_COOKIEJAR)
RequestBase.global_session.cookies.clear()





if __name__ == "__main__":
unittest.main()
3 changes: 3 additions & 0 deletions test/extensions/commands/cookie.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@name('set-cookie')
GET https://httpbin.org/cookies/set/dev/ram

15 changes: 15 additions & 0 deletions test/extensions/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dotextensions.server.handlers.basic_handlers import RunHttpFileHandler, GetNameReferencesHandler, \
ContentNameReferencesHandler
from dotextensions.server.models import Command
from dothttp.request_base import DOTHTTP_COOKIEJAR, RequestBase
from test import TestBase
from test.core.test_certs import http_base, cert_base

Expand Down Expand Up @@ -214,6 +215,20 @@ def test_env(self):
result = self.execute_file(f"{command_dir}/isolated/env.http", env=["simple"])
self.assertEqual(200, result.result['status'])


def test_execute(self):
result = self.execute_file(f"{command_dir}/cookie.http", target="set-cookie")
self.assertEqual("""@name("set-cookie")
GET "https://httpbin.org/cookies/set/dev/ram"
"cookie": "dev=ram"
""", result.result['http'])
os.remove(DOTHTTP_COOKIEJAR)
RequestBase.global_session.cookies.clear()


def test_property(self):
result = self.execute_file(f"{command_dir}/isolated/env.http", properties={"path": "get"})
self.assertEqual(200, result.result['status'])
Expand Down

0 comments on commit 99718ed

Please sign in to comment.