Skip to content

Commit

Permalink
refactor: fix test imports and includes for fetch module ns update
Browse files Browse the repository at this point in the history
  • Loading branch information
0hsn committed Nov 11, 2024
1 parent f0ebc47 commit c06db39
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
8 changes: 4 additions & 4 deletions tests/infrastructure/symbol_table_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Variables,
replace_value,
)
from chk.modules.fetch import HttpDocument
from chk.modules.fetch import HttpDocumentSupport


class TestVariableTableManager:
Expand All @@ -39,7 +39,7 @@ def test_handle_pass():
}
)

http_doc = HttpDocument.from_file_context(file_ctx)
http_doc = HttpDocumentSupport.from_file_context(file_ctx)

variable_doc = Variables()
VariableTableManager.handle(variable_doc, http_doc, exc)
Expand Down Expand Up @@ -277,7 +277,7 @@ def test_get_exposed_replaced_data_pass_returns_empty_list():

file_ctx = FileContext(filepath_hash="ab12", document=document)

http_doc = HttpDocument.from_file_context(file_ctx)
http_doc = HttpDocumentSupport.from_file_context(file_ctx)

exposed_data = ExposeManager.get_exposed_replaced_data(
http_doc, {"a": 1, "b": 2}
Expand All @@ -302,7 +302,7 @@ def test_get_exposed_replaced_data_pass_returns_nonempty_list():
arguments={VariableConfigNode.VARIABLES: {"extension": ".org"}}
)

http_doc = HttpDocument.from_file_context(file_ctx)
http_doc = HttpDocumentSupport.from_file_context(file_ctx)

variable_doc = Variables()
VariableTableManager.handle(variable_doc, http_doc, exec_ctx)
Expand Down
2 changes: 1 addition & 1 deletion tests/infrastructure/third_party/http_fetcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests
from defusedxml.minidom import parseString

from chk.modules.fetch import ApiResponseModel
from chk.modules.fetch.entities import ApiResponseModel

BODY_JSON = """[
{
Expand Down
37 changes: 25 additions & 12 deletions tests/modules/fetch/fetch_entities_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
# type: ignore
import json

import pytest

from chk.infrastructure.file_loader import FileContext
from chk.infrastructure.symbol_table import Variables
from chk.modules.fetch import (
HttpDocument,
HttpDocumentSupport,
)
from chk.modules.fetch import HttpDocumentSupport
from chk.modules.fetch.entities import HttpDocument


class TestHttpDocument:
@staticmethod
def test_bool_pass():
ctx = FileContext(
document={
"version": "default:http:0.7.2",
"request": {
"url": "https://jsonplaceholder.typicode.com/albums/1",
"method": "GET",
},
}
)

doc = HttpDocumentSupport.from_file_context(ctx)

assert doc


class TestHttpDocumentSupport:
@staticmethod
def test_from_file_context_pass():
ctx = FileContext(
Expand All @@ -24,7 +39,7 @@ def test_from_file_context_pass():
}
)

doc = HttpDocument.from_file_context(ctx)
doc = HttpDocumentSupport.from_file_context(ctx)

assert isinstance(doc.context, tuple)
assert isinstance(doc.version, str)
Expand All @@ -39,7 +54,7 @@ def test_from_file_context_fail_no_request():
)

with pytest.raises(RuntimeError):
HttpDocument.from_file_context(ctx)
HttpDocumentSupport.from_file_context(ctx)

@staticmethod
def test_from_file_context_fail_no_version():
Expand All @@ -53,10 +68,8 @@ def test_from_file_context_fail_no_version():
)

with pytest.raises(ValueError):
HttpDocument.from_file_context(ctx)
HttpDocumentSupport.from_file_context(ctx)


class TestHttpDocumentSupport:
@staticmethod
def test_execute_request_pass():
ctx = FileContext(
Expand All @@ -69,7 +82,7 @@ def test_execute_request_pass():
}
)

http_doc = HttpDocument.from_file_context(ctx)
http_doc = HttpDocumentSupport.from_file_context(ctx)
resp = HttpDocumentSupport.execute_request(http_doc)

assert "userId" in resp.body
Expand All @@ -86,7 +99,7 @@ def test_process_request_template_pass():
}
)

http_doc = HttpDocument.from_file_context(ctx)
http_doc = HttpDocumentSupport.from_file_context(ctx)
variable_doc = Variables({"method": "GET"})

HttpDocumentSupport.process_request_template(http_doc, variable_doc)
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/fetch/fetch_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Fetch module tests
"""
from chk.infrastructure.file_loader import FileContext, ExecuteContext
from chk.infrastructure.file_loader import ExecuteContext, FileContext
from chk.modules.fetch import call


Expand Down
3 changes: 2 additions & 1 deletion tests/modules/fetch/fetch_request_helper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import pytest

from chk.modules.fetch import BearerAuthentication, HttpRequestArgCompiler
from chk.modules.fetch.entities import BearerAuthentication
from chk.modules.fetch.services import HttpRequestArgCompiler


class TestHttpRequestArgCompiler:
Expand Down

0 comments on commit c06db39

Please sign in to comment.