-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
json payload: keys/values without quotes & prerequest message cleanup…
… & use pytest to test dothtp request files
- Loading branch information
Showing
15 changed files
with
210 additions
and
24 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.0.43a24" | ||
__version__ = "0.0.43a25" |
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
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
Empty file.
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,8 @@ | ||
import pytest | ||
from .conftest import * | ||
|
||
if __name__ == "__main__": | ||
# run pytest with the current module | ||
# this will not work because of arguments | ||
# use `pytest dothttp_test --directory test/extensions/commands/names.http --prefix test -v -s --html=report.html` | ||
pytest.main(["dothttp_test", "-v", "-s", "--html=report.html"]) |
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,26 @@ | ||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--prefix", action="store", type=str, help="prefix for httpdef name", default="*" | ||
) | ||
parser.addoption( | ||
"--directory", | ||
action="store", | ||
nargs="+", | ||
help="list of directories to search for httpdef files", | ||
default=["."], | ||
) | ||
parser.addoption("--property-file", help="property file") | ||
parser.addoption( | ||
"--no-cookie", | ||
help="cookie storage is disabled", | ||
action="store_const", | ||
const=True, | ||
) | ||
parser.addoption( | ||
"--env", | ||
help="environment to select in property file. properties will be enabled on FIFO", | ||
nargs="+", | ||
default=["*"], | ||
) | ||
parser.addoption("--property", help="list of property's", | ||
nargs="+", default=[]) |
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,125 @@ | ||
import os | ||
from collections import namedtuple | ||
import logging | ||
|
||
from dothttp.parse import ( | ||
Config, | ||
) | ||
from dothttp.parse.request_base import ( | ||
RequestCompiler, | ||
dothttp_model, | ||
) | ||
from dotextensions.server.handlers.basic_handlers import RunHttpFileHandler | ||
|
||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
HttpDefTest = namedtuple( | ||
"HttpDef", ["display", "file", "name", "config", "failed"]) | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
prefix = metafunc.config.getoption("prefix") | ||
directory = metafunc.config.getoption("directory") | ||
# iterate through all sub directories in the directory | ||
# and get all httpdef files | ||
# and pass it to the test function | ||
tests_to_run = [] | ||
|
||
for dir in directory: | ||
if not os.path.exists(dir): | ||
LOGGER.error(f"{dir} does not exists") | ||
continue | ||
if os.path.isfile(dir): | ||
tests_to_run += extrct_tests_to_run(metafunc, | ||
prefix, dir) | ||
else: | ||
for root, _dirs, files in os.walk(dir): | ||
for filename in files: | ||
tests_to_run += extrct_tests_to_run( | ||
metafunc, prefix, os.path.join(root, filename)) | ||
metafunc.parametrize("httpdeftest", tests_to_run, ids=lambda x: x.display) | ||
|
||
|
||
def extrct_tests_to_run(metafunc, prefix, filename): | ||
tests_to_run = [] | ||
if filename.endswith(".http"): | ||
with open(os.path.join(filename)) as f: | ||
httpdef = f.read() | ||
try: | ||
model = dothttp_model.model_from_str(httpdef) | ||
for http in model.allhttps: | ||
if prefix is not None: | ||
if prefix == "*": | ||
tests_to_run.append( | ||
HttpDefTest( | ||
file=filename, | ||
name=http.namewrap.name, | ||
display=f"{filename} - name={http.namewrap.name}", | ||
config=metafunc.config, | ||
failed=False | ||
) | ||
) | ||
elif http.namewrap and http.namewrap.name.startswith(prefix): | ||
tests_to_run.append( | ||
HttpDefTest( | ||
file=filename, | ||
name=http.namewrap.name, | ||
display=f"{filename} - name={http.namewrap.name}", | ||
config=metafunc.config, | ||
failed=False | ||
) | ||
) | ||
except: | ||
tests_to_run.append( | ||
HttpDefTest( | ||
file=filename, | ||
name="entire_file", | ||
display=f"{filename} - name='entire_file'", | ||
config=metafunc.config, | ||
failed=True | ||
) | ||
) | ||
LOGGER.error(f"error in parsing {filename}") | ||
return tests_to_run | ||
|
||
|
||
def test_httpdef(httpdeftest: HttpDefTest): | ||
if httpdeftest.failed: | ||
assert False, "failed to parse" | ||
# read below arguments from command line | ||
config = Config( | ||
file=httpdeftest.file, | ||
target=httpdeftest.name, | ||
property_file=httpdeftest.config.getoption("property_file"), | ||
env=httpdeftest.config.getoption("env"), | ||
properties=httpdeftest.config.getoption("property"), | ||
debug=True, | ||
info=True, | ||
curl=False, | ||
no_cookie=False, | ||
format=False, | ||
) | ||
comp = RequestCompiler(config) | ||
|
||
realized_http_def_content = RunHttpFileHandler.get_http_from_req( | ||
comp.httpdef) | ||
|
||
logging.warning( | ||
f"realized_http_def_content {realized_http_def_content}", | ||
) | ||
|
||
resp = comp.get_response() | ||
|
||
logging.warning(f"resp={resp}") | ||
|
||
script_result = comp.script_execution.execute_test_script(resp) | ||
|
||
for test in script_result.tests: | ||
# at present only one failure is reported in the test. | ||
# if there are multiple failures, only the first one is reported | ||
logging.warning( | ||
f"script_result: test={test}, test_success: {test.success}, error:{test.error}", | ||
) | ||
assert test.success, test.error |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "dothttp-req" | ||
version = "0.0.43a24" | ||
version = "0.0.43a25" | ||
description = "Dothttp is Simple http client for testing and development" | ||
authors = ["Prasanth <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -10,7 +10,7 @@ classifiers = [ | |
"Operating System :: OS Independent", | ||
] | ||
exclude = ["test", "test.core", "test.extensions", "benchmarks"] | ||
packages = [{'include'='dotextensions'}, {'include'='dothttp'}, {'include'='dothttp_req'}] | ||
packages = [{'include'='dotextensions'}, {'include'='dothttp'}, {'include'='dothttp_req'}, {'include'='dothttp_test'}] | ||
repository = "https://github.com/cedric05/dothttp" | ||
|
||
[tool.poetry.urls] | ||
|
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,2 @@ | ||
[pytest] | ||
addopts = --ignore=dothttp_test -s |
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